Skip to main content

UdpHeader

Struct UdpHeader 

Source
pub struct UdpHeader {
    pub source_port: u16,
    pub destination_port: u16,
    pub length: u16,
    pub checksum: u16,
}
Expand description

Udp header according to rfc768.

Fields§

§source_port: u16

Source port of the packet (optional).

§destination_port: u16

Destination port of the packet.

§length: u16

Length of the packet (includes the udp header length of 8 bytes).

§checksum: u16

The checksum of the packet. The checksum is calculated from a pseudo header, the udp header and the payload. The pseudo header is composed of source and destination address, protocol number

Implementations§

Source§

impl UdpHeader

Source

pub const LEN: usize = 8

Serialized size of an UDP header in bytes/octets.

Source

pub const LEN_U16: u16 = 8

Serialized size of an UDP header in bytes/octets in an u16.

Source

pub const SERIALIZED_SIZE: usize = UdpHeader::LEN

👎Deprecated since 0.14.0:

Use UdpHeader::LEN instead

Source

pub fn without_ipv4_checksum( source_port: u16, destination_port: u16, payload_length: usize, ) -> Result<UdpHeader, ValueTooBigError<usize>>

Returns an udp header for the given parameters

Source

pub fn with_ipv4_checksum( source_port: u16, destination_port: u16, ip_header: &Ipv4Header, payload: &[u8], ) -> Result<UdpHeader, ValueTooBigError<usize>>

Calculate an udp header given an ipv4 header and the payload

Source

pub fn calc_checksum_ipv4( &self, ip_header: &Ipv4Header, payload: &[u8], ) -> Result<u16, ValueTooBigError<usize>>

Calculates the upd header checksum based on a ipv4 header.

Source

pub fn calc_checksum_ipv4_raw( &self, source: [u8; 4], destination: [u8; 4], payload: &[u8], ) -> Result<u16, ValueTooBigError<usize>>

Calculates the upd header checksum based on a ipv4 header.

Source

pub fn with_ipv6_checksum( source_port: u16, destination_port: u16, ip_header: &Ipv6Header, payload: &[u8], ) -> Result<UdpHeader, ValueTooBigError<usize>>

Calculate an udp header given an ipv6 header and the payload

Source

pub fn calc_checksum_ipv6( &self, ip_header: &Ipv6Header, payload: &[u8], ) -> Result<u16, ValueTooBigError<usize>>

Calculates the checksum of the current udp header given an ipv6 header and the payload.

Source

pub fn calc_checksum_ipv6_raw( &self, source: [u8; 16], destination: [u8; 16], payload: &[u8], ) -> Result<u16, ValueTooBigError<usize>>

Calculates the checksum of the current udp header given an ipv6 source & destination address plus the payload.

Source

pub fn read_from_slice(slice: &[u8]) -> Result<(UdpHeader, &[u8]), LenError>

👎Deprecated since 0.10.1:

Use UdpHeader::from_slice instead.

Reads a udp header from a slice directly and returns a tuple containing the resulting header & unused part of the slice.

Source

pub fn from_slice(slice: &[u8]) -> Result<(UdpHeader, &[u8]), LenError>

Reads a udp header from a slice directly and returns a tuple containing the resulting header & unused part of the slice.

Source

pub fn from_bytes(bytes: [u8; 8]) -> UdpHeader

Read an UdpHeader from a static sized byte array.

Source

pub fn read<T: Read + Seek + Sized>(reader: &mut T) -> Result<UdpHeader, Error>

Available on crate feature std only.

Tries to read an udp header from the current position.

Source

pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>

Available on crate feature std only.

Write the udp header without recalculating the checksum or length.

Source

pub const fn header_len(&self) -> usize

Length of the serialized header in bytes.

The function always returns the constant crate::UdpHeader::LEN and exists to keep the methods consistent with other headers.

Source

pub const fn header_len_u16(&self) -> u16

Length of the serialized header in bytes in an u16.

The function always returns the constant crate::UdpHeader::LEN_U16 and exists to keep the methods consistent with other headers.

Source

pub fn to_bytes(&self) -> [u8; 8]

Returns the serialized form of the header as a statically sized byte array.

Trait Implementations§

Source§

impl Clone for UdpHeader

Source§

fn clone(&self) -> UdpHeader

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 UdpHeader

Source§

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

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

impl Default for UdpHeader

Source§

fn default() -> UdpHeader

Returns the “default value” for a type. Read more
Source§

impl Hash for UdpHeader

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for UdpHeader

Source§

fn cmp(&self, other: &UdpHeader) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for UdpHeader

Source§

fn eq(&self, other: &UdpHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for UdpHeader

Source§

fn partial_cmp(&self, other: &UdpHeader) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for UdpHeader

Source§

impl StructuralPartialEq for UdpHeader

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.