address

package
v0.0.0-...-507ffb6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package address contains network address manipulation utilities.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyAddress is returned when the provided string representation of an
	// address is empty.
	ErrEmptyAddress = errors.New("empty address")
)

Functions

This section is empty.

Types

type ExtraAddresses

type ExtraAddresses struct {
	// ForwardedIPs contains the forwarded IPs.
	ForwardedIPs IPAddressMap
	// TargetInstanceIPs contains the target instance IPs.
	TargetInstanceIPs IPAddressMap
	// IPAliases contains the IP aliases.
	IPAliases IPAddressMap
}

ExtraAddresses contains the extra addresses of a NIC.

func NewExtraAddresses

func NewExtraAddresses(nic *metadata.NetworkInterface, config *cfg.Sections, ignore IPAddressMap) *ExtraAddresses

NewExtraAddresses returns a new ExtraAddresses object having addresses ignored from the provided ignore map.

func (*ExtraAddresses) MergedMap

func (c *ExtraAddresses) MergedMap() IPAddressMap

MergedMap returns a map of IP addresses that are merged from the ForwardedIPs, TargetInstanceIPs and IPAliases.

func (*ExtraAddresses) MergedSlice

func (c *ExtraAddresses) MergedSlice() []*IPAddr

MergedSlice returns a slice of IP addresses that are merged from the ForwardedIPs, TargetInstanceIPs and IPAliases. It will sort the slice by the IP address string representation.

type IPAddr

type IPAddr struct {
	IP   *net.IP
	CIDR *net.IPNet
}

IPAddr is a struct containing an IP address and its CIDR.

func ParseIP

func ParseIP(ip string) (*IPAddr, error)

ParseIP parses an IP address string into a net.IP. Input data may be CIDR notation address or regular IP address, this function takes that into account and attempt to parse it as CIDR if it fails then it tries to parse as a regular IP.

func (*IPAddr) IsIPv6

func (i *IPAddr) IsIPv6() bool

IsIPv6 returns true if the IP address is an IPv4 address.

func (*IPAddr) Mask

func (i *IPAddr) Mask() (net.IPMask, error)

Mask returns the netmask of the IP address.

func (*IPAddr) NetAddr

func (i *IPAddr) NetAddr() netip.Addr

NetAddr returns the netip.Addr representation of the IP address.

func (*IPAddr) String

func (i *IPAddr) String() string

String returns the string representation of the IP address. If the IP address is a CIDR address, the string representation will be in CIDR notation.

type IPAddressMap

type IPAddressMap map[string]*IPAddr

IPAddressMap is a map of IP addresses, it's indexed by the string representation of the IP address and the value is the IP address wrapped into a net.IP object.

func MergeIPAddressMap

func MergeIPAddressMap(args ...IPAddressMap) IPAddressMap

MergeIPAddressMap merges the given IP address maps into a single map.

func NewIPAddressMap

func NewIPAddressMap(addresses []string, ignore IPAddressMap) IPAddressMap

NewIPAddressMap returns a new IP address map from the given addresses slice.

func (IPAddressMap) Add

func (m IPAddressMap) Add(addr *IPAddr)

Add adds the given IP address to the map.

func (IPAddressMap) FormatIPs

func (m IPAddressMap) FormatIPs() string

FormatIPs returns a string representation of the IP address map.

func (IPAddressMap) IPs

func (m IPAddressMap) IPs() []string

IPs returns the list of IP addresses in the map.

func (IPAddressMap) RemoveAddresses

func (m IPAddressMap) RemoveAddresses(addresses []string)

RemoveAddresses removes the given addresses from the map.

func (IPAddressMap) RemoveIPAddrs

func (m IPAddressMap) RemoveIPAddrs(addr []*IPAddr)

RemoveIPAddrs removes the given IP addresses from the map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳