Struct UdpPacket
pub struct UdpPacket<'a> { /* private fields */ }Expand description
A read/write wrapper around an User Datagram Protocol packet buffer.
Implementations§
§impl<'a> Packet<'a>
impl<'a> Packet<'a>
pub 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.
pub fn new_checked(buffer: &'a mut [u8]) -> Result<Packet<'a>, Error>
pub fn new_checked(buffer: &'a mut [u8]) -> Result<Packet<'a>, Error>
Shorthand for a combination of new_unchecked and check_len.
pub fn check_len(&self) -> Result<(), Error>
pub fn check_len(&self) -> Result<(), Error>
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.
pub fn verify_checksum(&self, src_addr: &Address, dst_addr: &Address) -> bool
pub fn verify_checksum(&self, src_addr: &Address, dst_addr: &Address) -> 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.
pub fn set_src_port(&mut self, value: u16)
pub fn set_src_port(&mut self, value: u16)
Set the source port field.
pub fn set_dst_port(&mut self, value: u16)
pub fn set_dst_port(&mut self, value: u16)
Set the destination port field.
pub fn set_checksum(&mut self, value: u16)
pub fn set_checksum(&mut self, value: u16)
Set the checksum field.
pub fn fill_checksum(&mut self, src_addr: &Address, dst_addr: &Address)
pub fn fill_checksum(&mut self, src_addr: &Address, dst_addr: &Address)
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.
pub fn payload_mut(&mut self) -> &mut [u8] ⓘ
pub fn payload_mut(&mut self) -> &mut [u8] ⓘ
Return a mutable pointer to the payload.