Master the fundamental concepts of network stack fundamentals through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksTCP provides reliable, ordered byte streams. The minimum header is 20 bytes. For example, a SYN segment to port 443 might have source port 54321, destination port 443, sequence number 1000, and flags SYN+ACK encoded in byte 13.
80 and 49152Common flag combinations:
The data-offset nibble determines where TCP options end and payload begins. Misreading it desyncs every byte after the header. A data offset of 5 means 20 bytes with no options; 6 means 24 bytes with 4 bytes of options.
This task asks you to parse a simulated TCP segment and print ports, sequence numbers, flags, and window size. nmap's SYN scan crafts and reads exactly these fields to fingerprint open ports without completing a handshake.
Write a C program that parses a TCP segment supplied on stdin as whitespace-separated hex bytes (header plus optional payload bytes; at least the 20-byte header).
All multi-byte fields are big-endian. Source port (bytes 0-1) and destination port (bytes 2-3) are 16-bit. Sequence (bytes 4-7) and acknowledgment (bytes 8-11) are 32-bit. The data offset is the high nibble of byte 12, in 32-bit words, so header_len = data_offset * 4. Byte 13 holds the flags: FIN=0x01, SYN=0x02, RST=0x04, PSH=0x08, ACK=0x10, URG=0x20. Window is bytes 14-15.
Print one key=value line each for: src_port, dst_port, seq, ack, data_offset, header_len, window, and flags - the set flags in FIN,SYN,RST,PSH,ACK,URG order joined with + (e.g. SYN+ACK), or - when no flag is set.