netutils

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 123

Documentation

Index

Constants

View Source
const MaxUint16 = uint16(0xffff)

Variables

View Source
var (
	ErrInvalidNumber  = errors.Error("invalid number")
	ErrOutOfRange     = errors.Error("ip number out of range [0-255]")
	ErrInvalidIPAddr  = errors.Error("invalid ip address")
	ErrInvalidMask    = errors.Error("invalid mask")
	ErrOutOfRangeMask = errors.Error("out of range masklen [0-32]")
)
View Source
var MASKS = []string{"0", "128", "192", "224", "240", "248", "252", "254", "255"}

Functions

func DeriveIPv6AddrFromIPv4AddrMac added in v1.10.0

func DeriveIPv6AddrFromIPv4AddrMac(ipAddr string, macAddr string, startIp6, endIp6 string, maskLen6 uint8) string

func ErrMacFormat added in v1.10.0

func ErrMacFormat(macStr string) error

func FormatMacAddr

func FormatMacAddr(macAddr string) string

func GetFreePort added in v1.10.0

func GetFreePort() (int, error)

func IP2Number

func IP2Number(ipstr string) (uint32, error)

func IsExitAddress

func IsExitAddress(addr IPV4Addr) bool

func IsHostLocal

func IsHostLocal(addr IPV4Addr) bool

func IsLinkLocal

func IsLinkLocal(addr IPV4Addr) bool

func IsMulticast

func IsMulticast(addr IPV4Addr) bool

func IsPrivate

func IsPrivate(addr IPV4Addr) bool

func MacUnpackHex

func MacUnpackHex(mac string) string

func Mask2Len

func Mask2Len(mask IPV4Addr) int8

func Netlen2Mask added in v1.10.0

func Netlen2Mask(netmasklen int) string

func Number2Bytes

func Number2Bytes(num uint32) []byte

func Number2IP

func Number2IP(num uint32) string

func SetPrivatePrefixes

func SetPrivatePrefixes(pref []string)

Types

type IPV4Addr

type IPV4Addr uint32

func Masklen2Mask

func Masklen2Mask(maskLen int8) IPV4Addr

func NewIPV4Addr

func NewIPV4Addr(ipstr string) (IPV4Addr, error)

func ParsePrefix

func ParsePrefix(prefix string) (IPV4Addr, int8, error)

func (IPV4Addr) BroadcastAddr

func (addr IPV4Addr) BroadcastAddr(maskLen int8) IPV4Addr

func (IPV4Addr) CliAddr

func (addr IPV4Addr) CliAddr(maskLen int8) IPV4Addr

func (IPV4Addr) NetAddr

func (addr IPV4Addr) NetAddr(maskLen int8) IPV4Addr

func (IPV4Addr) StepDown

func (addr IPV4Addr) StepDown() IPV4Addr

func (IPV4Addr) StepUp

func (addr IPV4Addr) StepUp() IPV4Addr

func (IPV4Addr) String

func (addr IPV4Addr) String() string

func (IPV4Addr) ToBytes

func (addr IPV4Addr) ToBytes() []byte

func (IPV4Addr) ToMac

func (addr IPV4Addr) ToMac(prefix string) string

type IPV4AddrRange

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

func GetPrivateIPRanges

func GetPrivateIPRanges() []IPV4AddrRange

func NewIPV4AddrRange

func NewIPV4AddrRange(ip1 IPV4Addr, ip2 IPV4Addr) IPV4AddrRange

func NewIPV4AddrRangeFromIPNet

func NewIPV4AddrRangeFromIPNet(n *net.IPNet) IPV4AddrRange

n.IP and n.Mask must be ipv4 type. n.Mask must be canonical

func (IPV4AddrRange) AddressCount

func (ar IPV4AddrRange) AddressCount() int

func (IPV4AddrRange) Contains

func (ar IPV4AddrRange) Contains(ip IPV4Addr) bool

func (IPV4AddrRange) ContainsRange

func (ar IPV4AddrRange) ContainsRange(ar2 IPV4AddrRange) bool

func (IPV4AddrRange) EndIp

func (ar IPV4AddrRange) EndIp() IPV4Addr

func (IPV4AddrRange) IsOverlap

func (ar IPV4AddrRange) IsOverlap(ar2 IPV4AddrRange) bool

func (IPV4AddrRange) Merge

func (ar IPV4AddrRange) Merge(ar2 IPV4AddrRange) (*IPV4AddrRange, bool)

func (IPV4AddrRange) Random

func (ar IPV4AddrRange) Random() IPV4Addr

func (*IPV4AddrRange) Set added in v1.10.0

func (ar *IPV4AddrRange) Set(ip1 IPV4Addr, ip2 IPV4Addr)

func (IPV4AddrRange) StartIp

func (ar IPV4AddrRange) StartIp() IPV4Addr

func (IPV4AddrRange) String

func (ar IPV4AddrRange) String() string

func (IPV4AddrRange) Substract

func (ar IPV4AddrRange) Substract(ar2 IPV4AddrRange) (lefts []IPV4AddrRange, sub *IPV4AddrRange)

func (IPV4AddrRange) ToIPNets

func (ar IPV4AddrRange) ToIPNets() []*net.IPNet

func (IPV4AddrRange) ToMaskMatches

func (ar IPV4AddrRange) ToMaskMatches() [][2]uint32

type IPV4Prefix

type IPV4Prefix struct {
	Address IPV4Addr
	MaskLen int8
	// contains filtered or unexported fields
}

func NewIPV4Prefix

func NewIPV4Prefix(prefix string) (IPV4Prefix, error)

func (IPV4Prefix) Contains

func (prefix IPV4Prefix) Contains(ip IPV4Addr) bool

func (*IPV4Prefix) Equals

func (pref *IPV4Prefix) Equals(pref1 *IPV4Prefix) bool

func (*IPV4Prefix) String

func (pref *IPV4Prefix) String() string

func (IPV4Prefix) ToIPRange

func (prefix IPV4Prefix) ToIPRange() IPV4AddrRange

type IPV6Addr added in v1.10.0

type IPV6Addr [8]uint16

func NewIPV6Addr added in v1.10.0

func NewIPV6Addr(ipstr string) (IPV6Addr, error)

func ParsePrefix6 added in v1.10.0

func ParsePrefix6(prefix string) (IPV6Addr, uint8, error)

func (IPV6Addr) BroadcastAddr added in v1.10.0

func (addr IPV6Addr) BroadcastAddr(maskLen uint8) IPV6Addr

func (IPV6Addr) Equals added in v1.10.0

func (addr IPV6Addr) Equals(addr2 IPV6Addr) bool

func (IPV6Addr) Ge added in v1.10.0

func (addr IPV6Addr) Ge(addr2 IPV6Addr) bool

func (IPV6Addr) Gt added in v1.10.0

func (addr IPV6Addr) Gt(addr2 IPV6Addr) bool

func (IPV6Addr) HostAddr added in v1.10.0

func (addr IPV6Addr) HostAddr(hostAddr IPV6Addr, maskLen uint8) IPV6Addr

func (IPV6Addr) Le added in v1.10.0

func (addr IPV6Addr) Le(addr2 IPV6Addr) bool

func (IPV6Addr) Lt added in v1.10.0

func (addr IPV6Addr) Lt(addr2 IPV6Addr) bool

func (IPV6Addr) NetAddr added in v1.10.0

func (addr IPV6Addr) NetAddr(maskLen uint8) IPV6Addr

func (IPV6Addr) StepDown added in v1.10.0

func (addr IPV6Addr) StepDown() IPV6Addr

func (IPV6Addr) StepUp added in v1.10.0

func (addr IPV6Addr) StepUp() IPV6Addr

func (IPV6Addr) String added in v1.10.0

func (addr IPV6Addr) String() string

type IPV6AddrRange added in v1.10.0

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

func NewIPV6AddrRange added in v1.10.0

func NewIPV6AddrRange(ip1 IPV6Addr, ip2 IPV6Addr) IPV6AddrRange

func NewIPV6AddrRangeFromIPNet added in v1.10.0

func NewIPV6AddrRangeFromIPNet(n *net.IPNet) IPV6AddrRange

n.IP and n.Mask must be ipv4 type. n.Mask must be canonical

func (IPV6AddrRange) Contains added in v1.10.0

func (ar IPV6AddrRange) Contains(ip IPV6Addr) bool

func (IPV6AddrRange) ContainsRange added in v1.10.0

func (ar IPV6AddrRange) ContainsRange(ar2 IPV6AddrRange) bool

func (IPV6AddrRange) EndIp added in v1.10.0

func (ar IPV6AddrRange) EndIp() IPV6Addr

func (IPV6AddrRange) IsOverlap added in v1.10.0

func (ar IPV6AddrRange) IsOverlap(ar2 IPV6AddrRange) bool

func (IPV6AddrRange) Merge added in v1.10.0

func (ar IPV6AddrRange) Merge(ar2 IPV6AddrRange) (*IPV6AddrRange, bool)

func (IPV6AddrRange) Random added in v1.10.0

func (ar IPV6AddrRange) Random() IPV6Addr

func (*IPV6AddrRange) Set added in v1.10.0

func (ar *IPV6AddrRange) Set(ip1 IPV6Addr, ip2 IPV6Addr)

func (IPV6AddrRange) StartIp added in v1.10.0

func (ar IPV6AddrRange) StartIp() IPV6Addr

func (IPV6AddrRange) String added in v1.10.0

func (ar IPV6AddrRange) String() string

type IPV6Prefix added in v1.10.0

type IPV6Prefix struct {
	Address IPV6Addr
	MaskLen uint8
	// contains filtered or unexported fields
}

func NewIPV6Prefix added in v1.10.0

func NewIPV6Prefix(prefix string) (IPV6Prefix, error)

func (IPV6Prefix) Contains added in v1.10.0

func (prefix IPV6Prefix) Contains(ip IPV6Addr) bool

func (*IPV6Prefix) Equals added in v1.10.0

func (pref *IPV6Prefix) Equals(pref1 *IPV6Prefix) bool

func (*IPV6Prefix) String added in v1.10.0

func (pref *IPV6Prefix) String() string

func (IPV6Prefix) ToIPRange added in v1.10.0

func (prefix IPV6Prefix) ToIPRange() IPV6AddrRange

type SMacAddr added in v1.10.0

type SMacAddr [6]byte

func ParseMac added in v1.10.0

func ParseMac(macStr string) (SMacAddr, error)

func (SMacAddr) Add added in v1.10.0

func (mac SMacAddr) Add(step int) SMacAddr

func (SMacAddr) String added in v1.10.0

func (mac SMacAddr) String() string

Jump to

Keyboard shortcuts

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