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: u16Source port of the packet (optional).
destination_port: u16Destination port of the packet.
length: u16Length of the packet (includes the udp header length of 8 bytes).
checksum: u16The 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
impl UdpHeader
pub const SERIALIZED_SIZE: usize = 8usize
UdpHeader::LEN insteadsourcepub fn without_ipv4_checksum(
source_port: u16,
destination_port: u16,
payload_length: usize,
) -> Result<UdpHeader, ValueTooBigError<usize>>
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
sourcepub fn with_ipv4_checksum(
source_port: u16,
destination_port: u16,
ip_header: &Ipv4Header,
payload: &[u8],
) -> Result<UdpHeader, ValueTooBigError<usize>>
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
sourcepub fn calc_checksum_ipv4(
&self,
ip_header: &Ipv4Header,
payload: &[u8],
) -> Result<u16, ValueTooBigError<usize>>
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.
sourcepub fn calc_checksum_ipv4_raw(
&self,
source: [u8; 4],
destination: [u8; 4],
payload: &[u8],
) -> Result<u16, ValueTooBigError<usize>>
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.
sourcepub fn with_ipv6_checksum(
source_port: u16,
destination_port: u16,
ip_header: &Ipv6Header,
payload: &[u8],
) -> Result<UdpHeader, ValueTooBigError<usize>>
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
sourcepub fn calc_checksum_ipv6(
&self,
ip_header: &Ipv6Header,
payload: &[u8],
) -> Result<u16, ValueTooBigError<usize>>
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.
sourcepub fn calc_checksum_ipv6_raw(
&self,
source: [u8; 16],
destination: [u8; 16],
payload: &[u8],
) -> Result<u16, ValueTooBigError<usize>>
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.
sourcepub fn read_from_slice(slice: &[u8]) -> Result<(UdpHeader, &[u8]), LenError>
👎Deprecated since 0.10.1: Use UdpHeader::from_slice instead.
pub fn read_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.
sourcepub fn from_slice(slice: &[u8]) -> Result<(UdpHeader, &[u8]), LenError>
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.
sourcepub fn from_bytes(bytes: [u8; 8]) -> UdpHeader
pub fn from_bytes(bytes: [u8; 8]) -> UdpHeader
Read an UdpHeader from a static sized byte array.
sourcepub fn read<T: Read + Seek + Sized>(reader: &mut T) -> Result<UdpHeader, Error>
Available on crate feature std only.
pub fn read<T: Read + Seek + Sized>(reader: &mut T) -> Result<UdpHeader, Error>
std only.Tries to read an udp header from the current position.
sourcepub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
Available on crate feature std only.
pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
std only.Write the udp header without recalculating the checksum or length.
sourcepub const fn header_len(&self) -> usize
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.
sourcepub const fn header_len_u16(&self) -> u16
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.
Trait Implementations§
impl Eq for UdpHeader
impl StructuralPartialEq for UdpHeader
Auto Trait Implementations§
impl Freeze for UdpHeader
impl RefUnwindSafe for UdpHeader
impl Send for UdpHeader
impl Sync for UdpHeader
impl Unpin for UdpHeader
impl UnwindSafe for UdpHeader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)