[][src]Struct pcap_file::pcap::PcapReader

pub struct PcapReader<T: Read> {
    pub header: PcapHeader,
    // some fields omitted
}

Wraps another reader and uses it to read a Pcap formated stream.

It implements the Iterator trait in order to read one packet at a time

Examples

use std::fs::File;
use pcap_file::pcap::PcapReader;

let file_in = File::open("test.pcap").expect("Error opening file");
let pcap_reader = PcapReader::new(file_in).unwrap();

// Read test.pcap
for pcap in pcap_reader {

    //Check if there is no error
    let pcap = pcap.unwrap();

    //Do something
}

Fields

header: PcapHeader

Methods

impl<T: Read> PcapReader<T>[src]

pub fn new(reader: T) -> Result<PcapReader<T>, PcapError>[src]

Create a new PcapReader from an existing reader. This function read the global pcap header of the file to verify its integrity.

The underlying reader must point to a valid pcap file/stream.

Errors

Return an error if the data stream is not in a valid pcap file format. Or if the underlying data are not readable.

Examples

use std::fs::File;
use pcap_file::pcap::PcapReader;

let file_in = File::open("test.pcap").expect("Error opening file");
let pcap_reader = PcapReader::new(file_in).unwrap();

pub fn into_reader(self) -> T[src]

Consumes the PcapReader, returning the wrapped reader.

pub fn get_ref(&self) -> &T[src]

Gets a reference to the underlying reader.

It is not advised to directly read from the underlying reader.

pub fn get_mut(&mut self) -> &mut T[src]

Gets a mutable reference to the underlying reader.

It is not advised to directly read from the underlying reader.

Trait Implementations

impl<T: Read> Iterator for PcapReader<T>[src]

type Item = Result<Packet<'static>, PcapError>

The type of the elements being iterated over.

impl<T: Debug + Read> Debug for PcapReader<T>[src]

Auto Trait Implementations

impl<T> Send for PcapReader<T> where
    T: Send

impl<T> Sync for PcapReader<T> where
    T: Sync

impl<T> Unpin for PcapReader<T> where
    T: Unpin

impl<T> UnwindSafe for PcapReader<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for PcapReader<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]