Interactive network connection monitor with real-time traffic visualization.
Like ss or netstat, but shows which process generates how much traffic, who it talks to, and live sparklines.
- TUI with one row per socket (process → IP:PORT)
- Sparkline traffic history for the last 10 seconds (60 buckets × 166ms)
- Process resolution via
/proc/<pid>/fdinode mapping - AF_PACKET raw capture in C++ (zero-copy ring buffers)
- Keyboard navigation: ↑↓ select, Enter detail, q quit
socktop/
├── native/
│ ├── pkt_capture.hpp # C++ AF_PACKET capture + ring buffers
│ ├── pkt_capture.cpp # Zero-copy raw packet reader
│ └── CMakeLists.txt # Static lib build
├── src/
│ ├── main.rs # TUI event loop (ratatui + crossterm)
│ ├── ffi.rs # FFI bindings to C++ lib
│ ├── proc_parser.rs # /proc/net/tcp,udp parser + inode→pid
│ └── traffic.rs # Sparkline history + traffic tracker
├── Cargo.toml
├── build.rs # CMake integration
├── build_and_run.sh
└── README.md
# Requires: cmake, g++, rust toolchain
cargo build --releaseOr use the helper script:
sudo ./build_and_run.sh -i eth0# Monitor eth0 (default)
sudo ./target/release/socktop
# Monitor specific interface
sudo ./target/release/socktop -i wlan0
# Monitor all traffic on lo
sudo ./target/release/socktop -i lo| Key | Action |
|---|---|
| ↑/k | Select previous socket |
| ↓/j | Select next socket |
| Enter | Show socket detail view |
| Esc | Close detail view |
| q | Quit |
| r | Force refresh |
| PageUp | Scroll detail up |
| PageDown | Scroll detail down |
- C++ layer opens
AF_PACKETsocket, captures raw Ethernet frames - Parses IP/TCP/UDP headers, extracts 4-tuple + byte count
- Stores per-socket stats in a lock-free ring buffer (256 packets)
- Rust layer reads
/proc/net/tcpand/proc/net/udpfor socket list - Maps socket inodes to PIDs via
/proc/<pid>/fdsymlinks - Feeds captured bytes into per-socket sparkline history (60 × 166ms buckets)
- Renders TUI with
ratatui, refreshes at 5 FPS
- Linux (AF_PACKET + /proc/net)
- Root or
CAP_NET_RAWcapability - cmake, g++ (for C++ native library)
- Rust toolchain