netutils

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 12 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 AllIPV4AddrRange = IPV4AddrRange{
	// contains filtered or unexported fields
}
View Source
var AllIPV6AddrRange = IPV6AddrRange{
	// contains filtered or unexported fields
}
View Source
var IPV4Ones = IPV4Addr(0xffffffff)
View Source
var IPV4Zero = IPV4Addr(0)
View Source
var IPV6Ones = IPV6Addr([8]uint16{0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff})
View Source
var IPV6Zero = IPV6Addr([8]uint16{0, 0, 0, 0, 0, 0, 0, 0})
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 GetHttpRequestIp added in v1.10.2

func GetHttpRequestIp(r *http.Request) string

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) ToIP added in v1.10.2

func (addr IPV4Addr) ToIP() net.IP

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) Compare added in v1.10.2

func (v4range IPV4AddrRange) Compare(r2 IPV4AddrRange) sortutils.CompareResult

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) IsAll added in v1.10.2

func (r IPV4AddrRange) IsAll() bool

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) ([]IPV4AddrRange, *IPV4AddrRange)

func (IPV4AddrRange) Substract2 added in v1.10.2

func (ar IPV4AddrRange) Substract2(ar2 IPV4AddrRange) ([]IPV4AddrRange, bool, IPV4AddrRange)

func (IPV4AddrRange) ToIPNets

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

func (IPV4AddrRange) ToPrefixes added in v1.10.2

func (ar IPV4AddrRange) ToPrefixes() []IPV4Prefix

type IPV4AddrRangeList added in v1.10.2

type IPV4AddrRangeList []IPV4AddrRange

func (IPV4AddrRangeList) Len added in v1.10.2

func (rl IPV4AddrRangeList) Len() int

func (IPV4AddrRangeList) Less added in v1.10.2

func (rl IPV4AddrRangeList) Less(i, j int) bool

func (IPV4AddrRangeList) Merge added in v1.10.2

func (rl IPV4AddrRangeList) Merge() []IPV4AddrRange

func (IPV4AddrRangeList) String added in v1.10.2

func (rl IPV4AddrRangeList) String() string

func (IPV4AddrRangeList) Substract added in v1.10.2

func (rl IPV4AddrRangeList) Substract(addrRange IPV4AddrRange) []IPV4AddrRange

func (IPV4AddrRangeList) Swap added in v1.10.2

func (rl IPV4AddrRangeList) Swap(i, j int)

type IPV4Prefix

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

func NewIPV4Prefix

func NewIPV4Prefix(prefix string) (IPV4Prefix, error)

func NewIPV4PrefixFromAddr added in v1.10.2

func NewIPV4PrefixFromAddr(addr IPV4Addr, masklen int8) IPV4Prefix

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) ToIPNet added in v1.10.2

func (pref IPV4Prefix) ToIPNet() *net.IPNet

func (IPV4Prefix) ToIPRange

func (prefix IPV4Prefix) ToIPRange() IPV4AddrRange

type IPV6Addr added in v1.10.0

type IPV6Addr [8]uint16

func Mac2LinkLocal added in v1.10.2

func Mac2LinkLocal(mac string) (IPV6Addr, error)

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

func (IPV6Addr) ToBytes added in v1.10.2

func (addr IPV6Addr) ToBytes() []byte

func (IPV6Addr) ToIP added in v1.10.2

func (addr IPV6Addr) ToIP() net.IP

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) Compare added in v1.10.2

func (v6range IPV6AddrRange) Compare(r2 IPV6AddrRange) sortutils.CompareResult

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) IsAll added in v1.10.2

func (r IPV6AddrRange) IsAll() bool

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

func (IPV6AddrRange) Substract added in v1.10.2

func (ar IPV6AddrRange) Substract(ar2 IPV6AddrRange) ([]IPV6AddrRange, *IPV6AddrRange)

func (IPV6AddrRange) Substract2 added in v1.10.2

func (ar IPV6AddrRange) Substract2(ar2 IPV6AddrRange) ([]IPV6AddrRange, bool, IPV6AddrRange)

func (IPV6AddrRange) ToIPNets added in v1.10.2

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

func (IPV6AddrRange) ToPrefixes added in v1.10.2

func (ar IPV6AddrRange) ToPrefixes() []IPV6Prefix

type IPV6AddrRangeList added in v1.10.2

type IPV6AddrRangeList []IPV6AddrRange

func (IPV6AddrRangeList) Len added in v1.10.2

func (rl IPV6AddrRangeList) Len() int

func (IPV6AddrRangeList) Less added in v1.10.2

func (rl IPV6AddrRangeList) Less(i, j int) bool

func (IPV6AddrRangeList) Merge added in v1.10.2

func (rl IPV6AddrRangeList) Merge() []IPV6AddrRange

func (IPV6AddrRangeList) String added in v1.10.2

func (rl IPV6AddrRangeList) String() string

func (IPV6AddrRangeList) Substract added in v1.10.2

func (rl IPV6AddrRangeList) Substract(addrRange IPV6AddrRange) []IPV6AddrRange

func (IPV6AddrRangeList) Swap added in v1.10.2

func (rl IPV6AddrRangeList) Swap(i, j int)

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 NewIPV6PrefixFromAddr added in v1.10.2

func NewIPV6PrefixFromAddr(addr IPV6Addr, masklen uint8) IPV6Prefix

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) ToIPNet added in v1.10.2

func (pref IPV6Prefix) ToIPNet() *net.IPNet

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