Documentation ¶
Index ¶
- func Cmp(a, b net.IP) int
- func Distance(a, b net.IP) int64
- func GetSubnetGen(network *net.IPNet, prefixSize int32) func() *net.IPNet
- func IsBroadcast(ip net.IP, network *net.IPNet) bool
- func IsPointToPointSubnet(network *net.IPNet) bool
- func IsSingleIPSubnet(network *net.IPNet) bool
- func LastIP(network *net.IPNet) net.IP
- func NextIP(ip net.IP) net.IP
- func NextIPWithOffset(ip net.IP, offset int64) net.IP
- func NormalizeIP(ip net.IP) net.IP
- func PrevIP(ip net.IP) net.IP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cmp ¶
Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1 incomparable : -2
func Distance ¶
Distance returns amount of IPs between a and b returns -1 if result is negative returns -2 if result is too large or IPs are not valid addresses
func GetSubnetGen ¶ added in v0.2.0
GetSubnetGen returns generator function that can be called multiple times to generate subnet for the network with the prefix size. The function always returns non-nil function. The generator function will return nil If subnet can't be generate (invalid input args provided, or no more subnets available for the network). Example: _, network, _ := net.ParseCIDR("192.168.0.0/23") gen := GetSubnetGen(network, 25) println(gen().String()) // 192.168.0.0/25 println(gen().String()) // 192.168.0.128/25 println(gen().String()) // 192.168.1.0/25 println(gen().String()) // 192.168.1.128/25 println(gen().String()) // <nil> - no more ranges available
func IsBroadcast ¶
IsBroadcast returns true if provided IP is IPv4 Broadcast ip of the network
func IsPointToPointSubnet ¶ added in v0.2.0
IsPointToPointSubnet returns true if the network is point to point (/31 or /127)
func IsSingleIPSubnet ¶ added in v0.3.5
IsSingleIPSubnet returns true if the network is a single IP subnet (/32 or /128)
func LastIP ¶ added in v0.2.0
LastIP returns the last IP of a subnet, excluding the broadcast if IPv4 (if not /31 net)
func NextIPWithOffset ¶
NextIPWithOffset returns IP incremented by offset, if IP is invalid, return nil
func NormalizeIP ¶ added in v0.1.0
NormalizeIP will normalize IP by family, IPv4 : 4-byte form IPv6 : 16-byte form others : nil
Types ¶
This section is empty.