pub struct Ipv4Packet<T: AsRef<[u8]>> { /* private fields */ }
Expand description
A read/write wrapper around an Internet Protocol version 4 packet buffer.
Implementations§
Source§impl<T: AsRef<[u8]>> Packet<T>
impl<T: AsRef<[u8]>> Packet<T>
Sourcepub const fn new_unchecked(buffer: T) -> Packet<T>
pub const fn new_unchecked(buffer: T) -> Packet<T>
Imbue a raw octet buffer with IPv4 packet structure.
Sourcepub fn new_checked(buffer: T) -> Result<Packet<T>>
pub fn new_checked(buffer: T) -> Result<Packet<T>>
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 header length is greater
than total length.
The result of this check is invalidated by calling set_header_len and set_total_len.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the packet, returning the underlying buffer.
Sourcepub fn header_len(&self) -> u8
pub fn header_len(&self) -> u8
Return the header length, in octets.
Sourcepub fn more_frags(&self) -> bool
pub fn more_frags(&self) -> bool
Return the “more fragments” flag.
Sourcepub fn frag_offset(&self) -> u16
pub fn frag_offset(&self) -> u16
Return the fragment offset, in octets.
Sourcepub fn next_header(&self) -> Protocol
pub fn next_header(&self) -> Protocol
Return the next_header (protocol) field.
Sourcepub fn verify_checksum(&self) -> bool
pub fn verify_checksum(&self) -> bool
Source§impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T>
impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T>
Sourcepub fn set_version(&mut self, value: u8)
pub fn set_version(&mut self, value: u8)
Set the version field.
Sourcepub fn set_header_len(&mut self, value: u8)
pub fn set_header_len(&mut self, value: u8)
Set the header length, in octets.
Sourcepub fn set_total_len(&mut self, value: u16)
pub fn set_total_len(&mut self, value: u16)
Set the total length field.
Sourcepub fn clear_flags(&mut self)
pub fn clear_flags(&mut self)
Clear the entire flags field.
Sourcepub fn set_dont_frag(&mut self, value: bool)
pub fn set_dont_frag(&mut self, value: bool)
Set the “don’t fragment” flag.
Sourcepub fn set_more_frags(&mut self, value: bool)
pub fn set_more_frags(&mut self, value: bool)
Set the “more fragments” flag.
Sourcepub fn set_frag_offset(&mut self, value: u16)
pub fn set_frag_offset(&mut self, value: u16)
Set the fragment offset, in octets.
Sourcepub fn set_hop_limit(&mut self, value: u8)
pub fn set_hop_limit(&mut self, value: u8)
Set the time to live field.
Sourcepub fn set_next_header(&mut self, value: Protocol)
pub fn set_next_header(&mut self, value: Protocol)
Set the next header (protocol) field.
Sourcepub fn set_checksum(&mut self, value: u16)
pub fn set_checksum(&mut self, value: u16)
Set the header checksum field.
Sourcepub fn set_src_addr(&mut self, value: Address)
pub fn set_src_addr(&mut self, value: Address)
Set the source address field.
Sourcepub fn set_dst_addr(&mut self, value: Address)
pub fn set_dst_addr(&mut self, value: Address)
Set the destination address field.
Sourcepub fn fill_checksum(&mut self)
pub fn fill_checksum(&mut self)
Compute and fill in the header checksum.
Sourcepub fn payload_mut(&mut self) -> &mut [u8]
pub fn payload_mut(&mut self) -> &mut [u8]
Return a mutable pointer to the payload.
Trait Implementations§
Source§impl<T: AsRef<[u8]>> PrettyPrint for Packet<T>
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T>
Source§fn pretty_print(
buffer: &dyn AsRef<[u8]>,
f: &mut Formatter<'_>,
indent: &mut PrettyIndent,
) -> Result
fn pretty_print( buffer: &dyn AsRef<[u8]>, f: &mut Formatter<'_>, indent: &mut PrettyIndent, ) -> Result
impl<T: Eq + AsRef<[u8]>> Eq for Packet<T>
impl<T: AsRef<[u8]>> StructuralPartialEq for Packet<T>
Auto Trait Implementations§
impl<T> Freeze for Packet<T>where
T: Freeze,
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§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)