Struct etherparse::TcpSlice
source · pub struct TcpSlice<'a> { /* private fields */ }
Expand description
Slice containing the TCP header & payload.
Implementations§
source§impl<'a> TcpSlice<'a>
impl<'a> TcpSlice<'a>
sourcepub fn from_slice(slice: &'a [u8]) -> Result<TcpSlice<'a>, HeaderSliceError>
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.
sourcepub fn header_slice(&self) -> &'a [u8] ⓘ
pub fn header_slice(&self) -> &'a [u8] ⓘ
Returns the slice containing the TCP header (including options).
sourcepub const fn header_len(&self) -> usize
pub const fn header_len(&self) -> usize
Length of the TCP header (including TCP options).
sourcepub fn source_port(&self) -> u16
pub fn source_port(&self) -> u16
Read the destination port number in the TCP header.
sourcepub fn destination_port(&self) -> u16
pub fn destination_port(&self) -> u16
Read the destination port number in the TCP header.
sourcepub fn sequence_number(&self) -> u32
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]
sourcepub fn acknowledgment_number(&self) -> u32
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.
sourcepub fn data_offset(&self) -> u8
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.
sourcepub fn cwr(&self) -> bool
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).
sourcepub fn window_size(&self) -> u16
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.
sourcepub fn checksum(&self) -> u16
pub fn checksum(&self) -> u16
Checksum (16 bit one’s complement) of the pseudo ip header, this tcp header and the payload.
sourcepub fn urgent_pointer(&self) -> u16
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.
sourcepub fn options_iterator(&self) -> TcpOptionsIterator<'_> ⓘ
pub fn options_iterator(&self) -> TcpOptionsIterator<'_> ⓘ
Returns an iterator that allows to iterate through all known TCP header options.
sourcepub fn to_header(&self) -> TcpHeader
pub fn to_header(&self) -> TcpHeader
Decode all the fields and copy the results to a
crate::TcpHeader
` struct.
sourcepub fn calc_checksum_ipv4(
&self,
source_ip: [u8; 4],
destination_ip: [u8; 4]
) -> Result<u16, ValueTooBigError<usize>>
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.
sourcepub fn calc_checksum_ipv6(
&self,
source: [u8; 16],
destination: [u8; 16]
) -> Result<u16, ValueTooBigError<usize>>
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.