pub struct CapParser { /* private fields */ }Expand description
Parses a Cap from a slice of bytes.
You can match on PcapError::IncompleteBuffer to known if the parser need more data.
Example
use pcaparse::cap::CapParser;
use pcaparse::PcapError;
let cap = vec![0_u8; 0];
let mut src = &cap[..];
// Creates a new parser and parse the cap header
let (rem, cap_parser) = CapParser::new(&cap[..]).unwrap();
src = rem;
loop {
match cap_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) => {}, // Load more data into src
Err(_) => {}, // Parsing error
}
}Implementations§
source§impl CapParser
impl CapParser
sourcepub fn new(slice: &[u8]) -> PcapResult<(&[u8], CapParser)>
pub fn new(slice: &[u8]) -> PcapResult<(&[u8], CapParser)>
Creates a new CapParser.
Returns the remainder and the parser.
sourcepub fn next_packet<'a>(
&self,
slice: &'a [u8]
) -> PcapResult<(&'a [u8], CapPacket<'a>)>
pub fn next_packet<'a>( &self, slice: &'a [u8] ) -> PcapResult<(&'a [u8], CapPacket<'a>)>
Returns the remainder and the next CapPacket.
sourcepub fn next_raw_packet<'a>(
&self,
slice: &'a [u8]
) -> PcapResult<(&'a [u8], RawCapPacket<'a>)>
pub fn next_raw_packet<'a>( &self, slice: &'a [u8] ) -> PcapResult<(&'a [u8], RawCapPacket<'a>)>
Returns the remainder and the next RawCapPacket.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for CapParser
impl Send for CapParser
impl Sync for CapParser
impl Unpin for CapParser
impl UnwindSafe for CapParser
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more