[−][src]Struct pcap_parser::LegacyPcapReader
Parsing iterator over legacy pcap data (streaming version)
This iterator a streaming parser based on a circular buffer, so any input providing the Read
trait can be used.
The first call to next
will return the file header. Some information of this header must
be stored (for ex. the data link type) to be able to parse following block contents.
Following calls to next
will always return legacy data blocks.
The size of the circular buffer has to be big enough for at least one complete block. Using a larger value (at least 65k) is advised to avoid frequent reads and buffer shifts.
use pcap_parser::*; use pcap_parser::traits::PcapReaderIterator; use nom::ErrorKind; use std::fs::File; use std::io::Read; let mut file = File::open(path).unwrap(); let mut num_blocks = 0; let mut reader = LegacyPcapReader::new(65536, file).expect("LegacyPcapReader"); loop { match reader.next() { Ok((offset, block)) => { println!("got new block"); num_blocks += 1; match block { PcapBlockOwned::LegacyHeader(_hdr) => { // save hdr.network (linktype) }, PcapBlockOwned::Legacy(_b) => { // use linktype to parse b.data() }, PcapBlockOwned::NG(_) => unreachable!(), } reader.consume(offset); }, Err(ErrorKind::Eof) => break, Err(e) => panic!("error while reading: {:?}", e), } } println!("num_blocks: {}", num_blocks);
Methods
impl<R> LegacyPcapReader<R> where
R: Read,
[src]
R: Read,
pub fn new(
capacity: usize,
reader: R
) -> Result<LegacyPcapReader<R>, ErrorKind<u32>>
[src]
capacity: usize,
reader: R
) -> Result<LegacyPcapReader<R>, ErrorKind<u32>>
pub fn from_buffer(
buffer: Buffer,
reader: R
) -> Result<LegacyPcapReader<R>, ErrorKind<u32>>
[src]
buffer: Buffer,
reader: R
) -> Result<LegacyPcapReader<R>, ErrorKind<u32>>
Trait Implementations
impl<R> PcapReaderIterator<R> for LegacyPcapReader<R> where
R: Read,
[src]
R: Read,
Auto Trait Implementations
impl<R> Unpin for LegacyPcapReader<R> where
R: Unpin,
R: Unpin,
impl<R> Sync for LegacyPcapReader<R> where
R: Sync,
R: Sync,
impl<R> Send for LegacyPcapReader<R> where
R: Send,
R: Send,
impl<R> UnwindSafe for LegacyPcapReader<R> where
R: UnwindSafe,
R: UnwindSafe,
impl<R> RefUnwindSafe for LegacyPcapReader<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,