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>
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 TCP 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 field has a value smaller
than the minimal header length.
The result of this check is invalidated by calling set_header_len.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the packet, returning the underlying buffer.
Sourcepub fn seq_number(&self) -> SeqNumber
pub fn seq_number(&self) -> SeqNumber
Return the sequence number field.
Sourcepub fn ack_number(&self) -> SeqNumber
pub fn ack_number(&self) -> SeqNumber
Return the acknowledgement number field.
Sourcepub fn header_len(&self) -> u8
pub fn header_len(&self) -> u8
Return the header length, in octets.
Sourcepub fn window_len(&self) -> u16
pub fn window_len(&self) -> u16
Return the window size field.
Sourcepub fn segment_len(&self) -> usize
pub fn segment_len(&self) -> usize
Return the length of the segment, in terms of sequence space.
Sourcepub fn selective_ack_permitted(&self) -> Result<bool>
pub fn selective_ack_permitted(&self) -> Result<bool>
Returns whether the selective acknowledgement SYN flag is set or not.
Source§impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T>
impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T>
Sourcepub fn set_src_port(&mut self, value: u16)
pub fn set_src_port(&mut self, value: u16)
Set the source port field.
Sourcepub fn set_dst_port(&mut self, value: u16)
pub fn set_dst_port(&mut self, value: u16)
Set the destination port field.
Sourcepub fn set_seq_number(&mut self, value: SeqNumber)
pub fn set_seq_number(&mut self, value: SeqNumber)
Set the sequence number field.
Sourcepub fn set_ack_number(&mut self, value: SeqNumber)
pub fn set_ack_number(&mut self, value: SeqNumber)
Set the acknowledgement number field.
Sourcepub fn clear_flags(&mut self)
pub fn clear_flags(&mut self)
Clear the entire flags 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_window_len(&mut self, value: u16)
pub fn set_window_len(&mut self, value: u16)
Set the window size field.
Sourcepub fn set_checksum(&mut self, value: u16)
pub fn set_checksum(&mut self, value: u16)
Set the checksum field.
Sourcepub fn set_urgent_at(&mut self, value: u16)
pub fn set_urgent_at(&mut self, value: u16)
Set the urgent pointer field.
Sourcepub fn fill_checksum(&mut self, src_addr: &IpAddress, dst_addr: &IpAddress)
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.
Sourcepub fn options_mut(&mut self) -> &mut [u8]
pub fn options_mut(&mut self) -> &mut [u8]
Return a pointer to the options.
Sourcepub fn payload_mut(&mut self) -> &mut [u8]
pub fn payload_mut(&mut self) -> &mut [u8]
Return a mutable pointer to the payload data.