pcapfile_io/foundation/
types.rs1pub mod constants {
7 pub const PCAP_MAGIC_NUMBER: u32 = 0xD4C3B2A1;
9
10 pub const PROJ_MAGIC_NUMBER: u32 = 0xA1B2C3D4;
12
13 pub const MAJOR_VERSION: u16 = 2;
15
16 pub const MINOR_VERSION: u16 = 4;
18
19 pub const DEFAULT_MAX_PACKETS_PER_FILE: usize = 500;
21
22 pub const MAX_BUFFER_SIZE: usize = 50 * 1024 * 1024; pub const DEFAULT_FILE_NAME_FORMAT: &str =
27 "yyMMdd_HHmmss_fffffff";
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum PcapErrorCode {
33 Unknown = 0,
35 FileNotFound = 1001,
37 DirectoryNotFound = 1002,
39 InvalidFormat = 2001,
41 CorruptedHeader = 2002,
43 CorruptedData = 2003,
45 ChecksumMismatch = 2004,
47 InvalidPacketSize = 3001,
49 InvalidArgument = 3002,
51 InvalidState = 3003,
53}
54
55impl std::fmt::Display for PcapErrorCode {
56 fn fmt(
57 &self,
58 f: &mut std::fmt::Formatter<'_>,
59 ) -> std::fmt::Result {
60 match self {
61 PcapErrorCode::Unknown => write!(f, "未知错误"),
62 PcapErrorCode::FileNotFound => {
63 write!(f, "文件未找到")
64 }
65 PcapErrorCode::DirectoryNotFound => {
66 write!(f, "目录不存在")
67 }
68 PcapErrorCode::InvalidFormat => {
69 write!(f, "无效的文件格式")
70 }
71 PcapErrorCode::CorruptedHeader => {
72 write!(f, "文件头损坏")
73 }
74 PcapErrorCode::CorruptedData => {
75 write!(f, "数据包损坏")
76 }
77 PcapErrorCode::ChecksumMismatch => {
78 write!(f, "校验和不匹配")
79 }
80 PcapErrorCode::InvalidPacketSize => {
81 write!(f, "数据包大小无效")
82 }
83 PcapErrorCode::InvalidArgument => {
84 write!(f, "参数无效")
85 }
86 PcapErrorCode::InvalidState => {
87 write!(f, "操作状态无效")
88 }
89 }
90 }
91}