ip

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmp

func Cmp(a, b net.IP) int

Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1 incomparable : -2

func Distance

func Distance(a, b net.IP) int64

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

func GetSubnetGen(network *net.IPNet, prefixSize int32) func() *net.IPNet

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

func IsBroadcast(ip net.IP, network *net.IPNet) bool

IsBroadcast returns true if provided IP is IPv4 Broadcast ip of the network

func IsPointToPointSubnet added in v0.2.0

func IsPointToPointSubnet(network *net.IPNet) bool

IsPointToPointSubnet returns true if the network is point to point (/31 or /127)

func LastIP added in v0.2.0

func LastIP(network *net.IPNet) net.IP

LastIP returns the last IP of a subnet, excluding the broadcast if IPv4 (if not /31 net)

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns IP incremented by 1, if IP is invalid, return nil

func NextIPWithOffset

func NextIPWithOffset(ip net.IP, offset int64) net.IP

NextIPWithOffset returns IP incremented by offset, if IP is invalid, return nil

func NormalizeIP added in v0.1.0

func NormalizeIP(ip net.IP) net.IP

NormalizeIP will normalize IP by family, IPv4 : 4-byte form IPv6 : 16-byte form others : nil

func PrevIP

func PrevIP(ip net.IP) net.IP

PrevIP returns IP decremented by 1, if IP is invalid, return nil

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL