PcapDataEngine

Struct PcapDataEngine 

Source
pub struct PcapDataEngine<A: PcapAnalyzer> { /* private fields */ }
Expand description

pcap/pcap-ng data analyzer engine

PcapDataEngine iterates over a pcap input, parses data and abstracts the format (pcap datalink, endianness etc.) for the analysis.

PcapDataEngine stores a PcapAnalyzer instance, and wraps it to receive parsed data blocks. Internally, it is an abstraction over a BlockEngine.

§example

use pako_tools::{Config, Error, Packet, ParseContext, PcapAnalyzer, PcapDataEngine, PcapEngine};
#[derive(Default)]
pub struct ExampleAnalyzer {
    packet_count: usize,
}

impl PcapAnalyzer for ExampleAnalyzer {
    fn handle_packet(&mut self, packet: &Packet, ctx: &ParseContext) -> Result<(), Error> {
        Ok(())
    }
}

let config = Config::default();
let analyzer = ExampleAnalyzer::default();
let mut engine = PcapDataEngine::new(analyzer, &config);

// `engine.run()` can take any `mut Read` as input
// Here, we use a cursor as an example
use std::io::Cursor;
let mut input = Cursor::new(vec![1, 2, 3, 4, 5]);
let res = engine.run(&mut input);

Implementations§

Source§

impl<A: PcapAnalyzer> PcapDataEngine<A>

Source

pub fn new(data_analyzer: A, config: &Config) -> Self

Source

pub fn data_analyzer(&self) -> &A

Source

pub fn data_analyzer_mut(&mut self) -> &mut A

Trait Implementations§

Source§

impl<A: PcapAnalyzer> PcapEngine for PcapDataEngine<A>

Source§

fn run(&mut self, reader: &mut dyn Read) -> Result<(), Error>

Main function: given a reader, read all pcap data and call analyzer for each Packet

Auto Trait Implementations§

§

impl<A> Freeze for PcapDataEngine<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for PcapDataEngine<A>
where A: RefUnwindSafe,

§

impl<A> Send for PcapDataEngine<A>
where A: Send,

§

impl<A> Sync for PcapDataEngine<A>
where A: Sync,

§

impl<A> Unpin for PcapDataEngine<A>
where A: Unpin,

§

impl<A> UnwindSafe for PcapDataEngine<A>
where A: 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, 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.