abstract struct IP::Address
- IP::Address
- Struct
- Value
- Object
Included Modules
- Comparable(IP::Block)
- Comparable(IP::Address)
Direct Known Subclasses
Defined in:
ip/address.crip/address.cr
Constructors
-
.[](string : String) : self
Constructs a new IPv4 or IPv6
IP::Address
by interpreting the contents of aString
. -
.[]?(string : String) : self?
Constructs a new IPv4 or IPv6
IP::Address
by interpreting the contents of aString
. -
.new(string : String) : self
Constructs a new IPv4 or IPv6
IP::Address
by interpreting the contents of aString
. -
.new(sockaddr : ::Pointer(LibC::Sockaddr)) : self
Creates an
IP::Address
from the internal OS representation of a Socket Address. -
.new?(string : String) : self?
Constructs a new IPv4 or IPv6
IP::Address
by interpreting the contents of aString
.
Class Method Summary
-
.ipv4(string : String)
Constructs a new IPv4
IP::Address
from the contents of aString
. -
.ipv4?(string : String)
Constructs a new IPv4
IP::Address
from the contents of aString
. -
.ipv6(string : String)
Constructs a new IPv6
IP::Address
from the contents of aString
. -
.ipv6?(string : String)
Constructs a new IPv6
IP::Address
from the contents of aString
.
Instance Method Summary
-
#+(other : Int) : self
Generates a new
IP::Address
with a given integer offset. -
#-(other : Int) : self
Generates a new
IP::Address
with a given integer offset. -
#<=>(other : IP::Address) : Int
Compares this address with another, returning
-1
,0
or+1
depending if the address is less, equal or greater than the other address. -
#<=>(other : IP::Block) : Int
Compares this address with block, returning
-1
,0
or+1
depending if the address is less than, included in, or greater than the other block. -
#[](index : Int)
Returns the requested component from the address.
-
#adjacent?(other : IP::Block)
Compares this address with an
IP::Block
, indicating if they are adjacent. -
#adjacent?(other : IP::Address)
Compares this address with another address, indicating if they are adjacent.
-
#family : Socket::Family
Returns the
Socket::Family
associated with this address. -
#hash(hasher)
See
Object#hash(hasher)
-
#inspect(io : IO) : Nil
Appends a type-specified presentation representation of the address to the given
IO
. -
#ipv4? : Bool
Informs if the address is IPv4 or not.
-
#ipv6? : Bool
Informs if the address is IPv6 or not.
-
#loopback? : Bool
Informs if the address is in the loopback address space or not.
-
#max_value
The maximum address of this type.
- #to_sockaddr
-
#value
The internally stored value of the address.
-
#value_network
The internally stored value of the address in network byte order.
-
#width
The width of the address type.
Constructor Detail
Constructs a new IPv4 or IPv6 IP::Address
by interpreting the contents of a String
.
Expects an address in the form of [0-255].[0-255].[0-255].[0-255], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX, or XXXX:XXXX::XXXX:XXXX:XXXX.
Raises: MalformedError
when the input is malformed.
Constructs a new IPv4 or IPv6 IP::Address
by interpreting the contents of a String
.
Expects an address in the form of [0-255].[0-255].[0-255].[0-255], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX, or XXXX:XXXX::XXXX:XXXX:XXXX.
Returns nil
when the input is malformed.
Constructs a new IPv4 or IPv6 IP::Address
by interpreting the contents of a String
.
Expects an address in the form of [0-255].[0-255].[0-255].[0-255], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX, or XXXX:XXXX::XXXX:XXXX:XXXX.
Raises: MalformedError
when the input is malformed.
Creates an IP::Address
from the internal OS representation of a Socket Address.
Constructs a new IPv4 or IPv6 IP::Address
by interpreting the contents of a String
.
Expects an address in the form of [0-255].[0-255].[0-255].[0-255], XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX, or XXXX:XXXX::XXXX:XXXX:XXXX.
Returns nil
when the input is malformed.
Class Method Detail
Constructs a new IPv4 IP::Address
from the contents of a String
.
Expects an address in the form of [0-255].[0-255].[0-255].[0-255].
Raises: MalformedError
when the input is malformed.
Constructs a new IPv4 IP::Address
from the contents of a String
.
Expects an address in the form of [0-255].[0-255].[0-255].[0-255].
Returns nil
when the input is malformed.
Constructs a new IPv6 IP::Address
from the contents of a String
.
Expects an address in the standard presentation form XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX or in the compressed from similar to XXXX:XXXX::XXXX:XXXX:XXXX.
Raises: MalformedError
when the input is malformed.
Constructs a new IPv6 IP::Address
from the contents of a String
.
Expects an address in the standard presentation form XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX or in the compressed from similar to XXXX:XXXX::XXXX:XXXX:XXXX.
Returns nil
when the input is malformed.
Instance Method Detail
Compares this address with another, returning -1
, 0
or +1
depending if the
address is less, equal or greater than the other address.
Compares this address with block, returning -1
, 0
or +1
depending if the
address is less than, included in, or greater than the other block.
Compares this address with an IP::Block
, indicating if they are adjacent.
Adjacency is when there are no addresses between the address and the other address block and the address is not included in the block.
Compares this address with another address, indicating if they are adjacent.
Adjacency is when there are no addresses between the address and the other address and the two addresses are not the same.
Appends a type-specified presentation representation of the address to the
given IO
.