struct

Ipconv::IPv4

Inherits Comparable < Struct < Value < Object

Represents an IPv4 address backed by a 32-bit unsigned integer (UInt32).

Constructors

new(addr : UInt32)

Creates an IPv4 address from a 32-bit unsigned integer.

Source
new(octets : StaticArray(UInt8, 4))

Creates an IPv4 address from a 4-element UInt8 static array representing the 4 octets.

Source
parse(input : String) : IPv4

Auto-detects and parses an IPv4 address from string input. Supports dotted decimal, hex integer (with or without 0x prefix), hex dotted, decimal integer, binary dotted, and octal dotted formats.

Source

Instance methods

+(other : Int) : IPv4

Adds an integer offset to this IPv4 address. Raises OverflowError on bounds overflow or underflow.

Source
-(other : Int) : IPv4

Subtracts an integer offset from this IPv4 address. Raises OverflowError on bounds underflow or overflow.

Source
-(other : IPv4) : UInt128

Computes the address distance between this address and other. Raises OverflowError if self < other.

Source
<=>(other : IPv4) : Int32

Compares this IPv4 address with other by numeric address value.

Source
[](index : Int) : UInt8

Returns the octet at index (0 to 3).

Source
addr

Returns the underlying 32-bit unsigned integer representation of the IPv4 address.

Source
classify

Determines the historical class (A through E) for this IPv4 address.

Source
octets

Returns a 4-tuple of octets as UInt8 values.

Source
pred

Returns the previous sequential IPv4 address. Raises OverflowError if already at 0.0.0.0.

Source
special

Returns the Special purpose designation for this IPv4 address, or Special::None if public unicast.

Source
succ

Returns the next sequential IPv4 address. Raises OverflowError if already at 255.255.255.255.

Source
to_binary

Returns the binary dotted string representation (e.g. "11000000.10101000.00000001.00000001").

Source
to_dotted

Returns the dotted decimal string representation (e.g. "192.168.1.1").

Source
to_hex

Returns the hexadecimal integer representation with 0x prefix (e.g. "0xC0A80101").

Source
to_hex_dotted

Returns the dotted hexadecimal representation (e.g. "C0.A8.01.01").

Source
to_integer

Returns the decimal integer string representation (e.g. "3232235777").

Source
to_octal

Returns the octal dotted string representation (e.g. "0300.0250.0001.0001").

Source
to_s(io : IO) : Nil

Writes the dotted decimal representation of this address to io.

Source

Nested types