Legacy Pcap parsing & writing
A modified version of courvoif/pcap-file that supports only
the old legacy pcap file format (.pcap
extension).
The PCAP format is very simple. see here for a description of its structure. This crate provides some abstractions over it for reading and writing, including streaming variants. It is also non-async.
This crate has no external dependencies (apart from std). It has also no unsafe code.
All abstractions use the standard library Read
and Write
traits.
Examples
Reading data the easy way:
use PcapReader;
// Let's assume this is some pcap data. It can also be a file.
// Anything implementing `Read`.
let some_buffer = vec!;
let pcap_reader = new.unwrap;
// Packets can be iterated on.
for res in pcap_reader
Reading data while reusing the packet buffer. (This is a bit of a hack).
use PcapReader;
// Let's assume this is some pcap data. It can also be a file.
// Anything implementing `Read`.
let some_buffer = vec!;
let pcap_reader = new.unwrap;
// Define some backing data for the packets payload.
let mut backing_data = vec!;
// Iterate manually.
while let Some = pcap_reader.next_with
Writing data:
use ;
// Let's say you have a pcap header defined
let header: PcapHeader = ...
// and some supply of packets
let packets: = ...
// They can be written like so
let path = from;
let mut pcap_file_writer = new_with_header.unwrap;
for packet in packets
pcap_file_writer.close.unwrap;
License
Licensed under MIT/Apache-2.0 license.