struct IP::Address::IPv4

Defined in:

ip/address/ipv4.cr

Constant Summary

ADDRESS_MAX = 4294967295_u32
ADDRESS_WIDTH = 32_u8

Constructors

Instance Method Summary

Instance methods inherited from struct IP::Address

+(other : Int) : self +, -(other : Int) : self -, <=>(other : IP::Address) : Int
<=>(other : IP::Block) : Int
<=>
, [](index : Int) [], adjacent?(other : IP::Block)
adjacent?(other : IP::Address)
adjacent?
, family : Socket::Family family, hash(hasher) hash, inspect(io : IO) : Nil inspect, ipv4? : Bool ipv4?, ipv6? : Bool ipv6?, loopback? : Bool loopback?, max_value max_value, to_sockaddr to_sockaddr, value value, value_network value_network, width width

Constructor methods inherited from struct IP::Address

[](string : String) : self [], []?(string : String) : self? []?, new(string : String) : self
new(sockaddr : ::Pointer(LibC::Sockaddr)) : self
new
, new?(string : String) : self? new?

Class methods inherited from struct IP::Address

ipv4(string : String) ipv4, ipv4?(string : String) ipv4?, ipv6(string : String) ipv6, ipv6?(string : String) ipv6?

Constructor Detail

def self.new(value : Value) #

Creates a new IP::Address::IPv4 from a {{ Value.id }} value.


[View source]
def self.new(string : String) : self #

Constructs a new IP::Address::IPv4 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.new(octets : Octets) : self #

Constructs a new IP::Address::IPv4 from a Tuple of 4 UInt8.


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

Constructs a new IP::Address::IPv4 from a SockaddrIn*.


[View source]
def self.new(value : Int) : self #

Constructs a new IP::Address::IPv4 from an Int.


[View source]
def self.new?(string : String) : self? #

Constructs a new IP::Address::IPv4 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]

Instance Method Detail

def [](index : Int) : UInt8 #

Returns the requested octet from the address.

Raises OutOfBoundsError if the requested octet is not [0..3].


[View source]
def loopback? : Bool #

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


[View source]
def max_value : Value #

The maximum address of this type.


[View source]
def octets : Octets #

Returns a Tuple of 4 UInt8 which represent the addresses octets.


[View source]
def to_s(io : IO) #

Appends the presentation representation of the address to the given IO.


[View source]
def to_sockaddr(port : UInt16 = 0_u16) : ::Pointer(LibC::Sockaddr) #

Produces the c sockaddr_in struct required by bind, connect, sendto, and sendmsg.

Note: Unix Network Programming: Volume 1, 3rd Edition, p.68

  • sin_len: default size of this struct is 16 bytes. Is set internally when passed though bind, connect, sendto, or sendmsg.
  • sin_zero: is unused.

[View source]
def value : Value #

The internally stored value of the address.


[View source]
def value_network : LibC::UInt32T #

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


[View source]
def width : UInt8 #

The width of the address type.


[View source]