Documentation
¶
Overview ¶
Package netinfo provides network interface information.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Darwin ¶
Darwin implements the Provider interface for macOS systems.
func NewDarwinProvider ¶
NewDarwinProvider factory to create a new Darwin instance.
func (*Darwin) GetPrimaryInterface ¶
GetPrimaryInterface returns the name of the interface used for the default route from macOS `netstat -rn` output.
func (*Darwin) GetRoutes ¶
func (d *Darwin) GetRoutes( ctx context.Context, ) ([]RouteResult, error)
GetRoutes returns the macOS routing table by parsing `netstat -rn` output.
Expected format:
Routing tables Internet: Destination Gateway Flags Netif Expire default 192.168.1.1 UGScg en0 127 127.0.0.1 UCS lo0 192.168.1/24 link#6 UCS en0
type InterfaceResult ¶
InterfaceResult represents a network interface with its address.
type Linux ¶
type Linux struct {
Netinfo
RouteReaderFn func() (io.ReadCloser, error)
}
Linux implements the Provider interface for Linux systems.
func NewLinuxProvider ¶
func NewLinuxProvider() *Linux
NewLinuxProvider factory to create a new Linux instance.
func (*Linux) GetPrimaryInterface ¶
GetPrimaryInterface returns the name of the interface used for the default route by parsing /proc/net/route.
type Netinfo ¶
type Netinfo struct {
provider.FactsAware
InterfacesFn func() ([]net.Interface, error)
AddrsFn func(iface net.Interface) ([]net.Addr, error)
}
Netinfo provides cross-platform network interface information. Platform-specific types (Linux, Darwin) embed this for shared interface enumeration and add their own route implementations.
func (*Netinfo) GetInterfaces ¶
func (n *Netinfo) GetInterfaces() ([]InterfaceResult, error)
GetInterfaces retrieves non-loopback, up network interfaces with name, IPv4, and MAC address.
type Provider ¶
type Provider interface {
// GetInterfaces retrieves non-loopback, up network interfaces
// with name, IPv4, and MAC address.
GetInterfaces() ([]InterfaceResult, error)
// GetRoutes returns the system routing table.
GetRoutes(ctx context.Context) ([]RouteResult, error)
// GetPrimaryInterface returns the name of the interface used
// for the default route.
GetPrimaryInterface(ctx context.Context) (string, error)
}
Provider implements the methods to interact with network interface information.