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.
********************************************************************************* This was copied from https://github.com/apparentlymart/go-cidr ORIGINAL LICENSE is:
Copyright (c) 2015 Martin Atkins Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************
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 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 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 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
Types ¶
This section is empty.