1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::errors::PcapError;
use byteorder::{ByteOrder, ReadBytesExt};
#[derive(Clone, Debug)]
pub struct SimplePacketBlock<'a> {
pub original_len: u32,
pub data: &'a [u8]
}
impl<'a> SimplePacketBlock<'a> {
pub fn from_slice<B: ByteOrder>(mut slice: &'a [u8]) -> Result<(&'a [u8], Self), PcapError> {
if slice.len() < 4 {
return Err(PcapError::InvalidField("SimplePacketBlock: block length < 4"));
}
let original_len = slice.read_u32::<B>()?;
let packet = SimplePacketBlock {
original_len,
data: slice
};
Ok((&[], packet))
}
}