net

package
v1.11.0-cni-plu...-ddfc3b1 Latest Latest
Warning

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

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

Documentation

Overview

Package net implements a set of net types that are extensions to the built-in net package. The extensions provide additional function such as JSON marshaling and unmarshaling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPToBigInt

func IPToBigInt(ip IP) *big.Int

func ParseCIDR

func ParseCIDR(c string) (*IP, *IPNet, error)

func ParseCIDROrIP

func ParseCIDROrIP(c string) (*IP, *IPNet, error)

Parse a CIDR or an IP address and return the IP, CIDR or error. If an IP address string is supplied, then the CIDR returned is the fully masked IP address (i.e /32 or /128)

Types

type IP

type IP struct {
	net.IP
}

Sub class net.IP so that we can add JSON marshalling and unmarshalling.

func BigIntToIP

func BigIntToIP(ipInt *big.Int, v6 bool) IP

func IncrementIP

func IncrementIP(ip IP, increment *big.Int) IP

func MustParseIP

func MustParseIP(i string) IP

MustParseIP parses the string into an IP.

func ParseIP

func ParseIP(ip string) *IP

ParseIP returns an IP from a string

func (IP) MarshalJSON

func (i IP) MarshalJSON() ([]byte, error)

MarshalJSON interface for an IP

func (*IP) Network

func (i *IP) Network() *IPNet

Network returns the IP address as a fully masked IPNet type.

func (*IP) UnmarshalJSON

func (i *IP) UnmarshalJSON(b []byte) error

UnmarshalJSON interface for an IP

func (IP) Version

func (i IP) Version() int

Version returns the IP version for an IP, or 0 if the IP is not valid.

type IPNet

type IPNet struct {
	net.IPNet
}

Sub class net.IPNet so that we can add JSON marshalling and unmarshalling.

func MustParseCIDR

func MustParseCIDR(c string) IPNet

MustParseCIDR parses the string into an IPNet. The IP address in the IPNet is not masked.

func MustParseNetwork

func MustParseNetwork(c string) IPNet

MustParseNetwork parses the string into an IPNet. The IP address in the IPNet is masked.

func (IPNet) Covers

func (i IPNet) Covers(n net.IPNet) bool

Covers returns true if the whole of n is covered by this CIDR.

func (IPNet) IsNetOverlap

func (i IPNet) IsNetOverlap(n net.IPNet) bool

IsNetOverlap is a utility function that returns true if the two subnet have an overlap.

func (IPNet) MarshalJSON

func (i IPNet) MarshalJSON() ([]byte, error)

MarshalJSON interface for an IPNet

func (*IPNet) Network

func (i *IPNet) Network() *IPNet

Network returns the masked IP network.

func (IPNet) NthIP

func (i IPNet) NthIP(n int) IP

func (IPNet) NumAddrs

func (i IPNet) NumAddrs() *big.Int

func (IPNet) String

func (i IPNet) String() string

String returns a friendly name for the network. The standard net package implements String() on the pointer, which means it will not be invoked on a struct type, so we re-implement on the struct type.

func (*IPNet) UnmarshalJSON

func (i *IPNet) UnmarshalJSON(b []byte) error

UnmarshalJSON interface for an IPNet

func (*IPNet) Version

func (i *IPNet) Version() int

Version returns the IP version for an IPNet, or 0 if not a valid IP net.

type MAC

type MAC struct {
	net.HardwareAddr
}

Sub class net.HardwareAddr so that we can add JSON marshalling and unmarshalling.

func (MAC) MarshalJSON

func (m MAC) MarshalJSON() ([]byte, error)

MarshalJSON interface for a MAC

func (*MAC) UnmarshalJSON

func (m *MAC) UnmarshalJSON(b []byte) error

UnmarshalJSON interface for a MAC

Jump to

Keyboard shortcuts

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