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 = 128 * 1024 * 1024; pub const DEFAULT_FILE_NAME_FORMAT: &str =
25 "yyMMdd_HHmmss_fffffff";
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum PcapErrorCode {
31 Unknown = 0,
33 FileNotFound = 1001,
35 DirectoryNotFound = 1002,
37 InvalidFormat = 2001,
39 CorruptedHeader = 2002,
41 CorruptedData = 2003,
43 ChecksumMismatch = 2004,
45 InvalidPacketSize = 3001,
47 PacketSizeExceedsRemainingBytes = 3002,
49 TimestampParseError = 3003,
51 InvalidArgument = 3004,
53 InvalidState = 3005,
55}
56
57impl std::fmt::Display for PcapErrorCode {
58 fn fmt(
59 &self,
60 f: &mut std::fmt::Formatter<'_>,
61 ) -> std::fmt::Result {
62 match self {
63 PcapErrorCode::Unknown => write!(f, "未知错误"),
64 PcapErrorCode::FileNotFound => {
65 write!(f, "文件未找到")
66 }
67 PcapErrorCode::DirectoryNotFound => {
68 write!(f, "目录不存在")
69 }
70 PcapErrorCode::InvalidFormat => {
71 write!(f, "无效的文件格式")
72 }
73 PcapErrorCode::CorruptedHeader => {
74 write!(f, "文件头损坏")
75 }
76 PcapErrorCode::CorruptedData => {
77 write!(f, "数据包损坏")
78 }
79 PcapErrorCode::ChecksumMismatch => {
80 write!(f, "校验和不匹配")
81 }
82 PcapErrorCode::InvalidPacketSize => {
83 write!(f, "数据包大小无效")
84 }
85 PcapErrorCode::PacketSizeExceedsRemainingBytes => {
86 write!(f, "数据包长度超出文件剩余空间")
87 }
88 PcapErrorCode::TimestampParseError => {
89 write!(f, "时间戳解析错误")
90 }
91 PcapErrorCode::InvalidArgument => {
92 write!(f, "参数无效")
93 }
94 PcapErrorCode::InvalidState => {
95 write!(f, "操作状态无效")
96 }
97 }
98 }
99}