struct

IP::Address::IPv4

Inherits IP::Address < Comparable < Comparable < Struct < Value < Object

Constants

ADDRESS_MAX = 4294967295_u32
ADDRESS_WIDTH = 32_u8

Constructors

new(value : Value)

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

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

Source
new(octets : Octets) : self

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

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

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

Source
new(value : Int) : self

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

Source

Class methods

new?(string : String) : self | Nil

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.

Source

Instance methods

[](index : Int) : UInt8

Returns the requested octet from the address.

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

Source
loopback?

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

Source
max_value

The maximum address of this type.

Source
octets

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

Source
to_s(io : IO)

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

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