4 releases

Uses old Rust 2015

0.3.0 Sep 2, 2017
0.2.2 Aug 18, 2017
0.2.1 Aug 2, 2017
0.2.0 Aug 1, 2017

#661 in Network programming

Download history 177/week @ 2021-08-19 85/week @ 2021-08-26 24/week @ 2021-09-02 97/week @ 2021-09-09 23/week @ 2021-09-16 99/week @ 2021-09-23 50/week @ 2021-09-30 78/week @ 2021-10-07 143/week @ 2021-10-14 34/week @ 2021-10-21 32/week @ 2021-10-28 46/week @ 2021-11-04 69/week @ 2021-11-18 69/week @ 2021-11-25 31/week @ 2021-12-02

169 downloads per month
Used in 3 crates

MIT/Apache

28KB
575 lines

RPCAP

Build Status

An all-Rust library for reading and writing PCAP files.

Full API Documentation

// read a PCAP file
let infile = File::open("example.pcap").unwrap();
let reader = BufReader::new(infile);
let mut pcapr = PcapReader::new(reader).unwrap();
println!("linktype: {}", pcapr.get_linktype());
println!("snaplen: {}", pcapr.get_snaplen());

// create a new PCAP file
let outfile = File::create("copy.pcap").unwrap();
let writer = BufWriter::new(outfile);
let mut pcapw = PcapWriter::new(writer, WriteOptions {
    snaplen: pcapr.get_linktype(),
    linktype: pcapr.get_snaplen(),
}).unwrap();

// copy all packets from example.pcap to copy.pcap
while let Some(packet) = pcapr.next().unwrap() {
    println!("packet at {} with size {} (cropped from {})",
        packet.time, packet.data.len(), packet.orig_len);
    pcapw.write(&packet).unwrap();
}

Please note that there is no support for the newer pcapng file format. If you need that, you might want to have a look at the libpcap-wrapper for rust. The same applies if you need the advanced filtering options it has out of the box. To disect the packets from the pcap file, you could use the pnet library. In the time between me writing and publishing this library, it looks like the pcap-file and pcap-rs libraries have popped up, which seem to be doing a very similar thing as this library.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5MB
~39K SLoC