TCP(3)

πŸ’– TCP(3) β€” the tcp 1.7 manual, bestie edition πŸ’–

okay so you found the TCP(3) page, welcome, pull up a chair, we're decoding the Transport Control Protocol layer together and honestly? it's giving iconic. this is from the tcp 1.7 manual, and I'm gonna walk you through every single bit of it, no cap. πŸ¦‹


✨ NAME ✨

packet.transport.tcp β€” the TCP module. that's it, that's the name, she's simple and she's powerful. πŸ‘‘


🌸 DESCRIPTION 🌸

Decode TCP layer. literally just β€” decode the TCP layer. that's the whole job description and she does it flawlessly. πŸ’…

the vibes are specified by these, and I am quoting them exactly:

  • RFC 793 TRANSMISSION CONTROL PROTOCOL
  • RFC 2018 TCP Selective Acknowledgment Options
  • RFC 7323 TCP Extensions for High Performance

three RFCs, one legend. πŸ”₯


πŸŽ€ CLASSES πŸŽ€

class Flags(packet.utils.OptionFlags)

TCP Option flags. she's a subclass of packet.utils.OptionFlags and she's here to hold your flag bits, no notes. ✨

Methods defined here:


  • __str__ = str_flags(self) β€” yep, that's literally the line, she just points at str_flags(self). 🫢

class Option(baseobj.BaseObj)

Option object. a whole little object for a TCP option, we love a dedicated class. πŸ’œ

Methods defined here:


  • __init__(self, unpack) β€” Constructor which takes an unpack object as input. πŸ“

class Stream(baseobj.BaseObj)

TCP stream buffer object. yes bestie, we're buffering streams, this is where the fragments live. 🌈

Methods defined here:


  • __init__(self, seqno) β€” Constructor.

Initialize object's private data according to the arguments given. Arguments can be given as positional, named arguments or a combination of both. (flexible queen 🧚)

  • add_fragment(self, data, seq) β€” Add fragment data to stream buffer. 🧩
  • missing_fragment(self, seq) β€” Check if given sequence number is within a missing fragment. πŸ”

class TCP(baseobj.BaseObj)

TCP object. the main character, obviously. πŸ‘‘

Usage:

from packet.transport.tcp import TCP

x = TCP(pktt)

Object definition:

TCP(
    src_port    = int, # Source port
    dst_port    = int, # Destination port
    seq_number  = int, # Sequence number
    ack_number  = int, # Acknowledgment number
    hl          = int, # Data offset or header length (32bit words)
    header_size = int, # Data offset or header length in bytes
    flags = Flags(     # TCP flags:
        rawflags = int,#   Raw flags
        FIN = int,     #   No more data from sender
        SYN = int,     #   Synchronize sequence numbers
        RST = int,     #   Synchronize sequence numbers
        PSH = int,     #   Push function. Asks to push the buffered
                       #     data to the receiving application
        ACK = int,     #   Acknowledgment field is significant
        URG = int,     #   Urgent pointer field is significant
        ECE = int,     #   ECN-Echo has a dual role:
                       #     SYN=1, the TCP peer is ECN capable.
                       #     SYN=0, packet with Congestion Experienced
                       #     flag in IP header set is received during
                       #     normal transmission
        CWR = int,     #   Congestion Window Reduced
        NS  = int,     #   ECN-nonce concealment protection
    ),
    window_size = int, # Window size
    checksum    = int, # Checksum
    urgent_ptr  = int, # Urgent pointer
    seq         = int, # Relative sequence number
    options = list,    # List of TCP options
    psize = int,       # Payload data size
    data = string,     # Raw data of payload if unable to decode
)

Methods defined here:


  • __init__(self, pktt) β€” Constructor.

Initialize object's private data.

  • pktt: Packet trace object (packet.pktt.Pktt) so this layer has access to the parent layers. (she needs to know her ancestors, periodt. 🌳)
  • __str__(self) β€” String representation of object.

The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned.

If set to 1 the representation of the object is condensed:

'TCP 708 -> 2049, seq: 0xc4592255, ack: 0xca66dda1, ACK,FIN'

If set to 2 the representation of the object also includes the length of payload and a little bit more verbose:

'src port 708 -> dst port 2049, seq: 0xc4592255, ack: 0xca66dda1, len: 0, flags: FIN,ACK'

three levels of glow-up, pick your vibe. ✨


πŸ‘€ SEE ALSO πŸ‘€

the whole friend group, go say hi:

baseobj(3), packet.application.dns(3), packet.application.krb5(3), packet.application.rpc(3), packet.transport.mpa(3), packet.unpack(3), packet.utils(3)

iykyk. πŸ’«


πŸ’€ BUGS πŸ’€

No known bugs.

not a single one. she's flawless, she's that girl, nothing to see here, we move. πŸ’…βœ¨


🫢 AUTHOR 🫢

Jorge Mora (mora@netapp.com)

give him his flowers, he wrote the whole thing. 🌸


okay that's the page!! NFStest 3.2, dated 21 March 2023 β€” shoutout to the version and the date for making it official. now go decode some packets, bestie, you've got this. πŸ’–πŸŽ€πŸ¦‹