netpkt/tcp.rs#
Source: lib/netpkt/tcp.rs
tcp -- the TCP header and its options (RFC 9293, 7323, 2018)
TcpView::parse(b) ports, sequence and acknowledgement numbers, flags, window, options,
payload; checksum_ok_v4 / _v6
TcpOpts MSS, window scale, SACK permitted, SACK blocks, timestamps
TcpHdr { .. } push_v4 / push_v6 (&mut Pkt) with the checksum; the options are
written in the usual order and padded with NOPs / EOL
flags_str(flags) "SYN, ACK"
seq_lt / seq_le / seq_gt / seq_ge comparisons in sequence space (modulo 2^32)
port_name(port) well-known names ("http", "ssh", ...)
TCP_MIN: usize = 20
TCP_MAX: usize = 60
FIN: u8 = 0x01
SYN: u8 = 0x02
RST: u8 = 0x04
PSH: u8 = 0x08
ACK: u8 = 0x10
URG: u8 = 0x20
ECE: u8 = 0x40
CWR: u8 = 0x80
OPT_EOL: u8 = 0
OPT_NOP: u8 = 1
OPT_MSS: u8 = 2
OPT_WSCALE: u8 = 3
OPT_SACK_OK: u8 = 4
OPT_SACK: u8 = 5
OPT_TS: u8 = 8
fn seq_lt(a: u32, b: u32) -> boola < b in sequence spacefn seq_le(a: u32, b: u32) -> boolfn seq_gt(a: u32, b: u32) -> boolfn seq_ge(a: u32, b: u32) -> boolstruct TcpOptsthe TCP options this library understandsmss: Option<u16>wscale: Option<u8>sack_ok: boolsack: [(u32, u32); 4]-- SACK blocks (left, right edge);sack_nof them are validsack_n: u8ts: Option<(u32, u32)>-- timestamp value and echo reply
impl TcpOpts
fn parse(b: &[u8]) -> TcpOptsparses an option block; unknown options are skipped, a malformed one ends the walkfn len(&self) -> usizethe encoded length, padded to a multiple of 4fn is_empty(&self) -> boolfn write(&self, out: &mut [u8])writes the options (MSS, SACK-permitted, timestamps, window scale, SACK), NOP paddingstruct TcpView<'a>a received TCP segment
impl<'a> TcpView<'a>
fn parse(b: &'a [u8]) -> Option<TcpView<'a>>fn src_port(&self) -> u16fn dst_port(&self) -> u16fn seq(&self) -> u32fn ack(&self) -> u32fn header_len(&self) -> usizefn flags(&self) -> u8fn has(&self, f: u8) -> boolfn window(&self) -> u16fn checksum(&self) -> u16fn urgent(&self) -> u16fn options_raw(&self) -> &'a [u8]fn opts(&self) -> TcpOptsfn payload(&self) -> &'a [u8]fn bytes(&self) -> &'a [u8]fn seg_len(&self) -> u32the sequence space the segment occupies: payload length + SYN + FINfn checksum_ok_v4(&self, src: Ipv4, dst: Ipv4) -> boolfn checksum_ok_v6(&self, src: Ipv6, dst: Ipv6) -> boolstruct TcpHdra TCP header to writesrc_port: u16dst_port: u16seq: u32ack: u32flags: u8window: u16urgent: u16opts: TcpOpts
impl TcpHdr
fn read(v: &TcpView) -> TcpHdrfn len(&self) -> usizefn push_v4(&self, p: &mut Pkt, src: Ipv4, dst: Ipv4)prepends the header (the packet's content is the payload) with the IPv4 checksumfn push_v6(&self, p: &mut Pkt, src: Ipv6, dst: Ipv6)the same with the IPv6 pseudo headerfn flags_str(f: u8) -> String"SYN, ACK" (Wireshark order: FIN SYN RST PSH ACK URG ECE CWR)fn port_name(port: u16) -> Option<&'static str>a short name of a well-known TCP port