socket

package
v0.0.0-...-be347a3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InboundName   = "inbound"
	OutboundName  = "outbound"
	ListeningName = "listening"
)

Names for the direction of a connection

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction uint8

Direction indicates how a socket was initiated.

const (

	// Inbound indicates a connection was established from the outside to
	// listening socket on this host.
	Inbound Direction
	// Outbound indicates a connection was established from this socket to an
	// external listening socket.
	Outbound
	// Listening indicates a socket that is listening.
	Listening
)

func (Direction) String

func (d Direction) String() string

type ListenerTable

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

ListenerTable tracks sockets that are listening. It can then be used to identify if a socket is listening, incoming, or outgoing.

func NewListenerTable

func NewListenerTable() *ListenerTable

NewListenerTable returns a new ListenerTable.

func (*ListenerTable) Direction

func (t *ListenerTable) Direction(
	family uint8, proto uint8,
	localIP net.IP, localPort int,
	remoteIP net.IP, remotePort int,
) Direction

Direction returns whether the connection was incoming or outgoing based on the protocol and local address. It compares the given local address to the listeners in the table for the protocol and returns Inbound if there is a match. If remotePort is 0 then Listening is returned.

func (*ListenerTable) Put

func (t *ListenerTable) Put(proto uint8, ip net.IP, port int)

Put puts a new listening address into the table.

func (*ListenerTable) Reset

func (t *ListenerTable) Reset()

Reset resets all data in the table.

type NetlinkSession

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

NetlinkSession communicates with the kernel's netlink subsystem.

func NewNetlinkSession

func NewNetlinkSession() *NetlinkSession

NewNetlinkSession creates a new netlink session.

func (*NetlinkSession) GetSocketList

func (session *NetlinkSession) GetSocketList() ([]*linux.InetDiagMsg, error)

GetSocketList retrieves the current list of sockets from the kernel.

type Proc

type Proc struct {
	PID        int
	Command    string
	Executable string
	CmdLine    string
	Args       []string
}

Proc contains static process information.

type ProcTable

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

ProcTable contains all of the active processes (if the current user is root).

func NewProcTable

func NewProcTable(mountpoint string) (*ProcTable, error)

NewProcTable returns a new ProcTable that reads data from the /proc directory by default. An alternative proc filesystem mountpoint can be specified through the mountpoint parameter.

func (*ProcTable) Privileged

func (t *ProcTable) Privileged() bool

Privileged returns true if the process has enough permissions to read sockets of all users

func (*ProcTable) ProcessBySocketInode

func (t *ProcTable) ProcessBySocketInode(inode uint32) *Proc

ProcessBySocketInode returns the Proc associated with the given socket inode.

func (*ProcTable) Refresh

func (t *ProcTable) Refresh() error

Refresh updates the process table with new processes and removes processes that have exited. It collects the PID, command, and socket inode information. If running as non-root, only information from the current process will be collected.

Jump to

Keyboard shortcuts

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