struct

IP::Address

Inherits Comparable < Comparable < Struct < Value < Object

Constructors

[](string : String) : self

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.

Source
new(sockaddr : Pointer(LibC::Sockaddr)) : self

Creates an IP::Address from the internal OS representation of a Socket Address.

Source
new(string : String) : self

ditto

Source

Class methods

[]?(string : String) : self | Nil

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.

Source
ipv4(string : String)

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.

Source
ipv4?(string : String)

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.

Source
ipv6(string : String)

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.

Source
ipv6?(string : String)

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.

Source
new?(string : String) : self | Nil

ditto

Source

Instance methods

+(other : Int) : self

Generates a new IP::Address with a given integer offset.

Source
-(other : Int) : self

ditto

Source
<=>(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.

Source
<=>(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.

Source
[](index : Int)

Returns the requested component from the address.

Source
adjacent?(other : IP::Address)

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.

Source
adjacent?(other : IP::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.

Source
family

Returns the Socket::Family associated with this address.

Source
hash(hasher)

See Object#hash(hasher)

Source
inspect(io : IO) : Nil

Appends a type-specified presentation representation of the address to the given IO.

Source
ipv4?

Informs if the address is IPv4 or not.

Source
ipv6?

Informs if the address is IPv6 or not.

Source
loopback?

Informs if the address is in the loopback address space or not.

Source
max_value

The maximum address of this type.

Source
to_sockaddr
Source
value

The internally stored value of the address.

Source
value_network

The internally stored value of the address in network byte order.

Source
width

The width of the address type.

Source

Nested types