Skip to main content

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;
7mod sync;
8pub use sync::*;
9#[cfg(feature = "tokio-async")]
10mod tokio_impl;
11use thiserror::Error;
12#[cfg(feature = "tokio-async")]
13pub use tokio_impl::AsyncPcapReader;
14
15use crate::{byte_order::UnexpectedSize, link_type::InvalidLinkType};
16
17/// Errors that can occur when parsing or writing pcap files
18#[derive(Debug, Error)]
19pub enum PcapParseError {
20    #[error(transparent)]
21    IO(#[from] std::io::Error),
22    #[error("Invalid magic number got {0:?}")]
23    InvalidMagicNumber(Option<[u8; 4]>),
24    #[error(transparent)]
25    InvalidLinkType(#[from] InvalidLinkType),
26    #[error(
27        "Invalid packet length: snap length {snap_length} is greater than included length {incl_len}"
28    )]
29    InvalidPacketLength { snap_length: u32, incl_len: u32 },
30    #[error("Invalid version")]
31    InvalidVersion,
32    /// This should never happen. But preventing panics
33    #[error(transparent)]
34    TryFromSliceError(#[from] std::array::TryFromSliceError),
35    #[error(transparent)]
36    UnexpectedSize(#[from] UnexpectedSize),
37}