[][src]Struct pcap_file::pcap::PcapHeader

pub struct PcapHeader {
    pub magic_number: u32,
    pub version_major: u16,
    pub version_minor: u16,
    pub ts_correction: i32,
    pub ts_accuracy: u32,
    pub snaplen: u32,
    pub datalink: DataLink,
}

Pcap Global Header

Fields

magic_number: u32

Magic number

version_major: u16

Major version number

version_minor: u16

Minor version number

ts_correction: i32

GMT to local timezone correction, should always be 0

ts_accuracy: u32

Timestamp accuracy, should always be 0

snaplen: u32

Max length of captured packet, typically 65535

datalink: DataLink

DataLink type (first layer in the packet)

Methods

impl PcapHeader[src]

pub fn from_reader<R: Read>(reader: &mut R) -> Result<PcapHeader, PcapError>[src]

Creates a new PcapHeader from a reader

Returns an error if the reader doesn't contain a valid pcap or if there is a reading error.

pub fn from_slice(slice: &[u8]) -> Result<(&[u8], PcapHeader), PcapError>[src]

Creates a new PcapHeader from a slice of bytes

Returns an error if the reader doesn't contain a valid pcap or if there is a reading error.

PcapError::IncompleteBuffer indicates that there is not enough data in the buffer

pub fn set_ts_resolution(&mut self, ts_resolution: TsResolution)[src]

Set the timestamp resolution to ts_resolution by modifying the magic_number Preserve its endianness

pub fn set_endianness(&mut self, endianness: Endianness)[src]

Change the endianness of the magic_number

pub fn write_to<W: Write, B: ByteOrder>(
    &self,
    writer: &mut W
) -> Result<(), PcapError>
[src]

Write a PcapHeader to a writer.

Writes 24o in the writer on success.

pub fn endianness(&self) -> Endianness[src]

Return the endianness of the pcap

Panics

Panics if the magic number is invalid

pub fn ts_resolution(&self) -> TsResolution[src]

Return the timestamp resolution of the pcap

Panics

Panics if the magic number is invalid

pub fn to_array<B: ByteOrder>(&self) -> Result<Vec<u8>, PcapError>[src]

Deprecated since 1.0.0:

Please use write_to instead

Convert a PcapHeader to a Vec<u8>.

Deprecated since 1.0.0:

Please use the Default struct constructor instead, will be removed in 1.0

Creates a new PcapHeader with the following parameters:

This example is not tested
PcapHeader {

    magic_number : 0xa1b2c3d4,
    version_major : 2,
    version_minor : 4,
    ts_correction : 0,
    ts_accuracy : 0,
    snaplen : 65535,
    datalink : #datalink
};

Trait Implementations

impl Clone for PcapHeader[src]

impl Copy for PcapHeader[src]

impl Default for PcapHeader[src]

Creates a new PcapHeader with the default parameters:

This example is not tested
PcapHeader {

    magic_number : 0xa1b2c3d4,
    version_major : 2,
    version_minor : 4,
    ts_correction : 0,
    ts_accuracy : 0,
    snaplen : 65535,
    datalink : DataLink::ETHERNET
};

impl Eq for PcapHeader[src]

impl PartialEq<PcapHeader> for PcapHeader[src]

impl Debug for PcapHeader[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]