pub struct Packet<T> { /* private fields */ }Expand description
A read/write wrapper around an User Datagram Protocol packet buffer.
Implementations§
Source§impl<T: Payload> Packet<T>
impl<T: Payload> Packet<T>
Sourcepub fn new_checked(buffer: T, checksum: Checksum) -> Result<Self>
pub fn new_checked(buffer: T, checksum: Checksum) -> Result<Self>
Shorthand for a combination of new_unchecked and check_len.
Sourcepub fn new_unchecked(buffer: T, repr: Repr) -> Self
pub fn new_unchecked(buffer: T, repr: Repr) -> Self
Constructs a frame with assumed representation.
The validity of the frame is never a safety invariant but wrong data can still lead to inconsistent handling. In particular, wrong assumptions on the length may panic at runtime due to bounds checks.
Sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Get an immutable reference to the whole buffer.
Useful if the buffer is some other packet encapsulation.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the frame, returning the underlying buffer.
Sourcepub fn payload_mut_slice(&mut self) -> &mut [u8]where
T: PayloadMut,
pub fn payload_mut_slice(&mut self) -> &mut [u8]where
T: PayloadMut,
Return the payload as a mutable byte slice.
Source§impl<T: Payload + PayloadMut> Packet<T>
impl<T: Payload + PayloadMut> Packet<T>
Sourcepub fn fill_checksum(&mut self, checksum: Checksum)
pub fn fill_checksum(&mut self, checksum: Checksum)
Recalculate the checksum if necessary.
Note that the checksum test can be elided for non-Ipv6 upper layer protocol. This
provides in opportunity to recalculate it if necessary even though the header structure is
not otherwise mutably accessible while in Packet representation.
Source§impl<'a, T: Payload + ?Sized> Packet<&'a T>
impl<'a, T: Payload + ?Sized> Packet<&'a T>
Sourcepub fn payload_slice(&self) -> &'a [u8]
pub fn payload_slice(&self) -> &'a [u8]
Return a pointer to the payload.
Source§impl<T: Payload + PayloadMut> Packet<T>
impl<T: Payload + PayloadMut> Packet<T>
Sourcepub fn payload_mut(&mut self) -> &mut [u8]
pub fn payload_mut(&mut self) -> &mut [u8]
Return a mutable pointer to the payload.
Methods from Deref<Target = udp>§
Sourcepub fn check_len(&self) -> Result<()>
pub fn check_len(&self) -> Result<()>
Ensure that no accessor method will panic if called.
Returns Err(Error::Truncated) if the buffer is too short.
Returns Err(Error::Malformed) if the length field has a value smaller
than the header length.
The result of this check is invalidated by calling set_len.