netutil

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterByLocalListeningPorts added in v0.4.0

func FilterByLocalListeningPorts(conns []*ConnectionStat) ([]string, error)

FilterByLocalListeningPorts filters ConnectionStat slice by the local listening ports.

func IsPrivateIP added in v0.6.0

func IsPrivateIP(ip net.IP) bool

IsPrivateIP returns whether 'ip' is in private network space.

func LocalIPAddrs

func LocalIPAddrs() ([]string, error)

LocalIPAddrs gets the string slice of localhost IPaddrs.

func LocalListeningPorts

func LocalListeningPorts() ([]string, error)

LocalListeningPorts returns the local listening ports.

func NetlinkConnections added in v0.4.0

func NetlinkConnections() ([]*linux.InetDiagMsg, error)

NetlinkConnections returns connection stats.

func NetlinkFilterByLocalListeningPorts added in v0.4.2

func NetlinkFilterByLocalListeningPorts(conns []*linux.InetDiagMsg) ([]*linux.InetDiagMsg, error)

NetlinkFilterByLocalListeningPorts filters ConnectionStat slice by the local listening ports.

func NetlinkLocalListeningPorts added in v0.4.2

func NetlinkLocalListeningPorts() ([]string, error)

NetlinkLocalListeningPorts returns the local listening ports.

func ResolveAddr

func ResolveAddr(addr string) string

ResolveAddr lookup first hostname from IP Address.

Types

type Addr added in v0.4.3

type Addr struct {
	IP   string `json:"ip"`
	Port uint32 `json:"port"`
}

Addr is <addr>:<port>.

type ConnectionStat added in v0.4.3

type ConnectionStat struct {
	Laddr  Addr
	Raddr  Addr
	Status linux.TCPState
}

ConnectionStat represents statistics for a connection.

func ProcfsConnections added in v0.4.3

func ProcfsConnections() ([]*ConnectionStat, error)

ProcfsConnections returns connection stats. ref. https://github.com/shirou/gopsutil/blob/c23bcca55e77b8389d84b09db8c5ac2b472070ef/net/net_linux.go#L656

type NetlinkError added in v0.5.0

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

NetlinkError represents netlink error.

func (*NetlinkError) Error added in v0.5.0

func (e *NetlinkError) Error() string

type UserEnt added in v0.5.0

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

UserEnt represents a detail of network socket. see https://github.com/shemminger/iproute2/blob/afa588490b7e87c5adfb05d5163074e20b6ff14a/misc/ss.c#L509.

func (*UserEnt) Fd added in v0.5.0

func (u *UserEnt) Fd() int

Fd returns file descriptor.

func (*UserEnt) Inode added in v0.5.0

func (u *UserEnt) Inode() uint32

Inode returns inode.

func (*UserEnt) Pgrp added in v0.5.0

func (u *UserEnt) Pgrp() int

Pgrp returns process group id.

func (*UserEnt) Pid added in v0.5.0

func (u *UserEnt) Pid() int

Pid returns process id.

func (*UserEnt) Pname added in v0.5.0

func (u *UserEnt) Pname() string

Pname returns process name.

func (*UserEnt) Ppid added in v0.5.0

func (u *UserEnt) Ppid() int

Ppid returns process id.

func (*UserEnt) SetInode added in v0.5.0

func (u *UserEnt) SetInode(inode uint32)

SetInode set the inode.

type UserEntByLport added in v0.5.0

type UserEntByLport map[string]*UserEnt

UserEntByLport is a map that key is listening port, value is UserEnt structure.

type UserEnts added in v0.5.0

type UserEnts map[uint32]*UserEnt

UserEnts represents a hashmap of UserEnt as key is the inode.

func BuildUserEntries added in v0.5.0

func BuildUserEntries() (UserEnts, error)

BuildUserEntries scans under /proc/%pid/fd/.

Jump to

Keyboard shortcuts

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