1#[derive(Debug)]
3pub enum IoError {
4 Socket(std::io::Error),
6 Parse(&'static str),
8 Timeout,
10 InvalidMagic(u32),
12 UnsupportedVersion { major: u16, minor: u16 },
14 TruncatedRecord { expected: u32, got: usize },
16 InterfaceNotFound(String),
18 PermissionDenied,
20 Bpf(&'static str),
22 Npcap(String),
24 UnsupportedPlatform,
26}
27
28impl core::fmt::Display for IoError {
29 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30 match self {
31 Self::Socket(e) => write!(f, "socket error: {e}"),
32 Self::Parse(msg) => write!(f, "parse error: {msg}"),
33 Self::Timeout => write!(f, "timeout"),
34 Self::InvalidMagic(m) => write!(f, "invalid pcap magic number: 0x{m:08X}"),
35 Self::UnsupportedVersion { major, minor } => {
36 write!(f, "unsupported pcap version: {major}.{minor}")
37 }
38 Self::TruncatedRecord { expected, got } => {
39 write!(f, "truncated pcap record: expected {expected} bytes, got {got}")
40 }
41 Self::InterfaceNotFound(name) => write!(f, "interface not found: {name}"),
42 Self::PermissionDenied => write!(f, "permission denied (root/Administrator required)"),
43 Self::Bpf(msg) => write!(f, "BPF error: {msg}"),
44 Self::Npcap(msg) => write!(f, "NPcap error: {msg}"),
45 Self::UnsupportedPlatform => write!(f, "operation not supported on this platform"),
46 }
47 }
48}
49
50impl std::error::Error for IoError {}
51
52impl From<std::io::Error> for IoError {
53 fn from(e: std::io::Error) -> Self {
54 IoError::Socket(e)
55 }
56}