Struct etherparse::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 = 8usize

Serialized size of an UDP header in bytes/octets.

source

pub const LEN_U16: u16 = 8u16

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

source

pub const SERIALIZED_SIZE: usize = 8usize

👎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 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 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 PartialEq for UdpHeader

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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> 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,

§

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

§

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.