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 NameTooLong(usize),
18 CompressionLoop,
20 InterfaceNotFound(String),
22 PermissionDenied,
24 Bpf(&'static str),
26 Npcap(String),
28 UnsupportedPlatform,
30}
31
32impl core::fmt::Display for IoError {
33 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
34 match self {
35 Self::Socket(e) => write!(f, "socket error: {e}"),
36 Self::Parse(msg) => write!(f, "parse error: {msg}"),
37 Self::Timeout => write!(f, "timeout"),
38 Self::InvalidMagic(m) => write!(f, "invalid pcap magic number: 0x{m:08X}"),
39 Self::UnsupportedVersion { major, minor } => {
40 write!(f, "unsupported pcap version: {major}.{minor}")
41 }
42 Self::TruncatedRecord { expected, got } => {
43 write!(f, "truncated pcap record: expected {expected} bytes, got {got}")
44 }
45 Self::NameTooLong(len) => write!(f, "DNS name label too long: {len} bytes (max 63)"),
46 Self::CompressionLoop => write!(f, "DNS name compression loop detected"),
47 Self::InterfaceNotFound(name) => write!(f, "interface not found: {name}"),
48 Self::PermissionDenied => write!(f, "permission denied (root/Administrator required)"),
49 Self::Bpf(msg) => write!(f, "BPF error: {msg}"),
50 Self::Npcap(msg) => write!(f, "NPcap error: {msg}"),
51 Self::UnsupportedPlatform => write!(f, "operation not supported on this platform"),
52 }
53 }
54}
55
56impl std::error::Error for IoError {}
57
58impl From<std::io::Error> for IoError {
59 fn from(e: std::io::Error) -> Self {
60 IoError::Socket(e)
61 }
62}