pub struct UdpPacket<T>where
T: AsRef<[u8]>,{ /* private fields */ }
Expand description
A read/write wrapper around an User Datagram Protocol packet buffer.
Implementations§
§impl<T> Packet<T>where
T: AsRef<[u8]>,
impl<T> Packet<T>where T: AsRef<[u8]>,
pub const fn new_unchecked(buffer: T) -> Packet<T>
pub const fn new_unchecked(buffer: T) -> Packet<T>
Imbue a raw octet buffer with UDP packet structure.
pub fn new_checked(buffer: T) -> Result<Packet<T>, Error>
pub fn new_checked(buffer: T) -> Result<Packet<T>, 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.
The result of this check is invalidated by calling set_len.
pub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the packet, returning the underlying buffer.
§impl<T> Packet<T>where
T: AsRef<[u8]> + AsMut<[u8]>,
impl<T> Packet<T>where T: AsRef<[u8]> + AsMut<[u8]>,
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 header 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.
Trait Implementations§
§impl<T> PrettyPrint for Packet<T>where
T: AsRef<[u8]>,
impl<T> PrettyPrint for Packet<T>where T: AsRef<[u8]>,
§fn pretty_print(
buffer: &dyn AsRef<[u8]>,
f: &mut Formatter<'_>,
indent: &mut PrettyIndent
) -> Result<(), Error>
fn pretty_print( buffer: &dyn AsRef<[u8]>, f: &mut Formatter<'_>, indent: &mut PrettyIndent ) -> Result<(), Error>
Write a concise, formatted representation of a packet contained in the provided
buffer, and any nested packets it may contain. Read more
impl<T> Eq for Packet<T>where T: Eq + AsRef<[u8]>,
impl<T> StructuralEq for Packet<T>where T: AsRef<[u8]>,
impl<T> StructuralPartialEq for Packet<T>where T: AsRef<[u8]>,
Auto Trait Implementations§
impl<T> RefUnwindSafe for Packet<T>where T: RefUnwindSafe,
impl<T> Send for Packet<T>where T: Send,
impl<T> Sync for Packet<T>where T: Sync,
impl<T> Unpin for Packet<T>where T: Unpin,
impl<T> UnwindSafe for Packet<T>where T: UnwindSafe,
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
Mutably borrows from an owned value. Read more