[][src]Struct pcap_file::PcapParser

pub struct PcapParser { /* fields omitted */ }

Parser for a Pcap formated stream.

Examples

use pcap_file::pcap::PcapParser;
use pcap_file::PcapError;

let pcap = vec![0_u8; 0];
let mut src = &pcap[..];

// Creates a new parser and parse the pcap header
let (rem, pcap_parser) = PcapParser::new(&pcap[..]).unwrap();
src = rem;

loop {

    match pcap_parser.next_packet(src) {
        Ok((rem, packet)) => {
            // Do something

            // Don't forget to update src
            src = rem;

            // No more data, if no more incoming either then this is the end of the file
            if rem.is_empty() {
                break;
            }
        },
        Err(PcapError::IncompleteBuffer(needed)) => {},// Load more data into src
        Err(_) => {}// Parsing error
    }
}

Methods

impl PcapParser[src]

pub fn new(slice: &[u8]) -> Result<(&[u8], PcapParser), PcapError>[src]

Creates a new PcapParser. Returns the parser and the remainder.

pub fn next_packet<'a>(
    &self,
    slice: &'a [u8]
) -> Result<(&'a [u8], Packet<'a>), PcapError>
[src]

Returns the next packet and the remainder.

Trait Implementations

impl Debug for PcapParser[src]

Auto Trait Implementations

Blanket Implementations

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

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

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]