Help us shape the future of Go! Take the 2026 Go Developer Survey

netstat

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package netstat provides primitives for getting socket information on a Linux based operating system.

Index

Constants

View Source
const (
	AutoForwardIgnore = config.AutoForwardIgnore
	AutoForwardSilent = config.AutoForwardSilent
)

Variables

View Source
var (
	ErrNotEnoughFields = errors.New("gonetstat: not enough fields in the line")
)

Errors returned by gonetstat.

Functions

func NoopFilter

func NoopFilter(*SockTabEntry) bool

NoopFilter - a test function returning true for all elements.

Types

type AcceptFn

type AcceptFn func(*SockTabEntry) bool

AcceptFn is used to filter socket entries. The value returned indicates whether the element is to be appended to the socket list.

type Forwarder

type Forwarder interface {
	Forward(port string, attr PortForwardAttribute) error
	StopForward(port string) error
}

type PortAttributeResolver added in v1.1.0

type PortAttributeResolver func(port string) PortForwardAttribute

PortAttributeResolver resolves port forwarding attributes for a given port.

type PortFilter added in v1.1.0

type PortFilter func(port string) bool

PortFilter decides whether a discovered port should be auto-forwarded. Return true to forward, false to skip.

type PortForwardAttribute added in v1.1.0

type PortForwardAttribute struct {
	Label            string
	Protocol         string
	OnAutoForward    string
	RequireLocalPort bool
	ElevateIfNeeded  bool
}

PortForwardAttribute carries port metadata resolved from portsAttributes in the devcontainer config. Downstream forwarders use this to apply protocol, label, and forwarding-policy decisions.

type Process

type Process struct {
	Pid  int
	Name string
}

Process holds the PID and process name to which each socket belongs.

func (*Process) String

func (p *Process) String() string

type SkState

type SkState uint8

SkState type represents socket connection state.

const (
	Established SkState = 0x01
	SynSent     SkState = 0x02
	SynRecv     SkState = 0x03
	FinWait1    SkState = 0x04
	FinWait2    SkState = 0x05
	TimeWait    SkState = 0x06
	Close       SkState = 0x07
	CloseWait   SkState = 0x08
	LastAck     SkState = 0x09
	Listen      SkState = 0x0a
	Closing     SkState = 0x0b
)

Socket states.

func (SkState) String

func (s SkState) String() string

type SockAddr

type SockAddr struct {
	IP   net.IP
	Port uint16
}

SockAddr represents an ip:port pair.

func (*SockAddr) String

func (s *SockAddr) String() string

type SockTabEntry

type SockTabEntry struct {
	LocalAddr  *SockAddr
	RemoteAddr *SockAddr
	State      SkState
	UID        uint32
	Process    *Process
	// contains filtered or unexported fields
}

SockTabEntry type represents each line of the /proc/net/[tcp|udp].

func TCP6Socks

func TCP6Socks(accept AcceptFn) ([]SockTabEntry, error)

TCP6Socks returns a slice of active TCP IPv4 sockets containing only those elements that satisfy the accept function.

func TCPSocks

func TCPSocks(accept AcceptFn) ([]SockTabEntry, error)

TCPSocks returns a slice of active TCP sockets containing only those elements that satisfy the accept function.

func UDP6Socks

func UDP6Socks(accept AcceptFn) ([]SockTabEntry, error)

UDP6Socks returns a slice of active UDP IPv6 sockets containing only those elements that satisfy the accept function.

func UDPSocks

func UDPSocks(accept AcceptFn) ([]SockTabEntry, error)

UDPSocks returns a slice of active UDP sockets containing only those elements that satisfy the accept function.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher(forwarder Forwarder, opts ...WatcherOption) *Watcher

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

type WatcherOption added in v1.1.0

type WatcherOption func(*Watcher)

WatcherOption configures a Watcher.

func WithPortAttributes added in v1.1.0

func WithPortAttributes(resolver PortAttributeResolver) WatcherOption

WithPortAttributes configures the watcher with a port attribute resolver. When set, the watcher resolves attributes for each discovered port and passes them to the Forwarder. Ports with onAutoForward=ignore are skipped.

func WithPortFilter added in v1.1.0

func WithPortFilter(f PortFilter) WatcherOption

WithPortFilter sets a filter that is consulted before forwarding each auto-discovered port. Ports for which the filter returns false are silently skipped.

Jump to

Keyboard shortcuts

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