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
impl UdpHeader
sourcepub fn without_ipv4_checksum(
source_port: u16,
destination_port: u16,
payload_length: usize
) -> Result<UdpHeader, ValueError>
pub fn without_ipv4_checksum(
source_port: u16,
destination_port: u16,
payload_length: usize
) -> Result<UdpHeader, ValueError>
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, ValueError>
pub fn with_ipv4_checksum(
source_port: u16,
destination_port: u16,
ip_header: &Ipv4Header,
payload: &[u8]
) -> Result<UdpHeader, ValueError>
Calculate an udp header given an ipv4 header and the payload
sourcepub fn calc_checksum_ipv4(
&self,
ip_header: &Ipv4Header,
payload: &[u8]
) -> Result<u16, ValueError>
pub fn calc_checksum_ipv4(
&self,
ip_header: &Ipv4Header,
payload: &[u8]
) -> Result<u16, ValueError>
Calculates the upd header checksum based on a ipv4 header.
sourcepub fn calc_checksum_ipv4_raw(
&self,
source: [u8; 4],
destination: [u8; 4],
protocol: u8,
payload: &[u8]
) -> Result<u16, ValueError>
pub fn calc_checksum_ipv4_raw(
&self,
source: [u8; 4],
destination: [u8; 4],
protocol: u8,
payload: &[u8]
) -> Result<u16, ValueError>
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, ValueError>
pub fn with_ipv6_checksum(
source_port: u16,
destination_port: u16,
ip_header: &Ipv6Header,
payload: &[u8]
) -> Result<UdpHeader, ValueError>
Calculate an udp header given an ipv6 header and the payload
sourcepub fn calc_checksum_ipv6(
&self,
ip_header: &Ipv6Header,
payload: &[u8]
) -> Result<u16, ValueError>
pub fn calc_checksum_ipv6(
&self,
ip_header: &Ipv6Header,
payload: &[u8]
) -> Result<u16, ValueError>
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, ValueError>
pub fn calc_checksum_ipv6_raw(
&self,
source: &[u8; 16],
destination: &[u8; 16],
payload: &[u8]
) -> Result<u16, ValueError>
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]), ReadError>
pub fn read_from_slice(slice: &[u8]) -> Result<(UdpHeader, &[u8]), ReadError>
Reads a udp header from a slice directly and returns a tuple containing the resulting header & unused part of the slice.
Trait Implementations§
source§impl SerializedSize for UdpHeader
impl SerializedSize for UdpHeader
source§const SERIALIZED_SIZE: usize = 8usize
const SERIALIZED_SIZE: usize = 8usize
Size of the header itself