Traffic Capture is a lightweight C++17 tool for capturing, parsing, and exporting network packets (Ethernet, ARP, IPv4) to PCAP format for analysis in Wireshark. It features a modular and extensible architecture, where capture sources, protocol parsers, and exporters are independent, interchangeable components.
The project demonstrates a clean packet-processing pipeline designed for scalability and easy integration with custom network monitoring or analysis systems.
- Overview
- Features
- Quickstart
- Requirements
- Build and Run
- Testing
- Project Structure
- Code Quality
- CI/CD
- Known Limitations
- Roadmap
- License
Traffic Capture provides a complete low-level packet processing pipeline:
- Capture packets directly from a network interface using raw sockets
- Parse Layer 2 (Ethernet, ARP) and Layer 3 (IPv4) headers
- Display parsed packet details to console and export to Wireshark-compatible PCAP files
- Provide a modular API for extending capture sources, parsers, and exporters
Its core design focuses on extensibility, clarity, and modularity, allowing new protocols or export formats to be added with minimal effort.
- Real-time packet capture from any interface
- Parsing of Ethernet, ARP, and IPv4 protocols
- PCAP export compatible with Wireshark and tcpdump
- Interactive command-line interface (CLI)
- Promiscuous mode support
- 150+ unit and integration tests (veth-based)
- Modular architecture for independent component development
- CI/CD with build, tests, static analysis, and formatting checks
Clone and build:
git clone https://github.com/IRomanchuk06/traffic_capture.git
cd traffic_capture
sudo apt-get update
sudo apt-get install -y build-essential cmake ninja-build clang
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildRun interactively:
sudo ./bin/traffic_captureCapture 100 packets and export to PCAP:
sudo ./bin/traffic_capture -i eth0 -c 100 -o packets.pcapCapture for 30 seconds in promiscuous mode:
sudo ./bin/traffic_capture -i eth0 -t 30 -pOpen the resulting file in Wireshark:
wireshark packets.pcap- Linux kernel 3.10+
- Root privileges (required for raw sockets)
- C++17 compiler (GCC 7+ / Clang 5+)
- CMake 3.20+, Ninja or Make
Optional development tools:
sudo apt-get install -y clang-tidy cppcheck clang-formatBuild with tests:
rm -rf build
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON
cmake --build buildNote: First build may take longer due to local download and build of GoogleTest dependency.
Run tests:
cd build
ctest --output-on-failure
# sudo ctest --output-on-failure # for integration tests
cd ..CLI Options:
| Option | Description |
|---|---|
-h, --help |
Show help and exit |
-i, --interface IFACE |
Network interface to capture from |
-c, --count N |
Number of packets to capture |
-t, --time SECS |
Capture duration in seconds |
-o, --output FILE |
Output PCAP file (default: capture.pcap) |
-p, --promiscuous |
Enable promiscuous mode |
-I, --interactive |
Enable interactive mode (default) |
-v, --verbose |
Verbose output |
-x, --hex |
Print packets in hexadecimal format |
-P, --parsed |
Display parsed protocol information |
All tests (unit + integration):
cd build
sudo ctest --output-on-failure
cd ..Unit tests only:
cd build
ctest -L unit --output-on-failure
cd ..Integration tests (require sudo):
cd build
sudo ctest -L integration --output-on-failure
cd ..Run a specific test:
cd build
sudo ctest -R "ArpParserTest.PacketTooShort27Bytes" --output-on-failure
cd ..Notes:
- Loopback-based tests can be unstable in CI; use veth pairs instead.
- Integration tests are optional in CI (non-blocking).
traffic_capture/
├─ src/
│ ├─ main.cpp # Entry point (CLI)
│ ├─ capture.cpp # Packet capture (raw sockets)
│ ├─ cli.cpp # Interactive CLI and arguments
│ ├─ export/pcap.cpp # PCAP exporter
│ └─ parsers/
│ ├─ frame.cpp # Ethernet parser
│ ├─ L2/arp.cpp # ARP parser
│ └─ L3/ipv4.cpp # IPv4 parser
├─ h/
│ ├─ capture.hpp
│ ├─ cli.hpp
│ └─ parsers/...
├─ tests/
│ ├─ unit/ # Unit tests
│ └─ integration/ # Integration (veth)
│ ├─ test_real_capture.cpp
│ └─ helpers/
│ ├─ veth_setup.hpp
│ └─ packet_sender.hpp
├─ .github/workflows/ci.yml # CI/CD configuration
├─ .clang-tidy
├─ .clang-format
└─ README.md
Run local checks:
./run_checks.shIncludes:
- Static analysis (
clang-tidy,cppcheck) - Formatting verification (
clang-format) - Build validation and test execution
Also included is a script to auto-format project code using clang-format:
./format_code.shThis script recursively formats C++ source and header files in src/, h/, and tests/ directories according to the project style.
GitHub Actions perform:
- Build and run of unit tests
- Integration tests (optional, sudo required)
- Static analysis (
clang-tidy,cppcheck) - Code formatting validation (non-blocking)
CI status:
- Requires root privileges for raw socket access
- Loopback testing may fail in CI environments
- Supported on Linux only
- Extended protocol support (IPv6, ICMP, TCP, UDP)
- BPF-style filtering
- Interface statistics and live metrics
- GUI / web dashboard
- Performance benchmarking suite
This project is licensed under the MIT License.
You are free to use, modify, and distribute this software with attribution.
See the full license text in the LICENSE file.