Documentation
¶
Overview ¶
Package subnet provides interfaces for subnet calculation operations.
Package subnet provides core domain types and calculations for IP subnet operations.
Index ¶
Constants ¶
This section is empty.
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 Calculator ¶
type Calculator interface {
// Calculate creates a Network from a CIDR string.
Calculate(cidr string) (Network, error)
// Split divides a network into subnets of the specified prefix length.
Split(network *Network, targetBits int) error
}
Calculator defines the interface for subnet calculation operations.
type DefaultCalculator ¶
type DefaultCalculator struct{}
DefaultCalculator is the standard implementation of Calculator.
func NewCalculator ¶
func NewCalculator() *DefaultCalculator
NewCalculator creates a new DefaultCalculator.
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.