How chenjiandongx/sniffer works
sniffer is a cross-platform network troubleshooting TUI. The user starts it with device, BPF, refresh, DNS, and view options; it captures packets, attributes connections to processes, aggregates traffic, and renders byte, packet, connection, and plot views. Linux uses netlink and /proc for socket attribution, macOS invokes lsof, and Windows uses gopsutil. The excerpts show the main orchestration and aggregation paths; platform-specific attribution is represented by the documented approaches. Optional DNS resolution and OS interfaces are shown as integrations.
Main entry points: sniffer.go Sniffer loop · pcap_linux.go Capture client · pcap_others.go Other platforms · stat.go Traffic aggregation
Components 16
Command and orchestration
- CLI options
cli.go - Sniffer loop
sniffer.go
Packet capture
- Capture client
pcap_linux.go - Other platforms
pcap_others.go - Traffic sink
pcap.go - DNS resolver
dns.go - Device discovery
pcap.go
Connection attribution
- Socket fetcher
conn_linux.go - Linux socket mapping
conn_linux.go - macOS socket mapping
conn_darwin.go - Windows socket mapping
conn_windows.go
Aggregation and views
- Traffic aggregation
stat.go - TUI views
ui.go
Other components
- Operator
- Packet capture
- OS socket metadata
Connections 24
- Operator → CLI options: sets options
cli.go - CLI options → Sniffer loop: starts
cli.go - CLI options → Device discovery: lists devices
cli.go - Sniffer loop → Capture client: creates client
sniffer.go - Sniffer loop → DNS resolver: creates resolver
sniffer.go - Sniffer loop → Socket fetcher: selects fetcher
sniffer.go - Capture client → Device discovery: selects devices
pcap_linux.go - Other platforms → Device discovery: selects devices
pcap_others.go - Capture client → Packet capture: reads packets
pcap_linux.go - Other platforms → Packet capture: reads packets
pcap_others.go - Capture client → Traffic sink: records segments
pcap_linux.go - Other platforms → Traffic sink: records segments
pcap_others.go - Capture client → DNS resolver: resolves addresses
pcap_linux.go - Other platforms → DNS resolver: resolves addresses
pcap_others.go - Socket fetcher → Linux socket mapping: implements
conn_linux.go - Linux socket mapping → OS socket metadata: reads netlink and proc
conn_linux.go - macOS socket mapping → OS socket metadata: invokes lsof
conn_darwin.go - Windows socket mapping → OS socket metadata: queries processes
conn_windows.go - Sniffer loop → Traffic sink: takes utilization
sniffer.go - Sniffer loop → Socket fetcher: gets open sockets
sniffer.go - Sniffer loop → Traffic aggregation: supplies measurements
sniffer.go - Traffic aggregation → Traffic aggregation: matches and aggregates
stat.go - Sniffer loop → TUI views: renders snapshot
sniffer.go - TUI views → Traffic aggregation: ranks view data
ui.go