pub struct UdpPacket<'a> { /* private fields */ }Expand description
A read/write wrapper around an User Datagram Protocol packet buffer.
Implementations§
Source§impl<'a> Packet<'a>
impl<'a> Packet<'a>
Sourcepub const fn new_unchecked(buffer: &'a mut [u8]) -> Packet<'a>
pub const fn new_unchecked(buffer: &'a mut [u8]) -> Packet<'a>
Imbue a raw octet buffer with UDP packet structure.
Sourcepub fn new_checked(buffer: &'a mut [u8]) -> Result<Packet<'a>>
pub fn new_checked(buffer: &'a mut [u8]) -> Result<Packet<'a>>
Shorthand for a combination of new_unchecked and check_len.
Sourcepub fn check_len(&self) -> Result<()>
pub fn check_len(&self) -> Result<()>
Ensure that no accessor method will panic if called.
Returns Err(Error) if the buffer is too short.
Returns Err(Error) if the length field has a value smaller
than the header length, or larger than the buffer.
The result of this check is invalidated by calling set_len.
Sourcepub fn verify_checksum(
&self,
src_addr: &IpAddress,
dst_addr: &IpAddress,
) -> bool
pub fn verify_checksum( &self, src_addr: &IpAddress, dst_addr: &IpAddress, ) -> bool
Validate the packet checksum.
An all-zeroes checksum field means the transmitter didn’t generate one. That is accepted on UDP-over-IPv4, and rejected on UDP-over-IPv6, which requires checksums (RFC 8200 § 8.1).
§Panics
This function panics unless src_addr and dst_addr belong to the same family,
and that family is IPv4 or IPv6.
§Fuzzing
This function always returns true when fuzzing.
Sourcepub fn set_src_port(&mut self, value: u16)
pub fn set_src_port(&mut self, value: u16)
Set the source port field.
Sourcepub fn set_dst_port(&mut self, value: u16)
pub fn set_dst_port(&mut self, value: u16)
Set the destination port field.
Sourcepub fn set_checksum(&mut self, value: u16)
pub fn set_checksum(&mut self, value: u16)
Set the checksum field.
Sourcepub fn fill_checksum(&mut self, src_addr: &IpAddress, dst_addr: &IpAddress)
pub fn fill_checksum(&mut self, src_addr: &IpAddress, dst_addr: &IpAddress)
Compute and fill in the checksum.
§Panics
This function panics unless src_addr and dst_addr belong to the same family,
and that family is IPv4 or IPv6.
Sourcepub fn payload_mut(&mut self) -> &mut [u8] ⓘ
pub fn payload_mut(&mut self) -> &mut [u8] ⓘ
Return a mutable pointer to the payload.