Struct etherparse::TcpHeader [−][src]
TCP header according to rfc 793.
Field descriptions copied from RFC 793 page 15++
Fields
source_port: u16
The source port number.
destination_port: u16
The destination port number.
sequence_number: u32
The sequence number of the first data octet in this segment (except when SYN is present).
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]
acknowledgment_number: u32
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.
ns: bool
ECN-nonce - concealment protection (experimental: see RFC 3540)
fin: bool
No more data from sender
syn: bool
Synchronize sequence numbers
rst: bool
Reset the connection
psh: bool
Push Function
ack: bool
Acknowledgment field significant
urg: bool
Urgent Pointer field significant
ece: bool
ECN-Echo (RFC 3168)
cwr: bool
Congestion Window Reduced (CWR) flag
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).
window_size: 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.
checksum: u16
Checksum (16 bit one's complement) of the pseudo ip header, this tcp header and the payload.
urgent_pointer: 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.
Implementations
impl TcpHeader
[src]
pub fn new(
source_port: u16,
destination_port: u16,
sequence_number: u32,
window_size: u16
) -> TcpHeader
[src]
source_port: u16,
destination_port: u16,
sequence_number: u32,
window_size: u16
) -> TcpHeader
Creates a TcpHeader with the given values and the rest initialized with default values.
pub fn data_offset(&self) -> u8
[src]
The number of 32 bit words in the TCP Header.
This indicates where the data begins. The TCP header (even one including options) is an integral number of 32 bits long.
pub fn header_len(&self) -> u16
[src]
Returns the length of the header including the options.
pub fn options_len(&self) -> usize
[src]
Returns the options size in bytes based on the currently set data_offset. Returns None if the data_offset is smaller then the minimum size or bigger then the maximum supported size.
pub fn options(&self) -> &[u8]
[src]
Returns a slice containing the options of the header (size is determined via the data_offset field.
pub fn set_options(
&mut self,
options: &[TcpOptionElement]
) -> Result<(), TcpOptionWriteError>
[src]
&mut self,
options: &[TcpOptionElement]
) -> Result<(), TcpOptionWriteError>
Sets the options (overwrites the current options) or returns an error when there is not enough space.
pub fn set_options_raw(
&mut self,
data: &[u8]
) -> Result<(), TcpOptionWriteError>
[src]
&mut self,
data: &[u8]
) -> Result<(), TcpOptionWriteError>
Sets the options to the data given.
pub fn options_iterator(&self) -> TcpOptionsIterator<'_>ⓘNotable traits for TcpOptionsIterator<'a>
impl<'a> Iterator for TcpOptionsIterator<'a> type Item = Result<TcpOptionElement, TcpOptionReadError>;
[src]
Notable traits for TcpOptionsIterator<'a>
impl<'a> Iterator for TcpOptionsIterator<'a> type Item = Result<TcpOptionElement, TcpOptionReadError>;
Returns an iterator that allows to iterate through all known TCP header options.
pub fn read_from_slice(slice: &[u8]) -> Result<(TcpHeader, &[u8]), ReadError>
[src]
Reads a tcp header from a slice
pub fn read<T: Read + Sized>(reader: &mut T) -> Result<TcpHeader, ReadError>
[src]
Read a tcp header from the current position
pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
[src]
Write the tcp header to a stream (does NOT calculate the checksum).
pub fn calc_checksum_ipv4(
&self,
ip_header: &Ipv4Header,
payload: &[u8]
) -> Result<u16, ValueError>
[src]
&self,
ip_header: &Ipv4Header,
payload: &[u8]
) -> Result<u16, ValueError>
Calculates the upd header checksum based on a ipv4 header and returns the result. This does NOT set the checksum.
pub fn calc_checksum_ipv4_raw(
&self,
source_ip: [u8; 4],
destination_ip: [u8; 4],
payload: &[u8]
) -> Result<u16, ValueError>
[src]
&self,
source_ip: [u8; 4],
destination_ip: [u8; 4],
payload: &[u8]
) -> Result<u16, ValueError>
Calculates the checksum for the current header in ipv4 mode and returns the result. This does NOT set the checksum.
pub fn calc_checksum_ipv6(
&self,
ip_header: &Ipv6Header,
payload: &[u8]
) -> Result<u16, ValueError>
[src]
&self,
ip_header: &Ipv6Header,
payload: &[u8]
) -> Result<u16, ValueError>
Calculates the upd header checksum based on a ipv6 header and returns the result. This does NOT set the checksum..
pub fn calc_checksum_ipv6_raw(
&self,
source: &[u8; 16],
destination: &[u8; 16],
payload: &[u8]
) -> Result<u16, ValueError>
[src]
&self,
source: &[u8; 16],
destination: &[u8; 16],
payload: &[u8]
) -> Result<u16, ValueError>
Calculates the checksum for the current header in ipv6 mode and returns the result. This does NOT set the checksum.
Trait Implementations
impl Clone for TcpHeader
[src]
impl Debug for TcpHeader
[src]
impl Default for TcpHeader
[src]
impl Eq for TcpHeader
[src]
impl PartialEq<TcpHeader> for TcpHeader
[src]
Auto Trait Implementations
impl RefUnwindSafe for TcpHeader
[src]
impl Send for TcpHeader
[src]
impl Sync for TcpHeader
[src]
impl Unpin for TcpHeader
[src]
impl UnwindSafe for TcpHeader
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,