ipcalc

package
v0.1.0-rc16 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAvailableIP    = errors.New("no available IP address")
	ErrNoAvailableMac   = errors.New("no available MAC address")
	ErrNetworkConflict  = errors.New("network CIDR conflict")
	ErrIPRangesConflict = errors.New("ip ranges conflict")
)

Functions

func AddIPToRange

func AddIPToRange(ip net.IP, ipRanges []flv1.IPRange) []flv1.IPRange

AddIPToRange adds an IP address to IPRange.

func CheckIPRangesConflict

func CheckIPRangesConflict(ranges1, ranges2 []flv1.IPRange) error

func CheckNetworkConflict

func CheckNetworkConflict(cidr1, cidr2 string) error

func GetAvailableIP

func GetAvailableIP(
	cidr string, ipRanges []flv1.IPRange, usedIPs []flv1.IPRange,
) (net.IP, error)

GetAvailableIP gets a **16bytes length** IP address by CIDR and IPRange. ErrNoAvailableIP error will be returned if no IP address resource available.

func GetDefaultGateway

func GetDefaultGateway(CIDR string) (net.IP, error)

GetDefaultGateway returns **16 bytes** IP address by CIDR.

Example:

CIDR `192.168.1.0/24` -> return `192.168.1.1`.

func IPDecrease

func IPDecrease(ip net.IP)

IPIncrease decreases the provided IP address.

func IPInNetwork

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

func IPInRanges

func IPInRanges(ip net.IP, ipRanges []flv1.IPRange) bool

IPInRanges checks whether the address is in the IPRange.

func IPIncrease

func IPIncrease(ip net.IP)

IPIncrease increases the provided IP address.

func IsAvailableIP

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

IsAvailableIP returns true if the provided IP address is not a broadcast and not a network address.

func IsBroadCast

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

IsBroadCast checks if the IP address is the broadcast address of the network.

func IsNetwork

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

IsNetwork checks if the IP address is the network address itself.

func MaskXOR

func MaskXOR(mask net.IPMask) net.IPMask

MaskXOR returns the XOR-ed network mask.

Example:

input '255.255.240.0' -> return '0.0.15.255'

func RemoveIPFromRange

func RemoveIPFromRange(ip net.IP, ipRanges []flv1.IPRange) []flv1.IPRange

RemoveIPFromRange removes an IP address from IPRange.

Types

This section is empty.

Jump to

Keyboard shortcuts

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