Skip to main content

PcapFlowSource

Struct PcapFlowSource 

Source
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>>

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, Error>

Open a pcap file from disk.

Source§

impl<R: Read> PcapFlowSource<R>

Source

pub fn from_reader(reader: R) -> Result<Self, Error>

Wrap any Read (e.g., Cursor<&[u8]> for tests).

Source

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.

Source

pub fn with_extractor<E: FlowExtractor>(self, extractor: E) -> EventIter<R, E> ⓘ
where E::Key: Clone,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.