Documentation
¶
Overview ¶
Package cidr is a collection of assorted utilities for computing network and host addresses within network ranges.
It expects a CIDR-type address structure where addresses are divided into some number of prefix bits representing the network and then the remaining suffix bits represent the host.
For example, it can help to calculate addresses for sub-networks of a parent network, or to calculate host addresses within a particular prefix.
At present this package is prioritizing simplicity of implementation and de-prioritizing speed and memory usage. Thus caution is advised before using this package in performance-critical applications or hot codepaths. Patches to improve the speed and memory usage may be accepted as long as they do not result in a significant increase in code complexity.
Index ¶
- func AddressCount(network *net.IPNet) uint64
- func AddressRange(network *net.IPNet) (net.IP, net.IP)
- func Dec(IP net.IP) net.IP
- func Host(base *net.IPNet, num int) (net.IP, error)
- func HostBig(base *net.IPNet, num *big.Int) (net.IP, error)
- func Inc(IP net.IP) net.IP
- func NextSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool)
- func PreviousSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool)
- func Subnet(base *net.IPNet, newBits int, num int) (*net.IPNet, error)
- func SubnetBig(base *net.IPNet, newBits int, num *big.Int) (*net.IPNet, error)
- func VerifyNoOverlap(subnets []*net.IPNet, CIDRBlock *net.IPNet) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddressCount ¶
AddressCount returns the number of distinct host addresses within the given CIDR range.
Since the result is a uint64, this function returns meaningful information only for IPv4 ranges and IPv6 ranges with a prefix size of at least 65.
func AddressRange ¶
AddressRange returns the first and last addresses in the given CIDR range.
func Host ¶
Host takes a parent CIDR range and turns it into a host IP address with the given host number.
For example, 10.3.0.0/16 with a host number of 2 gives 10.3.0.2.
func HostBig ¶ added in v1.1.0
HostBig takes a parent CIDR range and turns it into a host IP address with the given host number. It differs from Host in that it takes a *big.Int for the num, instead of an int.
For example, 10.3.0.0/16 with a host number of 2 gives 10.3.0.2.
func NextSubnet ¶
NextSubnet returns the next available subnet of the desired mask size starting for the maximum IP of the offset subnet If the IP exceeds the maxium IP then the second return value is true
func PreviousSubnet ¶
PreviousSubnet returns the subnet of the desired mask in the IP space just lower than the start of IPNet provided. If the IP space rolls over then the second return value is true
func Subnet ¶
Subnet takes a parent CIDR range and creates a subnet within it with the given number of additional prefix bits and the given network number.
For example, 10.3.0.0/16, extended by 8 bits, with a network number of 5, becomes 10.3.5.0/24 .
func SubnetBig ¶ added in v1.1.0
SubnetBig takes a parent CIDR range and creates a subnet within it with the given number of additional prefix bits and the given network number. It differs from Subnet in that it takes a *big.Int for the num, instead of an int.
For example, 10.3.0.0/16, extended by 8 bits, with a network number of 5, becomes 10.3.5.0/24 .
Types ¶
This section is empty.