netstat

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SSFREE = 0 + iota
	SSUNCONNECTED
	SSCONNECTING
	SSCONNECTED
	SSDISCONNECTING
)
View Source
const (
	RTFUP        uint32 = 0x0001
	RTFGATEWAY   uint32 = 0x0002
	RTFHOST      uint32 = 0x0004
	RTFREINSTATE uint32 = 0x0008
	RTFDYNAMIC   uint32 = 0x0010
	RTFMODIFIED  uint32 = 0x0020
	RTFMTU       uint32 = 0x0040
	RTFMSS       uint32 = RTFMTU
	RTFWINDOW    uint32 = 0x0080
	RTFIRTT      uint32 = 0x0100
	RTFREJECT    uint32 = 0x0200
	RTFNOTCACHED uint32 = 0x0400

	RTFDEFAULT   uint32 = 0x00010000
	RTFALLONLINK uint32 = 0x00020000
	RTFADDRCONF  uint32 = 0x00040000
	RTFNONEXTHOP uint32 = 0x00200000
	RTFEXPIRES   uint32 = 0x00400000
	RTFCACHE     uint32 = 0x01000000
	RTFFLOW      uint32 = 0x02000000
	RTFPOLICY    uint32 = 0x04000000
	RTFLOCAL     uint32 = 0x80000000
)
View Source
const (
	SSACCEPTCON = (1 << 16)
	SSWAITDATA  = (1 << 17)
	SSNOSPACE   = (1 << 18)
)
View Source
const SystemClkTck = 100

CLK_TCK is a constant on Linux for all architectures except alpha and ia64. See e.g. https://git.musl-libc.org/cgit/musl/tree/src/conf/sysconf.c#n30 https://github.com/containerd/cgroups/pull/12 https://lore.kernel.org/lkml/agtlq6$iht$1@penguin.transmeta.com/

Variables

View Source
var (
	ANYADDR = "0.0.0.0"
	ANYMASK = "00000000"
)
View Source
var (
	ProcNetigmpv4path = "/proc/net/igmp"
	ProcNetigmpv6path = "/proc/net/igmp6"
)
View Source
var ErrRouteCacheIPv6only = errors.New("route cache printing for IPv6 only")
View Source
var ProcNetDevPath = "/proc/net/dev"
View Source
var ProcNetRoutePath4 = "/proc/net/route"
View Source
var ProcNetRoutePath6 = "/proc/net/ipv6_route"
View Source
var ProcnetPath = "/proc/net"
View Source
var (
	SNMP4file = "/proc/net/snmp"
)
View Source
var (
	SNMP6file = "/proc/net/snmp6"
)

Functions

func PrintInterfaceTable

func PrintInterfaceTable(ifstr string, cont bool, out io.Writer) error

func PrintMulticastGroups

func PrintMulticastGroups(ipv4, ipv6 bool, out io.Writer) error

Types

type AddressFamily

type AddressFamily interface {
	RoutesFormatString(bool) (string, error)
	PrintStatistics(io.Writer) error
	ClearOutput()
}

func NewAddressFamily

func NewAddressFamily(ipv6Flag bool, output *Output) AddressFamily

type CFMode

type CFMode uint8
const (
	FIB   CFMode = 0x00
	CACHE CFMode = 0xFF
)

type FmtFlags

type FmtFlags struct {
	Extend    bool // Adds fields User and Inode for ip sockets
	Wide      bool // Unknown
	NumHosts  bool // dont resolve host ip to names - applies to ip socks
	NumPorts  bool // dont resolve port numbers to names - applies to ip socks
	NumUsers  bool // dont resolve user id to usernames - applies to ip and unix socks
	ProgNames bool // Adds fields PID/Program name for sockets (for ip and unix sockets)
	Timer     bool // Adds field timer for sockets (not unix socket)
	Symbolic  bool // Rounting table/cache -> no ip to name conversion, same as -n
}

type Groups

type Groups []member

func (*Groups) String

func (g *Groups) String() string

type IPAddress

type IPAddress struct {
	Address net.IP
	Port    uint16
}

func (*IPAddress) String

func (s *IPAddress) String() string

type IPv4

type IPv4 struct {
	*Output
}

func (*IPv4) ClearOutput

func (i *IPv4) ClearOutput()

func (*IPv4) PrintStatistics

func (i *IPv4) PrintStatistics(out io.Writer) error

func (*IPv4) RoutesFormatString

func (i *IPv4) RoutesFormatString(_ bool) (string, error)

type IPv6

type IPv6 struct {
	*Output
}

func (*IPv6) ClearOutput

func (i *IPv6) ClearOutput()

func (*IPv6) PrintStatistics

func (i *IPv6) PrintStatistics(out io.Writer) error

func (*IPv6) RoutesFormatString

func (i *IPv6) RoutesFormatString(cache bool) (string, error)

type NetSockets

type NetSockets struct {
	Protocol
	Entries []netSocket
}

func (*NetSockets) SocketsString

func (n *NetSockets) SocketsString(lst, all bool, outputfmt *Output) (string, error)

type NetStat

type NetStat struct {
	TCPExt   tcpExt
	IPExt    ipExt
	MPTCPExt mptcpext
}

func (*NetStat) String

func (n *NetStat) String() string

type NetState

type NetState uint8
const (
	TCP_ESTABLISHED NetState = 1 + iota
	TCP_SYN_SENT
	TCP_SYN_RECV
	TCP_FIN_WAIT1
	TCP_FIN_WAIT2
	TCP_TIME_WAIT
	TCP_CLOSE
	TCP_CLOSE_WAIT
	TCP_LAST_ACK
	TCP_LISTEN
	TCP_CLOSING
)

func (*NetState) String

func (n *NetState) String() string

type Output

type Output struct {
	strings.Builder
	FmtFlags

	ProgCache map[int]ProcNode
}

func NewOutput

func NewOutput(
	flags FmtFlags,
) (*Output, error)

func (*Output) AddIPSocket

func (o *Output) AddIPSocket(ipsock netSocket)

func (*Output) AddRoute4

func (o *Output) AddRoute4(r routev4)

func (*Output) AddRoute6

func (o *Output) AddRoute6(r routev6)

func (*Output) AddUnixSocket

func (o *Output) AddUnixSocket(uSock unixSocket)

func (*Output) ConstructTimer

func (o *Output) ConstructTimer(tr uint8, tl, retr, to uint64) string

func (*Output) InitIPSocketTitels

func (o *Output) InitIPSocketTitels()

func (*Output) InitRoute4Titel

func (o *Output) InitRoute4Titel()

func (*Output) InitRoute6Titel

func (o *Output) InitRoute6Titel()

func (*Output) InitUnixSocketTitels

func (o *Output) InitUnixSocketTitels()

type ProcNode

type ProcNode struct {
	Name  string
	PID   int
	Inode int
}

type Protocol

type Protocol string
const (
	PROT_IGMP  Protocol = "igmp"
	PROT_IGMP6 Protocol = "igmp6"
	PROT_TCP   Protocol = "tcp"
	PROT_TCP6  Protocol = "tcp6"
	PROT_UDP   Protocol = "udp"
	PROT_UDP6  Protocol = "udp6"
	PROT_UDPL  Protocol = "udplite"
	PROT_UDPL6 Protocol = "udplite6"
	PROT_RAW   Protocol = "raw"
	PROT_RAW6  Protocol = "raw6"
	PROT_UNIX  Protocol = "unix"
)

func (*Protocol) String

func (p *Protocol) String() string

type SNMP

type SNMP struct {
	IP      ip
	ICMP    icmp
	ICMPMsg icmpmsg
	TCP     tcp
	UDP     udp
	UDPL    udp
}

func (*SNMP) String

func (s *SNMP) String() string

type SNMP6

type SNMP6 struct {
	IP6   ip
	ICMP6 icmp
	UDP6  udp
	UDPL6 udp
	TCP6  tcp
}

func (*SNMP6) String

func (s *SNMP6) String() string

type SockState

type SockState uint8

type SockType

type SockType int

func (*SockType) String

func (s *SockType) String() string

type Socket

type Socket interface {
	SocketsString(bool, bool, *Output) (string, error)
	// contains filtered or unexported methods
}

func NewSocket

func NewSocket(t Protocol) (Socket, error)

type UnixSockets

type UnixSockets struct {
	Entries []unixSocket
}

func (*UnixSockets) SocketsString

func (u *UnixSockets) SocketsString(lst, all bool, outputfmt *Output) (string, error)

Jump to

Keyboard shortcuts

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