Ipv4Hdr

Struct Ipv4Hdr 

Source
#[repr(C)]
pub struct Ipv4Hdr { pub vihl: u8, pub tos: u8, pub tot_len: [u8; 2], pub id: [u8; 2], pub frags: [u8; 2], pub ttl: u8, pub proto: IpProto, pub check: [u8; 2], pub src_addr: [u8; 4], pub dst_addr: [u8; 4], }
Expand description

IPv4 header, which is present after the Ethernet header.

Fields§

§vihl: u8§tos: u8§tot_len: [u8; 2]§id: [u8; 2]§frags: [u8; 2]§ttl: u8§proto: IpProto§check: [u8; 2]§src_addr: [u8; 4]§dst_addr: [u8; 4]

Implementations§

Source§

impl Ipv4Hdr

Source

pub const LEN: usize = 20usize

Source

pub fn version(&self) -> u8

Returns the IP version field (should be 4).

Source

pub fn ihl(&self) -> u8

Returns the IP header length in bytes.

Source

pub fn set_vihl(&mut self, version: u8, ihl_in_bytes: u8)

Sets both the version and IHL fields.

Source

pub fn dscp(&self) -> u8

Returns the DSCP (Differentiated Services Code Point) field.

Source

pub fn ecn(&self) -> u8

Returns the ECN (Explicit Congestion Notification) field.

Source

pub fn set_tos(&mut self, dscp: u8, ecn: u8)

Sets the TOS field with separate DSCP and ECN values.

Source

pub fn tot_len(&self) -> u16

Returns the total length of the IP packet.

Source

pub fn set_tot_len(&mut self, len: u16)

Sets the total length of the IP packet.

Source

pub fn id(&self) -> u16

Returns the identification field.

Source

pub fn set_id(&mut self, id: u16)

Sets the identification field.

Source

pub fn frag_flags(&self) -> u8

Returns the fragmentation flags (3 bits).

Source

pub fn frag_offset(&self) -> u16

Returns the fragmentation offset (13 bits).

Source

pub fn set_frags(&mut self, flags: u8, offset: u16)

Sets both the fragmentation flags and offset.

Source

pub fn checksum(&self) -> u16

Returns the checksum field.

Source

pub fn set_checksum(&mut self, checksum: u16)

Sets the checksum field.

Source

pub fn src_addr(&self) -> Ipv4Addr

Returns the source address field.

Source

pub fn dst_addr(&self) -> Ipv4Addr

Returns the destination address field.

Source

pub fn set_src_addr(&mut self, src: Ipv4Addr)

Sets the source address field.

Source

pub fn set_dst_addr(&mut self, dst: Ipv4Addr)

Sets the destination address field.

Trait Implementations§

Source§

impl Clone for Ipv4Hdr

Source§

fn clone(&self) -> Ipv4Hdr

Returns a duplicate 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 Ipv4Hdr

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for Ipv4Hdr

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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>,

Source§

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>,

Source§

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.