ip

package
v3.7.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: Apache-2.0 Imports: 6 Imported by: 182

Documentation

Overview

The ip package contains yet another IP address (and CIDR) type :-). The types differ from the ones in the net package in that they are backed by fixed-sized arrays of the appropriate size. The key advantage of using a fixed-size array is that it makes the types hashable so they can be used as map keys. In addition, they can be converted to net.IP by slicing.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidIP = errors.New("Failed to parse IP address")

Functions

This section is empty.

Types

type Addr

type Addr interface {
	// Version returns the IP version; 4 or 6.
	Version() uint8
	// AsNetIP returns a net.IP, which is backed by/shares storage with
	// this object.
	AsNetIP() net.IP
	AsCalicoNetIP() calinet.IP
	AsCIDR() CIDR
	String() string
}

Addr represents either an IPv4 or IPv6 IP address.

func FromNetIP

func FromNetIP(netIP net.IP) Addr

func FromString

func FromString(s string) Addr

type CIDR

type CIDR interface {
	Version() uint8
	Addr() Addr
	Prefix() uint8
	String() string
	ToIPNet() net.IPNet
}

func CIDRFromCalicoNet

func CIDRFromCalicoNet(ipNet calinet.IPNet) CIDR

func CIDRFromIPNet

func CIDRFromIPNet(ipNet *net.IPNet) CIDR

func CIDRFromNetIP

func CIDRFromNetIP(netIP net.IP) CIDR

CIDRFromNetIP converts the given IP into our CIDR representation as a /32 or /128.

func CIDRFromString

func CIDRFromString(cidrStr string) (CIDR, error)

func MustParseCIDROrIP

func MustParseCIDROrIP(s string) CIDR

MustParseCIDROrIP parses the given IP address or CIDR, treating IP addresses as "full length" CIDRs. For example, "10.0.0.1" is treated as "10.0.0.1/32". It panics on failure.

func ParseCIDROrIP

func ParseCIDROrIP(s string) (CIDR, error)

ParseCIDROrIP parses the given IP address or CIDR, treating IP addresses as "full length" CIDRs. For example, "10.0.0.1" is treated as "10.0.0.1/32".

type V4Addr

type V4Addr [4]byte

func (V4Addr) AsCIDR

func (a V4Addr) AsCIDR() CIDR

func (V4Addr) AsCalicoNetIP

func (a V4Addr) AsCalicoNetIP() calinet.IP

func (V4Addr) AsNetIP

func (a V4Addr) AsNetIP() net.IP

func (V4Addr) String

func (a V4Addr) String() string

func (V4Addr) Version

func (a V4Addr) Version() uint8

type V4CIDR

type V4CIDR struct {
	// contains filtered or unexported fields
}

func (V4CIDR) Addr

func (c V4CIDR) Addr() Addr

func (V4CIDR) Prefix

func (c V4CIDR) Prefix() uint8

func (V4CIDR) String

func (c V4CIDR) String() string

func (V4CIDR) ToIPNet

func (c V4CIDR) ToIPNet() net.IPNet

func (V4CIDR) Version

func (c V4CIDR) Version() uint8

type V6Addr

type V6Addr [16]byte

func (V6Addr) AsCIDR

func (a V6Addr) AsCIDR() CIDR

func (V6Addr) AsCalicoNetIP

func (a V6Addr) AsCalicoNetIP() calinet.IP

func (V6Addr) AsNetIP

func (a V6Addr) AsNetIP() net.IP

func (V6Addr) String

func (a V6Addr) String() string

func (V6Addr) Version

func (a V6Addr) Version() uint8

type V6CIDR

type V6CIDR struct {
	// contains filtered or unexported fields
}

func (V6CIDR) Addr

func (c V6CIDR) Addr() Addr

func (V6CIDR) Prefix

func (c V6CIDR) Prefix() uint8

func (V6CIDR) String

func (c V6CIDR) String() string

func (V6CIDR) ToIPNet

func (c V6CIDR) ToIPNet() net.IPNet

func (V6CIDR) Version

func (c V6CIDR) Version() uint8

Jump to

Keyboard shortcuts

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