How matching works
Outcome: you can explain, step by step, how a packet on a wire becomes a row with a process's name on it — and you can name the situations where that chain breaks, because the lab broke it once on purpose and once by accident.
The two halves of the trick
Chapter 2 said the matcher joins packets to processes. Here is the join, on Linux, in full. It is worth seeing once, because every failure mode in this chapter is one of its steps failing.
Step one: the packet gives a connection. The sniffer reads each packet's addresses, ports, and protocol: "TCP, from 127.0.0.1 port 58878 to 127.0.0.1 port 18090, this many bytes."
Step two: the kernel's table gives a
socket. The kernel keeps every open
connection in its socket tables, which
Linux exposes under /proc (for
example /proc/net/tcp). Each entry
carries the same addresses and ports,
plus the socket's identity number —
its inode.
Step three: a process's hands give
the name. Each process's open files,
including its sockets, are listed under
/proc/<pid>/fd, and a socket entry
there reads socket:[<inode>]. Match
the inode from step two and you have
the process that owns the connection.
The lab performed the join by hand,
mid-download (transcript
examples/transcripts/t11-proc-crossref.txt):
$ ls -l /proc/<fixture-fetch pid>/fd | grep socket
5 -> socket:[180728]
$ grep 46AA /proc/net/tcp # 46AA is 18090 in hexadecimal
2: 0100007F:A45E 0100007F:46AA 01 ... 180728 ...
The client's own handle, socket inode
180728, is the same number sitting in
the kernel's table on the client's row
of the connection. That shared number
is the match. bandwhich repeats it
continuously, for every connection,
which is also why it needs the
cap_sys_ptrace and
cap_dac_read_search capabilities from
chapter 4: reading other processes'
socket handles is privileged for the
same reason sniffing is.
On macOS the matcher asks lsof for
the same facts, and on Windows the
Windows API; the shape is identical,
and those two routes are documented
from the project's text rather than run
in this lab.
Where the chain breaks
The process exits first. The join
needs the process alive at scan time.
A program that connects, transfers, and
exits inside a second may be gone
before its name can be attached — its
traffic still counted, its row labelled
<UNKNOWN>. The lab's burst test
(chapter 10) produced exactly that: the
client that moved 10 MiB in 0.060
seconds is <UNKNOWN> in every
refresh, while the long-lived server is
named throughout (transcript t03).
A tail of packets outlives the
match. Connections close with a small
ceremony of final packets, and the lab's
steady captures show a <UNKNOWN> row
carrying a few bytes — 12 bytes per
second in transcript t02 — even while
both real processes were still listed:
packets seen after their socket left
the table bandwhich scans. A small
<UNKNOWN> row next to a healthy
transfer is normal weather, not a
second mystery program.
Sockets are shared. One socket can be inherited by several processes — a supervisor and its workers, a parent and the child it handed a connection to. The inode then names a socket, not a single owner, and any one name bandwhich shows for it is at best the first owner it found. Treat the process name on shared infrastructure — proxies, servers that fork per connection — as the family name, not necessarily the individual.
Tunnels repackage everything. A VPN
or an SSH tunnel takes many programs'
packets and sends them inside its own
connection. Outside the tunnel, the
sniffer sees the tunnel's traffic: the
matcher faithfully names the tunnel
process, and every program inside the
tunnel is hidden behind it. This is not
an error — it is the correct answer
about the outer connection — but it
means "the VPN is using the bandwidth"
is as deep as bandwhich can honestly
go on the outside of a tunnel. (This
failure mode is described from how
tunnels work, not from a lab capture;
the lab's network could not carry a
tunnel out, and criteria.md labels it
documented-only.)
The pattern across all four: the bytes are always real. It is the name that is earned, per refresh, by a lookup that can lose. That is chapter 1's rule with its sleeves rolled up.
Check: during a fixture download, find
your client's socket inode in
/proc/<pid>/fd and the same number in
/proc/net/tcp. You have just done by
hand the only trick bandwhich has —
and you know exactly which step to
suspect the next time a row says
<UNKNOWN>.