netutil

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 8 Imported by: 2

README

netutil

netutil provides some Go network utility functions.

Documentation

Overview

Package netutil provides some network utility functions. Some of them are supported only on Linux.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAddr

func AddAddr(intf *net.Interface, ip net.IP, ipNet *net.IPNet, label string) error

AddAddr adds the specified IP address to the interface.

func DelAddr

func DelAddr(intf *net.Interface, ip net.IP, ipNet *net.IPNet) error

DelAddr deletes the specified IP address from the interface.

func HasAddr

func HasAddr(intf *net.Interface, ip net.IP) (bool, error)

HasAddr returns whether or not the interface has the specified IP address.

func IPNetEqual

func IPNetEqual(ipNet1, ipNet2 *net.IPNet) bool

IPNetEqual resports whether ipNet1 and ipNet2 are the same IP network.

func IPNetTo4IfV4

func IPNetTo4IfV4(ipNet *net.IPNet) *net.IPNet

IPNetTo4IfV4 returns the IP network with IP replaced with IPto4If4().

func IPTo4IfV4

func IPTo4IfV4(ip net.IP) net.IP

IPTo4IfV4 returns the ip.To4() if ip is a v4 address, returns ip otherwise.

func InterfaceByIP

func InterfaceByIP(ip net.IP) (*net.Interface, error)

InterfaceByIP return the interface matched by the IP address.

func IsUniqueLocal

func IsUniqueLocal(ip net.IP) bool

IsUniqueLocal reports whether ip is a unique local address.

The identification of unique local addresses uses address type identification as defined in "Local IPv6 Unicast Addresses" section of RFC 4193 and "Private Address Space" in RFC 1918.

func ParseIP

func ParseIP(s string) net.IP

ParseIP parses s as an IP address using net.ParseIP(), and converts the IP with IPTo4Ifv4().

func SendGARP

func SendGARP(intf *net.Interface, ip net.IP) error

SendGARP sends a GARP (Gratuitous ARP) packet.

func SplitHostPort

func SplitHostPort(hostPort string) (host string, port int, err error)

SplitHostPort split host and port and validate port to be an integer between 0 and 65535.

Types

type IP

type IP net.IP

IP is an IP address which can be marshaled and marshaled to YAML.

func (IP) MarshalYAML

func (i IP) MarshalYAML() (interface{}, error)

MarshalYAML marshal an IP address to string.

func (*IP) UnmarshalYAML

func (i *IP) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshal an IP address string from YAML.

type IPAndNet

type IPAndNet struct {
	IP    net.IP
	IPNet *net.IPNet
}

IPAndNet is an IP address with IPNet which can be marshaled and marshaled to YAML.

func ParseCIDR

func ParseCIDR(s string) (*IPAndNet, error)

ParseCIDR parses s as a CIDR using net.ParseCIDR(), and converts the IP with IPTo4Ifv4().

func (*IPAndNet) Equal

func (i *IPAndNet) Equal(j *IPAndNet) bool

Equal reports whether i and j are the same IP address and network. IP addresses are compared with IP.Equal and networks are compared with the results of IPNet.String().

func (IPAndNet) MarshalYAML

func (i IPAndNet) MarshalYAML() (interface{}, error)

MarshalYAML marshal an IP address and network to string.

func (*IPAndNet) UnmarshalYAML

func (i *IPAndNet) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshal an CIDR address string from YAML.

Jump to

Keyboard shortcuts

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