smoltcp::wire

Struct TcpPacket

Source
pub struct TcpPacket<T: AsRef<[u8]>> { /* private fields */ }
Expand description

A read/write wrapper around a Transmission Control Protocol packet buffer.

Implementations§

Source§

impl<T: AsRef<[u8]>> Packet<T>

Source

pub const fn new_unchecked(buffer: T) -> Packet<T>

Imbue a raw octet buffer with TCP packet structure.

Source

pub fn new_checked(buffer: T) -> Result<Packet<T>>

Shorthand for a combination of new_unchecked and check_len.

Source

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 field has a value smaller than the minimal header length.

The result of this check is invalidated by calling set_header_len.

Source

pub fn into_inner(self) -> T

Consume the packet, returning the underlying buffer.

Source

pub fn src_port(&self) -> u16

Return the source port field.

Source

pub fn dst_port(&self) -> u16

Return the destination port field.

Source

pub fn seq_number(&self) -> SeqNumber

Return the sequence number field.

Source

pub fn ack_number(&self) -> SeqNumber

Return the acknowledgement number field.

Source

pub fn fin(&self) -> bool

Return the FIN flag.

Source

pub fn syn(&self) -> bool

Return the SYN flag.

Source

pub fn rst(&self) -> bool

Return the RST flag.

Source

pub fn psh(&self) -> bool

Return the PSH flag.

Source

pub fn ack(&self) -> bool

Return the ACK flag.

Source

pub fn urg(&self) -> bool

Return the URG flag.

Source

pub fn ece(&self) -> bool

Return the ECE flag.

Source

pub fn cwr(&self) -> bool

Return the CWR flag.

Source

pub fn ns(&self) -> bool

Return the NS flag.

Source

pub fn header_len(&self) -> u8

Return the header length, in octets.

Source

pub fn window_len(&self) -> u16

Return the window size field.

Source

pub fn checksum(&self) -> u16

Return the checksum field.

Source

pub fn urgent_at(&self) -> u16

Return the urgent pointer field.

Source

pub fn segment_len(&self) -> usize

Return the length of the segment, in terms of sequence space.

Source

pub fn selective_ack_permitted(&self) -> Result<bool>

Returns whether the selective acknowledgement SYN flag is set or not.

Source

pub fn selective_ack_ranges(&self) -> Result<[Option<(u32, u32)>; 3]>

Return the selective acknowledgement ranges, if any. If there are none in the packet, an array of None values will be returned.

Source

pub fn verify_checksum( &self, src_addr: &IpAddress, dst_addr: &IpAddress, ) -> bool

Validate the packet checksum.

§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.

Source§

impl<'a, T: AsRef<[u8]> + ?Sized> Packet<&'a T>

Source

pub fn options(&self) -> &'a [u8]

Return a pointer to the options.

Source

pub fn payload(&self) -> &'a [u8]

Return a pointer to the payload.

Source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T>

Source

pub fn set_src_port(&mut self, value: u16)

Set the source port field.

Source

pub fn set_dst_port(&mut self, value: u16)

Set the destination port field.

Source

pub fn set_seq_number(&mut self, value: SeqNumber)

Set the sequence number field.

Source

pub fn set_ack_number(&mut self, value: SeqNumber)

Set the acknowledgement number field.

Source

pub fn clear_flags(&mut self)

Clear the entire flags field.

Source

pub fn set_fin(&mut self, value: bool)

Set the FIN flag.

Source

pub fn set_syn(&mut self, value: bool)

Set the SYN flag.

Source

pub fn set_rst(&mut self, value: bool)

Set the RST flag.

Source

pub fn set_psh(&mut self, value: bool)

Set the PSH flag.

Source

pub fn set_ack(&mut self, value: bool)

Set the ACK flag.

Source

pub fn set_urg(&mut self, value: bool)

Set the URG flag.

Source

pub fn set_ece(&mut self, value: bool)

Set the ECE flag.

Source

pub fn set_cwr(&mut self, value: bool)

Set the CWR flag.

Source

pub fn set_ns(&mut self, value: bool)

Set the NS flag.

Source

pub fn set_header_len(&mut self, value: u8)

Set the header length, in octets.

Source

pub fn set_window_len(&mut self, value: u16)

Set the window size field.

Source

pub fn set_checksum(&mut self, value: u16)

Set the checksum field.

Source

pub fn set_urgent_at(&mut self, value: u16)

Set the urgent pointer field.

Source

pub fn fill_checksum(&mut self, src_addr: &IpAddress, dst_addr: &IpAddress)

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.

Source

pub fn options_mut(&mut self) -> &mut [u8]

Return a pointer to the options.

Source

pub fn payload_mut(&mut self) -> &mut [u8]

Return a mutable pointer to the payload data.

Trait Implementations§

Source§

impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone + AsRef<[u8]>> Clone for Packet<T>

Source§

fn clone(&self) -> Packet<T>

Returns a copy of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + AsRef<[u8]>> Debug for Packet<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: AsRef<[u8]> + ?Sized> Display for Packet<&'a T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq + AsRef<[u8]>> PartialEq for Packet<T>

Source§

fn eq(&self, other: &Packet<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: AsRef<[u8]>> PrettyPrint for Packet<T>

Source§

fn pretty_print( buffer: &dyn AsRef<[u8]>, f: &mut Formatter<'_>, indent: &mut PrettyIndent, ) -> Result

Write a concise, formatted representation of a packet contained in the provided buffer, and any nested packets it may contain. Read more
Source§

impl<T: Eq + AsRef<[u8]>> Eq for Packet<T>

Source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.