pub struct PcapFlowSource<R: Read> { /* private fields */ }Available on crate feature
pcap only.Expand description
A pcap-backed source of PacketViews.
Wraps PcapReader from pcap-file and exposes ergonomic
iterators that hand off to netring-flow.
Implementations§
Source§impl PcapFlowSource<BufReader<File>>
impl PcapFlowSource<BufReader<File>>
Source§impl<R: Read> PcapFlowSource<R>
impl<R: Read> PcapFlowSource<R>
Sourcepub fn from_reader(reader: R) -> Result<Self, Error>
pub fn from_reader(reader: R) -> Result<Self, Error>
Wrap any Read (e.g., Cursor<&[u8]> for tests).
Sourcepub fn views(self) -> ViewIter<R> ⓘ
pub fn views(self) -> ViewIter<R> ⓘ
Iterate raw PacketViews. Each call yields the next packet
or Err on a malformed record.
Note: each OwnedPacketView owns its data (we copy from
the pcap reader because the underlying buffer is reused
across next_packet calls). One alloc per packet — fine for
offline analysis; not appropriate for sustained 1+ Gbps live
replay.
Sourcepub fn with_extractor<E: FlowExtractor>(self, extractor: E) -> EventIter<R, E> ⓘ
pub fn with_extractor<E: FlowExtractor>(self, extractor: E) -> EventIter<R, E> ⓘ
One-step pipeline: feed every view through extractor and
emit FlowEvents.
Constructs an internal FlowTracker with default config
and () for per-flow user state. For non-default config or
custom user state, drop down to the manual pattern:
use flowscope::pcap::PcapFlowSource;
use flowscope::{FlowTracker, FlowTrackerConfig};
use flowscope::extract::FiveTuple;
use std::time::Duration;
let mut tracker = FlowTracker::<FiveTuple>::with_config(
FiveTuple::bidirectional(),
FlowTrackerConfig {
idle_timeout_tcp: Duration::from_secs(60),
..Default::default()
},
);
for view in PcapFlowSource::open("trace.pcap")?.views() {
for _evt in tracker.track(view?.as_view()) {
// process
}
}Auto Trait Implementations§
impl<R> Freeze for PcapFlowSource<R>where
R: Freeze,
impl<R> RefUnwindSafe for PcapFlowSource<R>where
R: RefUnwindSafe,
impl<R> Send for PcapFlowSource<R>where
R: Send,
impl<R> Sync for PcapFlowSource<R>where
R: Sync,
impl<R> Unpin for PcapFlowSource<R>where
R: Unpin,
impl<R> UnsafeUnpin for PcapFlowSource<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for PcapFlowSource<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more