pub struct Ipv4PacketHeader {
    pub version: u8,
    pub hlen: u8,
    pub tos: u8,
    pub len: u16,
    pub id: u16,
    pub off: u16,
    pub ttl: u8,
    pub p: u8,
    pub sum: u16,
    pub src: Ipv4Addr,
    pub dst: Ipv4Addr,
}

Fields§

§version: u8§hlen: u8§tos: u8§len: u16§id: u16§off: u16§ttl: u8§p: u8§sum: u16§src: Ipv4Addr§dst: Ipv4Addr

Implementations§

source§

impl Ipv4PacketHeader

source

pub const MIN_SIZE: usize = 20usize

source

pub const CHECKSUM_WORD: usize = 5usize

source

pub const IP_DF: u16 = 16_384u16

source

pub const IP_MF: u16 = 8_192u16

source

pub fn new(src: Ipv4Addr, dst: Ipv4Addr, proto: u8) -> Self

source

pub fn decode(data: &[u8]) -> Result<Self, Error>

Parses the packet from a byte slice

source

pub fn encode<'o>(&self, buf: &'o mut [u8]) -> Result<&'o [u8], Error>

Encodes the packet into the provided buf slice

source

pub fn encode_with_payload<'o, F>( &mut self, buf: &'o mut [u8], encoder: F ) -> Result<&'o [u8], Error>
where F: FnOnce(&mut [u8]) -> Result<usize, Error>,

source

pub fn decode_with_payload( packet: &[u8], filter_src: Ipv4Addr, filter_dst: Ipv4Addr, filter_proto: Option<u8> ) -> Result<Option<(Self, &[u8])>, Error>

source

pub fn inject_checksum(packet: &mut [u8], checksum: u16)

source

pub fn checksum(packet: &[u8]) -> u16

Trait Implementations§

source§

impl Clone for Ipv4PacketHeader

source§

fn clone(&self) -> Ipv4PacketHeader

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ipv4PacketHeader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.