pub struct GenericPcapReader<R: Read> { /* private fields */ }Expand description
Generic PCAP/PCAPNG reader over any Read source.
This is the unified PCAP parser that uses pcap_parser for all formats.
It provides a simple next_packet() interface that works with any byte source.
Implementations§
Source§impl<R: Read> GenericPcapReader<R>
impl<R: Read> GenericPcapReader<R>
Sourcepub fn with_format(source: R, format: PcapFormat) -> Result<Self, Error>
pub fn with_format(source: R, format: PcapFormat) -> Result<Self, Error>
Create a reader with known format.
This is the primary constructor. Use PcapFormat::detect() to determine
the format from magic bytes before calling this.
Note: For legacy PCAP, the header is read during construction to extract the link_type. For PCAPNG, link_type is initially 1 and gets updated when the Interface Description Block is read during packet processing.
Sourcepub fn next_packet(&mut self) -> Result<Option<RawPacket>, Error>
pub fn next_packet(&mut self) -> Result<Option<RawPacket>, Error>
Read the next packet.
Returns Ok(None) at end of file.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Get the current frame count.
Sourcepub fn process_packets<F>(&mut self, max: usize, f: F) -> Result<usize, Error>
pub fn process_packets<F>(&mut self, max: usize, f: F) -> Result<usize, Error>
Process packets with zero-copy borrowed data.
The callback receives borrowed packet data. The borrow is valid
only during the callback - data must be processed before returning.
This eliminates the Bytes::copy_from_slice() overhead of next_packet().
Returns the number of packets processed.