myaddr

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: BSD-2-Clause Imports: 4 Imported by: 2

README

Overview

Build Status PkgGoDev

myaddr is a golang module for IPv4/IPv6 address, hardware(MAC) address and VLAN ID manipulation

Documentation

Overview

Package myaddr is Go module that provides varies functions to processing address, include IP address, MAC address and VLAN ID.

Index

Constants

View Source
const (
	MaxIPv4AddrN   = 4294967295
	MaxMACAddrN    = 281474976710655
	MaxIPv6AddrStr = "340282366920938463463374607431768211455"
)

MAX Values

Variables

This section is empty.

Functions

func AddrtoBig

func AddrtoBig(addr net.IP) *big.Int

AddrtoBig convert IP address to *big.Int

func BigtoAddr

func BigtoAddr(n *big.Int, ipv4 bool) (net.IP, error)

BigtoAddr convert n to IPv4 address if ipv4 is true, IPv6 address otherwise

func BigtoHWAddr

func BigtoHWAddr(n *big.Int, alen int) (net.HardwareAddr, error)

BigtoHWAddr convert n to a hardware address, with specified alen

func BigtoMACAddr

func BigtoMACAddr(n *big.Int) (net.HardwareAddr, error)

BigtoMACAddr convert n to a MAC address

func GenAddrWithIPNet added in v0.1.2

func GenAddrWithIPNet(prefix *net.IPNet, hostn *big.Int) (net.IP, error)

GenAddrWithIPNet geneate an address = prefix + hostn. hostn must>=0

func GenConnectionAddrStr

func GenConnectionAddrStr(prefix string, ip net.IP, port int) string

GenConnectionAddrStr return a string with following format: IPv4: <prefix><ip>:<port> IPv6: <prefix>[<ip>]:<port>

func GenPrefixWithPrefix added in v0.1.3

func GenPrefixWithPrefix(prefix netip.Prefix, hostn *big.Int) (netip.Prefix, error)

GenPrefixWithPrefix geneate an prefix = prefix + hostn. hostn must>=0

func GetLLAFromMac added in v0.1.1

func GetLLAFromMac(mac net.HardwareAddr) net.IP

GetLLAFromMac return an IPv6 link local address from mac, based on Appendix A of RFC4291

func HWAddrtoBig

func HWAddrtoBig(addr net.HardwareAddr) *big.Int

HWAddrtoBig convert hardware address to *big.Int

func IncAddr

func IncAddr(addr net.IP, step *big.Int) (net.IP, error)

IncAddr increase addr by step (could be negative), return the result

func IncMACAddr

func IncMACAddr(macaddr net.HardwareAddr, step *big.Int) (net.HardwareAddr, error)

IncMACAddr increase macaddr by step (could be negative), return the result

func IncreaseVLANIDs

func IncreaseVLANIDs(ids []uint16, step int) ([]uint16, error)

IncreaseVLANIDs increase a slice of VLAN Id (12 bit long) with specified step

Types

This section is empty.

Jump to

Keyboard shortcuts

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