Documentation
¶
Overview ¶
Package ipcalc provides network utilities for performing IP address arithmetic.
Note that next/prev functions are subject to wrapping, e.g., NextIP(255.255.255.255) -> 0.0.0.0.
Index ¶
- func Add(a, b net.IP, mask net.IPMask) net.IP
- func And(a, b net.IP) net.IP
- func Broadcast(n net.IPNet) net.IP
- func Complement(mask net.IPMask) net.IPMask
- func Contains(a, b net.IPNet) bool
- func CopyIP(ip net.IP) net.IP
- func IP(ip net.IP) net.IP
- func IPSize(ip net.IP) int
- func IPVersion(ip net.IP) int
- func Merge(a, b net.IP, mask net.IPMask) net.IP
- func NextIP(ip net.IP) net.IP
- func NextSubnet(n net.IPNet) net.IPNet
- func Or(a, b net.IP) net.IP
- func ParseIPMask(addr string) (net.IP, net.IPMask, error)
- func ParseMask(mask string) net.IPMask
- func PrevIP(ip net.IP) net.IP
- func PrevSubnet(n net.IPNet) net.IPNet
- func Substract(a, b net.IP, mask net.IPMask) net.IP
- func Xor(a, b net.IP) net.IP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add returns the sum of two net.IP addresses with the given mask. e.g., Add(192.168.0.1, 192.168.0.2, 0.0.0.255) -> 192.168.0.3.
func And ¶
And returns the bitwise AND of two net.IP addresses. e.g., And(192.168.0.255, 192.168.255.128) -> 192.168.0.128.
func Complement ¶
Complement returns the complement of a given net.IPMask, commonly used as a Wildcard Mask. e.g., Complement(255.255.254.0) -> 0.0.1.255.
func Contains ¶
Contains returns whether the first net.IPNet wholly contains the second one. If either net has a non-standard mask then the result is undefined.
func Merge ¶
Merge combines two net.IP addresses with the given mask. For bit i, if mask[i] is set then b[i] is returned, otherwise a[i] is returned. e.g., Merge(192.168.0.1, 172.16.32.100, 0.0.0.255) -> 192.168.0.100.
func NextSubnet ¶
NextSubnet returns the next subnet. e.g., NextSubnet(192.168.0.0/24) -> 192.168.1.0/24.
func Or ¶
Or returns the bitwise OR of two net.IP addresses. e.g., Or(192.168.0.15, 192.168.10.128) -> 192.168.0.128.
func ParseIPMask ¶
ParseIPMask returns a net.IP and net.IPMask from an ip[/mask] string representation. The IPMask need not be in CIDR format, if it starts with ~ then it will be inverted.
func PrevSubnet ¶
PrevSubnet returns the previous subnet. e.g., PrevSubnet(192.168.1.0/24) -> 192.168.0.0/24.
Types ¶
This section is empty.