Skip to main content

wireforge_app/pcap/
mod.rs

1//! pcap and pcapng file reader/writer.
2
3mod types;
4mod reader;
5mod writer;
6mod ng_reader;
7mod ng_writer;
8
9pub use types::{Endianness, LinkType, PcapHeader, PcapRecordHeader, PcapNgBlock};
10pub use reader::PcapReader;
11pub use writer::PcapWriter;
12pub use ng_reader::PcapNgReader;
13pub use ng_writer::PcapNgWriter;
14
15/// Common interface for reading packet captures (pcap or pcapng).
16///
17/// Two adapters implement this trait: [`PcapReader`] and [`PcapNgReader`].
18/// Both yield `(timestamp, raw_packet_data)` tuples regardless of the
19/// underlying file format.
20pub trait PacketCaptureReader {
21    type Error;
22
23    /// The link-layer type of the captured packets, if known.
24    fn link_type(&self) -> Option<LinkType>;
25
26    /// Read the next captured packet. Returns `None` at end-of-file.
27    #[allow(clippy::type_complexity)]
28    fn next_packet(&mut self) -> Option<Result<(std::time::Duration, Vec<u8>), Self::Error>>;
29}