struct

Ipconv::CIDR

Inherits Struct < Value < Object

Represents a Classless Inter-Domain Routing (CIDR) IP network block.

Constructors

new(network : Address, prefix : UInt8)

Creates a CIDR from a base network Address and prefix length in bits.

Source
parse(input : String, strict : Bool = false, warn : Bool = false) : CIDR

Parses a CIDR string (e.g. "192.168.1.0/24" or "2001:db8::/32"). Normalizes host bits if non-zero. If strict is true, raises ValidationError on non-zero host bits. If warn is true, prints a warning to STDERR.

Source

Class methods

hi_mask(prefix : UInt8) : UInt64

Computes the high 64 bits of an IPv6 network mask for the given prefix length.

Source
lo_mask(prefix : UInt8) : UInt64

Computes the low 64 bits of an IPv6 network mask for the given prefix length.

Source
network_mask(prefix : UInt8, bits : UInt8 = 32_u8) : UInt32

Computes an IPv4 32-bit network mask for the given prefix length and total bits.

Source
warn_host_bits(input : String, given : Address, network : Address, _prefix : UInt8)

Emits a warning to STDERR when host bits were non-zero in the input CIDR.

Source

Instance methods

first

Returns the first (network) address in this CIDR block.

Source
first_host

Returns the first usable host address in this subnet. Handles /31 and /32 special cases for IPv4 (RFC 3021), and /127 and /128 for IPv6 (RFC 6164).

Source
host_count

Returns the number of usable host addresses in this subnet as a UInt128. Follows RFC 3021 (/31 = 2 hosts) and RFC 6164 (/127 = 2 hosts).

Source
last

Returns the last (broadcast for IPv4, last for IPv6) address in this CIDR block.

Source
last_host

Returns the last usable host address in this subnet. Handles /31 and /32 special cases for IPv4 (RFC 3021), and /127 and /128 for IPv6 (RFC 6164).

Source
network

Returns the base network address.

Source
prefix

Returns the prefix length in bits (0-32 for IPv4, 0-128 for IPv6).

Source
subnet_mask

Returns the subnet mask as an Address (IPv4 or IPv6).

Source
to_s

Returns the CIDR notation string (e.g. "192.168.1.0/24").

Source
total

Returns the total number of IP addresses in this CIDR range as a UInt128.

Source
version

Returns the IP version string ("4" or "6").

Source
wildcard_mask

Returns the wildcard mask as an Address (IPv4 or IPv6).

Source