pcaparse
This is a combination of awesome pcap-file crate and pcap-file-tokio crate with some issues fixed and new features added.
Provides parsers, readers and writers for Cap(Network Associates Sniffer 2.x), Pcap and PcapNg files.
Why this crate
- I previously made a PR to pcap-file repo to handle a snaplen issue, but the author seems has no time to maintain it.
- The sync and async processing share similar logic but divided into two crates, which will increase the difficulty of fixing problems.
To do
- Fix timestamp of pcapng
- Add parser and reader for cap(Network Associates Sniffer 2.x) file
- Add writer for cap(Network Associates Sniffer 2.x) file
Crate Features
tokio enables async reading and writing via tokio crate.
Installation
This crate is on crates.io.
Add it to your Cargo.toml:
[]
= "0.1"
Examples
PcapReader
use File;
use PcapReader;
let file_in = open.expect;
let mut pcap_reader = new.unwrap;
// Read test.pcap
while let Some = pcap_reader.next_packet
Async PcapReader
enable tokio feature first
use File;
use PcapReader;
async
Async PcapReader from tokio's TcpStream (AKA pcap-over-ip)
enable tokio feature first
use ;
use PcapReader;
async
async
PcapNgReader
use File;
use PcapNgReader;
let file_in = open.expect;
let mut pcapng_reader = new.unwrap;
// Read test.pcapng
while let Some = pcapng_reader.next_block
Async PcapNgReader from tokio's File
enable tokio feature first
use File;
use PcapNgReader;
async
CapReader
use File;
use CapReader;
let file_in = open.expect;
let mut cap_reader = new.unwrap;
// Read test.cap
while let Some = cap_reader.next_packet
Async CapReader
enable tokio feature first
use File;
use CapReader;
async
Fuzzing
Currently there are 4 crude harnesses to check that the parser won't panic in any situation. To start fuzzing you must install cargo-fuzz with the command:
And then, in the root of the repository, you can run the harnesses as:
Keep in mind that libfuzzer by default uses only one core, so you can either run all the harnesses in different terminals, or you can pass the -jobs and -workers attributes. More info can be found in its documentation here.
To get better crash reports add to you rust flags: -Zsanitizer=address.
E.g.
RUSTFLAGS="-Zsanitizer=address"
License
Licensed under MIT.
Disclaimer
To test the library I used the excellent PcapNg testing suite provided by hadrielk.