netutils

package module
v0.0.0-...-0aa3ed0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 9 Imported by: 3

README

Netutils

Simple packet of pure go functions, that help with work with network

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTapDevice

func CreateTapDevice(name, cidr string) error

CreateTapDevice create tap device, sets cidr to it and up via ip command

func EnableIpv4Forwarding

func EnableIpv4Forwarding() error

EnableIpv4Forwarding writes 1 to '/proc/sys/net/ipv4/ip_forward'

func FindIPv4

func FindIPv4(addrs []net.Addr) netip.Addr

FindIPv4 returns first ipv4 in slice of addresses or "0.0.0.0"

func GetDefaultGatewayDevice

func GetDefaultGatewayDevice() string

GetDefaultGateway parses command 'ip route' and return default device name

func GetInterfaceIndex

func GetInterfaceIndex(iface string) int

GetInterfaceIndex returns the index of the network interface with the given name.

func GetInterfaceMTU

func GetInterfaceMTU(name string) (int, error)

GetInterfaceMTU returns mtu from file '/sys/class/net/<interface>/mtu'

func Htons

func Htons(i uint16) uint16

Htons converts a short (16-bit) integer from host byte order to network byte order.

func OpenRawSocket

func OpenRawSocket(name string) (int, error)

OpenRawSocket opens raw socket by name and return its file descriptor

func StopTapDevice

func StopTapDevice(name string) error

StopTapDevice stop tap device by name via ip command

Types

type InterfaceInfo

type InterfaceInfo struct {
	Name     string
	HardAddr net.HardwareAddr
	IP       net.IP
}

func GetDefaultGatewayInfo

func GetDefaultGatewayInfo(ifce string) (InterfaceInfo, error)

GetDefaultGatewayInfo gather gateway info by interface name or empty struct

func GetInterfaceInfo

func GetInterfaceInfo(name string) (InterfaceInfo, error)

GetInterfaceInfo gather interface mac and ip address

Jump to

Keyboard shortcuts

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