Struct etherparse::TcpSlice

source ·
pub struct TcpSlice<'a> { /* private fields */ }
Expand description

Slice containing the TCP header & payload.

Implementations§

source§

impl<'a> TcpSlice<'a>

source

pub fn from_slice(slice: &'a [u8]) -> Result<TcpSlice<'a>, HeaderSliceError>

Try creating a TcpSlice from a slice containing the TCP header and the TCP payload.

source

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

Returns the slice containing the TCP header and payload.

source

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

Returns the slice containing the TCP header (including options).

source

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

Returns the slice containing the TCP payload.

source

pub const fn header_len(&self) -> usize

Length of the TCP header (including TCP options).

source

pub fn source_port(&self) -> u16

Read the destination port number in the TCP header.

source

pub fn destination_port(&self) -> u16

Read the destination port number in the TCP header.

source

pub fn sequence_number(&self) -> u32

Read the sequence number in the TCP header.

If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1. [copied from RFC 793, page 16]

source

pub fn acknowledgment_number(&self) -> u32

Reads the acknowledgment number in the TCP header.

If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive.

Once a connection is established this is always sent.

source

pub fn data_offset(&self) -> u8

Read the number of 32 bit words in the TCP Header.

This indicates where the payload begins. The TCP header (even one including options) is an integral number of 32 bits long.

source

pub fn ns(&self) -> bool

ECN-nonce - concealment protection (experimental: see RFC 3540)

source

pub fn fin(&self) -> bool

Read the fin flag (no more data from sender).

source

pub fn syn(&self) -> bool

Reads the syn flag (synchronize sequence numbers).

source

pub fn rst(&self) -> bool

Reads the rst flag (reset the connection).

source

pub fn psh(&self) -> bool

Reads the psh flag (push function).

source

pub fn ack(&self) -> bool

Reads the ack flag (acknowledgment field significant).

source

pub fn urg(&self) -> bool

Reads the urg flag (Urgent Pointer field significant).

source

pub fn ece(&self) -> bool

Read the ECN-Echo flag (RFC 3168).

source

pub fn cwr(&self) -> bool

Reads the cwr flag (Congestion Window Reduced).

This flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168).

source

pub fn window_size(&self) -> u16

The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept.

source

pub fn checksum(&self) -> u16

Checksum (16 bit one’s complement) of the pseudo ip header, this tcp header and the payload.

source

pub fn urgent_pointer(&self) -> u16

This field communicates the current value of the urgent pointer as a positive offset from the sequence number in this segment.

The urgent pointer points to the sequence number of the octet following the urgent data. This field is only be interpreted in segments with the URG control bit set.

source

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

Options of the header

source

pub fn options_iterator(&self) -> TcpOptionsIterator<'_>

Returns an iterator that allows to iterate through all known TCP header options.

source

pub fn to_header(&self) -> TcpHeader

Decode all the fields and copy the results to a crate::TcpHeader` struct.

source

pub fn calc_checksum_ipv4( &self, source_ip: [u8; 4], destination_ip: [u8; 4] ) -> Result<u16, ValueTooBigError<usize>>

Calculates the checksum for the current header in ipv4 mode and returns the result. This does NOT set the checksum.

source

pub fn calc_checksum_ipv6( &self, source: [u8; 16], destination: [u8; 16] ) -> Result<u16, ValueTooBigError<usize>>

Calculates the checksum for the current header in ipv6 mode and returns the result. This does NOT set the checksum.

Trait Implementations§

source§

impl<'a> Clone for TcpSlice<'a>

source§

fn clone(&self) -> TcpSlice<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for TcpSlice<'a>

source§

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

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

impl<'a> PartialEq for TcpSlice<'a>

source§

fn eq(&self, other: &TcpSlice<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for TcpSlice<'a>

source§

impl<'a> StructuralPartialEq for TcpSlice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for TcpSlice<'a>

§

impl<'a> RefUnwindSafe for TcpSlice<'a>

§

impl<'a> Send for TcpSlice<'a>

§

impl<'a> Sync for TcpSlice<'a>

§

impl<'a> Unpin for TcpSlice<'a>

§

impl<'a> UnwindSafe for TcpSlice<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

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

Performs the conversion.