network

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package network provides utility functions to extract some data about network

Index

Constants

View Source
const ETH_P_ALL int = 0x03

Variables

View Source
var (
	BroadcastMAC = net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
	LoopbackMAC  = net.HardwareAddr{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
)

Functions

func AddrEqual added in v0.0.14

func AddrEqual(a, b string) bool

AddrEqual compares two address strings and returns true if they are equal.

It treats loopback and unspecified IPs as equivalent. Returns false in case of inequality or error.

func DisplayInterfaces

func DisplayInterfaces(includeAny bool) error

func GetDefaultGatewayIPv4

func GetDefaultGatewayIPv4() (netip.Addr, error)

func GetDefaultInterface

func GetDefaultInterface() (*net.Interface, error)

func GetGatewayIPv4FromInterface

func GetGatewayIPv4FromInterface(iface string) (netip.Addr, error)

func GetIPv4PrefixFromInterface

func GetIPv4PrefixFromInterface(iface *net.Interface) (netip.Prefix, error)

func InterfaceByName

func InterfaceByName(name string) (*net.Interface, error)

InterfaceByName returns the interface specified by name.

func IsLocalAddress added in v0.0.10

func IsLocalAddress(addr string) bool

func ListenPacket added in v0.0.14

func ListenPacket(conf *ListenConfig) (*packet.Conn, error)

Types

type ListenConfig added in v0.0.14

type ListenConfig struct {
	Device      *net.Interface // network interface which to bind to, if not specified default interface is used
	Protocol    int            // network protocol, defaults to ETH_P_ALL
	Promiscuous *bool          // enable or disable promiscuous mode
	FilterExpr  string         // packet filter expression like in tcpdump
}

Jump to

Keyboard shortcuts

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