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
34
35
36
37
38
39
40
41
42
43
44
use thiserror::Error;
pub type PcapResult<T> = Result<T, PcapError>;
#[derive(Error, Debug)]
pub enum PcapError {
#[error("Need more bytes")]
IncompleteBuffer,
#[error("Error reading bytes")]
IoError(#[source] std::io::Error),
#[error("Invalid field value: {0}")]
InvalidField(&'static str),
#[error("UTF8 error")]
Utf8Error(#[source] std::str::Utf8Error),
#[error("UTF8 error")]
FromUtf8Error(#[source] std::string::FromUtf8Error),
#[error("No corresponding interface id: {0}")]
InvalidInterfaceId(u32),
}
impl From<std::str::Utf8Error> for PcapError {
fn from(err: std::str::Utf8Error) -> Self {
PcapError::Utf8Error(err)
}
}
impl From<std::string::FromUtf8Error> for PcapError {
fn from(err: std::string::FromUtf8Error) -> Self {
PcapError::FromUtf8Error(err)
}
}