Skip to main content

Module tcp_sockets

Module tcp_sockets 

Source
Expand description

The connected TCP sockets of the machine with their byte counts, and the sockets a process holds. What: The TCP sockets of this machine that are connected, with the bytes each has sent and had acknowledged and the bytes it has received, and the sockets a process holds. Why: rchar and wchar of /proc/<pid>/io count read and write, not send and recv, so a transfer done through libcurl (git-remote-http) moves no byte the push meter can see, and /proc/net/tcp has queue lengths and no running count. The kernel’s own socket diagnostics (NETLINK_SOCK_DIAG, man 7 sock_diag, the interface ss reads) return, for every socket, its state, its inode and a struct tcp_info with tcpi_bytes_acked and tcpi_bytes_received; a socket a process holds is the socket:[<inode>] link of its /proc/<pid>/fd (man 5 proc_pid_fd).

In TS you’d write (pseudocode):

const sockets = establishedSockets(); const mine = socketInodesOf(pid); sockets.filter((socket) => mine.includes(socket.inode));

Structs§

TcpSocket
One connected TCP socket as the kernel reports it.

Constants§

ESTABLISHED
The state number of a connected socket, TCP_ESTABLISHED in include/net/tcp_states.h.

Functions§

established_sockets
Every connected TCP socket of the network namespace of this process, or nothing where the kernel cannot say.
socket_inodes_of
The inodes of the sockets a process holds open, or nothing where its descriptors cannot be read.