abstract struct IP::Address

Included Modules

Direct Known Subclasses

Defined in:

ip/address.cr
ip/address.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.[](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.


[View source]
def self.[]?(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.

Returns nil when the input is malformed.


[View source]
def self.new(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.


[View source]
def self.new(sockaddr : ::Pointer(LibC::Sockaddr)) : self #

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


[View source]
def self.new?(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.

Returns nil when the input is malformed.


[View source]

Class Method Detail

def self.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.


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.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.


[View source]

Instance Method Detail

def +(other : Int) : self #

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


[View source]
def -(other : Int) : self #

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


[View source]
def <=>(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.


[View source]
def <=>(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.


[View source]
abstract def [](index : Int) #

Returns the requested component from the address.


[View source]
def 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.


[View source]
def 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.


[View source]
def family : Socket::Family #

Returns the Socket::Family associated with this address.


[View source]
def hash(hasher) #

See Object#hash(hasher)


[View source]
def inspect(io : IO) : Nil #

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


[View source]
def ipv4? : Bool #

Informs if the address is IPv4 or not.


[View source]
def ipv6? : Bool #

Informs if the address is IPv6 or not.


[View source]
abstract def loopback? : Bool #

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


[View source]
abstract def max_value #

The maximum address of this type.


[View source]
abstract def to_sockaddr #

[View source]
abstract def value #

The internally stored value of the address.


[View source]
abstract def value_network #

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


[View source]
abstract def width #

The width of the address type.


[View source]