netinfo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 11 Imported by: 0

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

type Darwin struct {
	Netinfo
	RouteReaderFn func(ctx context.Context) (io.ReadCloser, error)
}

Darwin implements the Provider interface for macOS systems.

func NewDarwinProvider

func NewDarwinProvider(
	em exec.Manager,
) *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) GetPrimaryInterface

func (d *Darwin) GetPrimaryInterface(
	ctx context.Context,
) (string, error)

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

type InterfaceResult struct {
	Name   string
	IPv4   string
	IPv6   string
	MAC    string
	Family string
}

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

func (l *Linux) GetPrimaryInterface(
	_ context.Context,
) (string, error)

GetPrimaryInterface returns the name of the interface used for the default route by parsing /proc/net/route.

func (*Linux) GetRoutes

func (l *Linux) GetRoutes(
	_ context.Context,
) ([]RouteResult, error)

GetRoutes returns the system routing table 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.

type RouteResult

type RouteResult struct {
	Destination string
	Gateway     string
	Interface   string
	Mask        string
	Metric      int
	Flags       string
}

RouteResult represents a network routing table entry.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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