Struct pcaparse::cap::CapReader

source ·
pub struct CapReader<R> { /* private fields */ }
Expand description

Reads a cap from a reader.

Example

use std::fs::File;

use pcaparse::cap::CapReader;

let file_in = File::open("test.cap").expect("Error opening file");
let mut cap_reader = CapReader::new(file_in).unwrap();

// Read test.cap
while let Some(pkt) = cap_reader.next_packet() {
    //Check if there is no error
    let pkt = pkt.unwrap();

    //Do something
}

Implementations§

source§

impl<R> CapReader<R>

source

pub fn header(&self) -> CapHeader

Returns the global header of the cap.

source§

impl<R: Read> CapReader<R>

source

pub fn new(reader: R) -> Result<CapReader<R>, PcapError>

Creates a new CapReader from an existing reader.

This function reads the global cap header of the file to verify its integrity.

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

Errors

The data stream is not in a valid cap file format.

The underlying data are not readable.

source

pub fn into_reader(self) -> R

Consumes Self, returning the wrapped reader.

source

pub fn next_packet(&mut self) -> Option<Result<CapPacket<'_>, PcapError>>

Returns the next CapPacket.

source

pub fn next_raw_packet(&mut self) -> Option<Result<RawCapPacket<'_>, PcapError>>

Returns the next RawCapPacket.

Trait Implementations§

source§

impl<R> AsMut<R> for CapReader<R>

source§

fn as_mut(&mut self) -> &mut R

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<R> AsRef<R> for CapReader<R>

source§

fn as_ref(&self) -> &R

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<R: Debug> Debug for CapReader<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for CapReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for CapReader<R>
where R: Send,

§

impl<R> Sync for CapReader<R>
where R: Sync,

§

impl<R> Unpin for CapReader<R>
where R: Unpin,

§

impl<R> UnwindSafe for CapReader<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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.