rusty_pcap/pcap/
mod.rs

1//! Parsing for PCAP Files based on the libpcap format
2//!
3//! Sources
4//! - [Wireshark Wiki - File Format](https://wiki.wireshark.org/Development/LibpcapFileFormat)
5pub mod file_header;
6pub mod packet_header;
7pub mod sync;
8#[cfg(feature = "tokio-async")]
9pub mod tokio_impl;
10use thiserror::Error;
11
12use crate::{byte_order::UnexpectedSize, link_type::InvalidLinkType};
13
14/// Errors that can occur when parsing or writing pcap files
15#[derive(Debug, Error)]
16pub enum PcapParseError {
17    #[error(transparent)]
18    IO(#[from] std::io::Error),
19    #[error("Invalid magic number got {0:?}")]
20    InvalidMagicNumber(Option<[u8; 4]>),
21    #[error(transparent)]
22    InvalidLinkType(#[from] InvalidLinkType),
23    #[error(
24        "Invalid packet length: snap length {snap_length} is greater than included length {incl_len}"
25    )]
26    InvalidPacketLength { snap_length: u32, incl_len: u32 },
27    #[error("Invalid version")]
28    InvalidVersion,
29    /// This should never happen. But preventing panics
30    #[error(transparent)]
31    TryFromSliceError(#[from] std::array::TryFromSliceError),
32    #[error(transparent)]
33    UnexpectedSize(#[from] UnexpectedSize),
34}