Class: SFML::Network::IpAddress
- Inherits:
-
Object
- Object
- SFML::Network::IpAddress
- Defined in:
- lib/sfml/network/ip_address.rb
Overview
An IPv4 address. The CSFML side stores it as a fixed-size 16-byte NUL-terminated dotted-decimal string (“192.168.1.42”).
SFML::Network::IpAddress.from_string("192.168.1.42")
SFML::Network::IpAddress.from_bytes(192, 168, 1, 42)
SFML::Network::IpAddress::LOCALHOST # 127.0.0.1
SFML::Network::IpAddress::ANY # 0.0.0.0
SFML::Network::IpAddress::BROADCAST # 255.255.255.255
SFML::Network::IpAddress.local # local network IP
Constant Summary collapse
- NONE =
wrap(C::Network.sfIpAddress_None)
- ANY =
wrap(C::Network.sfIpAddress_Any)
- LOCALHOST =
wrap(C::Network.sfIpAddress_LocalHost)
- BROADCAST =
wrap(C::Network.sfIpAddress_Broadcast)
Class Method Summary collapse
- .from_bytes(a, b, c, d) ⇒ Object
- .from_integer(n) ⇒ Object
- .from_string(s) ⇒ Object
-
.local ⇒ Object
The IP this machine sees on its local network.
-
.public(timeout: SFML::Time.zero) ⇒ Object
Public-facing IP.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Class Method Details
.from_bytes(a, b, c, d) ⇒ Object
17 18 19 |
# File 'lib/sfml/network/ip_address.rb', line 17 def self.from_bytes(a, b, c, d) wrap(C::Network.sfIpAddress_fromBytes(Integer(a), Integer(b), Integer(c), Integer(d))) end |
.from_integer(n) ⇒ Object
21 22 23 |
# File 'lib/sfml/network/ip_address.rb', line 21 def self.from_integer(n) wrap(C::Network.sfIpAddress_fromInteger(Integer(n))) end |
.from_string(s) ⇒ Object
13 14 15 |
# File 'lib/sfml/network/ip_address.rb', line 13 def self.from_string(s) wrap(C::Network.sfIpAddress_fromString(s.to_s)) end |
.local ⇒ Object
The IP this machine sees on its local network.
26 27 28 |
# File 'lib/sfml/network/ip_address.rb', line 26 def self.local wrap(C::Network.sfIpAddress_getLocalAddress) end |
.public(timeout: SFML::Time.zero) ⇒ Object
Public-facing IP. Performs an outbound query, so optionally cap with a timeout. Slow — minutes if the network is down.
32 33 34 |
# File 'lib/sfml/network/ip_address.rb', line 32 def self.public(timeout: SFML::Time.zero) wrap(C::Network.sfIpAddress_getPublicAddress(timeout.to_native)) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
52 53 54 |
# File 'lib/sfml/network/ip_address.rb', line 52 def ==(other) other.is_a?(IpAddress) && to_s == other.to_s end |
#hash ⇒ Object
56 |
# File 'lib/sfml/network/ip_address.rb', line 56 def hash = to_s.hash |
#to_i ⇒ Object
48 49 50 |
# File 'lib/sfml/network/ip_address.rb', line 48 def to_i C::Network.sfIpAddress_toInteger(@struct) end |
#to_s ⇒ Object Also known as: inspect
43 44 45 |
# File 'lib/sfml/network/ip_address.rb', line 43 def to_s @struct[:address].to_ptr.read_string_to_null end |