███████╗██╗ ███████╗██████╗ ██╗ ██╗ █████╗ ███╗ ██╗████████╗
██╔════╝██║ ██╔════╝██╔══██╗██║ ██║██╔══██╗████╗ ██║╚══██╔══╝
█████╗ ██║ █████╗ ██████╔╝███████║███████║██╔██╗ ██║ ██║
██╔══╝ ██║ ██╔══╝ ██╔═══╝ ██╔══██║██╔══██║██║╚██╗██║ ██║
███████╗███████╗███████╗██║ ██║ ██║██║ ██║██║ ╚████║ ██║
╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝
███████╗██╗ ██╗██████╗ ███████╗██╗ ██╗
██╔════╝██║ ██║██╔══██╗██╔════╝██║ ██║
███████╗███████║██████╔╝█████╗ ██║ █╗ ██║
╚════██║██╔══██║██╔══██╗██╔══╝ ██║███╗██║
███████║██║ ██║██║ ██║███████╗╚███╔███╔╝
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝
ElephantShrew captures live packets from one or more network interfaces. Packet
recording to the Redis-compatible stream elephantshrew:packets is enabled
with -r. It can also bridge raw packets from one interface to another, with
optional bidirectional forwarding.
- A C++20 compiler
mesonninjapkg-config- Boost
- OpenSSL
spdlog- PcapPlusPlus
nlohmann/json.hpp- Redis or DragonFly listening on
127.0.0.1:6379when using-r clang-tidyfor Clang static analysis reportscppcheckfor standalone static analysis reportsvalgrindfor runtime leak reports
Run the build from the project root:
meson setup builddir
meson compile -C builddirMeson build profiles are scripted under scripts/setup_build.sh and create
separate build directories per compiler/profile:
./scripts/setup_build.sh gcc debug
meson compile -C build/debug-gcc
./scripts/setup_build.sh gcc release
meson compile -C build/release-gcc
./scripts/setup_build.sh clang debug
meson compile -C build/debug-clang
./scripts/setup_build.sh clang release
meson compile -C build/release-clangRelease builds enable:
buildtype=releaseoptimization=3b_lto=trueb_ndebug=truestrip=true- host-specific
-march=native -mtune=native -fomit-frame-pointer
The binary will be created at:
./builddir/elephantshrewThe default runtime config lives at:
./elephantshrew.jsonInstall the analysis tools:
sudo apt-get install -y cppcheck clang-tidy valgrindGenerate a clang-tidy report from the Clang debug build:
./scripts/setup_build.sh clang debug
meson compile -C build/debug-clang
./scripts/run_clang_tidy.sh "$(pwd)" "$(pwd)/build/debug-clang" "$(pwd)/reports/clang-tidy"Generate a cppcheck report:
sudo apt-get install -y cppcheck
./scripts/setup_build.sh gcc debug
meson compile -C build/debug-gcc
./scripts/run_cppcheck.sh "$(pwd)" "$(pwd)/build/debug-gcc" "$(pwd)/reports/cppcheck"Generate a Valgrind leak report:
./scripts/setup_build.sh gcc debug
meson compile -C build/debug-gcc
./scripts/run_valgrind.sh "$(pwd)/build/debug-gcc" "$(pwd)/reports/valgrind" -sVS Code tasks are included for:
- GCC debug/release builds
- Clang debug/release builds
clang-tidyreportscppcheckreports- Valgrind leak reports
- package installation tasks for
cppcheck,clang-tidy, andvalgrind
VS Code launch configurations are included for both GCC and Clang debug binaries and pre-build the selected debug target before launching.
If you do not pass any interface arguments, ElephantShrew will auto-select the
first available interface. The process keeps running until you stop it with
Ctrl+C.
Capture from a single interface and record packets:
sudo ./builddir/elephantshrew -r -i eth0Capture from multiple interfaces by repeating -i:
sudo ./builddir/elephantshrew -r -i eth0 -i wlan0Route packets from eth0 to eth1:
sudo ./builddir/elephantshrew --route eth0:eth1Bridge packets in both directions between eth0 and eth1:
sudo ./builddir/elephantshrew --route eth0:eth1 --bidirectionalRoute packets and record/debug them at the same time:
sudo ./builddir/elephantshrew -r -d --route eth0:eth1 --bidirectionalRun with automatic interface selection:
sudo ./builddir/elephantshrew -rRun in debug mode and print one log line per incoming packet:
sudo ./builddir/elephantshrew -d -i eth0Run with both packet recording and debug logging enabled:
sudo ./builddir/elephantshrew -r -d -i eth0Run with an explicit JSON config file:
sudo ./builddir/elephantshrew -c elephantshrew.jsonList available interfaces without starting capture:
./builddir/elephantshrew -s- Packet capture commonly requires elevated privileges, which is why the
examples use
sudo. -sscans and lists available interfaces.-iselects one or more interfaces for live capture.-cloads runtime settings from a JSON file.-renables packet recording to Redis/DragonFly and validates the connection on startup.-denables packet-level debug logs that include the interface name, addresses, protocol, and packet length.--routeenables interface-to-interface forwarding using a route pair such aseth0:eth1.--bidirectionalforwards traffic in both directions for the route pair.- Routing forwards raw Ethernet frames, so ARP, ICMP, UDP, and TCP traffic all traverse the bridge transparently. TCP stream reassembly remains the responsibility of the connected endpoints.
- CLI flags override the JSON config for
-i,-r,-d,--route, and--bidirectional.
elephantshrew.json contains the runtime defaults:
{
"capture": {
"interfaces": [],
"record_packets": false,
"debug_packets": false
},
"routing": {
"enabled": false,
"ingress_iface": "eth0",
"egress_iface": "eth1",
"bidirectional": false
},
"redis": {
"host": "127.0.0.1",
"port": "6379",
"stream_key": "elephantshrew:packets",
"max_pending_writes": 1024,
"connect_timeout_ms": 5000,
"drain_timeout_ms": 5000
},
"supervisor": {
"restart_delay_ms": 2000,
"poll_interval_ms": 200
},
"ui": {
"show_startup_art": true
}
}