pcapfile_io/foundation/
types.rs1pub mod constants {
7 pub const PCAP_MAGIC_NUMBER: u32 = 0xD4C3B2A1;
9
10 pub const MAJOR_VERSION: u16 = 2;
12
13 pub const MINOR_VERSION: u16 = 4;
15
16 pub const DEFAULT_MAX_PACKETS_PER_FILE: usize = 500;
18
19 pub const MAX_BUFFER_SIZE: usize = 50 * 1024 * 1024; pub const DEFAULT_FILE_NAME_FORMAT: &str =
24 "yyMMdd_HHmmss_fffffff";
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum PcapErrorCode {
30 Unknown = 0,
32 FileNotFound = 1001,
34 DirectoryNotFound = 1002,
36 InvalidFormat = 2001,
38 CorruptedHeader = 2002,
40 CorruptedData = 2003,
42 ChecksumMismatch = 2004,
44 InvalidPacketSize = 3001,
46 PacketSizeExceedsRemainingBytes = 3002,
48 TimestampParseError = 3003,
50 InvalidArgument = 3004,
52 InvalidState = 3005,
54}
55
56impl std::fmt::Display for PcapErrorCode {
57 fn fmt(
58 &self,
59 f: &mut std::fmt::Formatter<'_>,
60 ) -> std::fmt::Result {
61 match self {
62 PcapErrorCode::Unknown => write!(f, "未知错误"),
63 PcapErrorCode::FileNotFound => {
64 write!(f, "文件未找到")
65 }
66 PcapErrorCode::DirectoryNotFound => {
67 write!(f, "目录不存在")
68 }
69 PcapErrorCode::InvalidFormat => {
70 write!(f, "无效的文件格式")
71 }
72 PcapErrorCode::CorruptedHeader => {
73 write!(f, "文件头损坏")
74 }
75 PcapErrorCode::CorruptedData => {
76 write!(f, "数据包损坏")
77 }
78 PcapErrorCode::ChecksumMismatch => {
79 write!(f, "校验和不匹配")
80 }
81 PcapErrorCode::InvalidPacketSize => {
82 write!(f, "数据包大小无效")
83 }
84 PcapErrorCode::PacketSizeExceedsRemainingBytes => {
85 write!(f, "数据包长度超出文件剩余空间")
86 }
87 PcapErrorCode::TimestampParseError => {
88 write!(f, "时间戳解析错误")
89 }
90 PcapErrorCode::InvalidArgument => {
91 write!(f, "参数无效")
92 }
93 PcapErrorCode::InvalidState => {
94 write!(f, "操作状态无效")
95 }
96 }
97 }
98}