Represents an IPv4 Classless Inter-Domain Routing (CIDR) subnet block.
Normalizes the network base address upon initialization and provides subnet slicing.
Constructors
new(network :
IPv4Address, prefix :
Int32)
Initializes an IPv4CIDR with a network address and prefix (0..32).
Normalizes host bits in the network address to 0.
Sourceparse(cidr_str :
String) :
IPv4CIDR Parses a CIDR string (e.g. "192.168.1.0/24") into an IPv4CIDR struct.
SourceClass methods
Computes the 32-bit subnet mask for a given prefix length.
SourceInstance methods
broadcast
Returns the broadcast address for this subnet.
Sourcecontains?(address :
IPv4Address) :
Bool Returns true if this CIDR block contains the specified IPv4Address.
Sourcecontains?(other :
IPv4CIDR) :
Bool Returns true if this CIDR block completely encloses another IPv4CIDR.
Sourcefirst_usable
Returns the first usable host IP in the subnet.
Sourcehost_at(offset :
Int) :
IPv4Address Calculates the IP address at a specific numerical offset within the subnet.
Sourcelast_usable
Returns the last usable host IP in the subnet.
Sourcenetmask
Returns the subnet mask as an IPv4Address.
Sourceoverlaps?(other :
IPv4CIDR) :
Bool Returns true if this CIDR block overlaps with another IPv4CIDR.
SourceSlices this subnet into child subnets of prefix new_prefix without intermediate allocations.
SourceOutputs CIDR string representation (e.g. "192.168.1.0/24").
Sourcetotal_hosts
Computes total host addresses in this subnet (including network and broadcast).
Sourceusable_hosts
Computes usable host count taking RFC 3021 (/31) and /32 into account.
Sourcewildcard_mask
Returns the wildcard mask (inverted subnet mask) as an IPv4Address.
Source