Documentation
¶
Overview ¶
Package subnet provides core domain types and calculations for IP subnet operations.
Index ¶
Constants ¶
const MaxGeneratedSubnets = 1_000_000
MaxGeneratedSubnets is the safety limit for subnet splitting operations. This prevents accidental memory exhaustion from very large splits.
Variables ¶
This section is empty.
Functions ¶
func CalculateBroadcastAddr ¶
CalculateBroadcastAddr computes the broadcast address from network address and subnet mask.
func CalculateMaxHosts ¶
CalculateMaxHosts returns the number of usable host addresses in a subnet. Uses big.Int to handle IPv6 networks without overflow.
func CalculateSubnetMask ¶
CalculateSubnetMask generates a subnet mask for the given mask bits and address size.
Types ¶
type Network ¶
type Network struct {
CIDR netip.Prefix `json:"cidr"`
NetworkAddr netip.Addr `json:"networkAddr"`
BroadcastAddr netip.Addr `json:"broadcastAddr"`
FirstHostIP netip.Addr `json:"firstIP"`
LastHostIP netip.Addr `json:"lastIP"`
SubnetMask netip.Addr `json:"subnetMask"`
MaskBits int `json:"maskBits"`
MaxHosts *big.Int `json:"maxHosts"`
Subnets []Network `json:"subnets,omitempty"`
}
Network represents an IP network with calculated properties.
func GenerateSubnets ¶
GenerateSubnets creates all subnets of targetBits size within the given prefix.
func NewNetwork ¶
NewNetwork creates a Network from a CIDR string.
func NewNetworkFromPrefix ¶
NewNetworkFromPrefix creates a Network from a netip.Prefix.