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 worksThe IPv4 header is at least 20 bytes. The first byte packs version (high nibble) and IHL (low nibble). For example, byte 0x45 means version 4 and IHL 5, so the header is 5 x 4 = 20 bytes with no options.
| Offset | Field | Example |
|---|---|---|
| 0 | Version + IHL | 0x45 |
| 8 | TTL | 64 (decremented per hop) |
| 9 | Protocol | 6 = TCP, 17 = UDP, 1 = ICMP |
| 12-15 | Source IP | 192.168.1.1 |
| 16-19 | Destination IP | 8.8.8.8 |
Common protocol values you will see constantly:
1: ICMP (ping, traceroute)6: TCP17: UDPThis task asks you to parse a simulated IPv4 packet and print every field. You will need this byte-level parsing when you implement checksums, build raw packets, and read traceroute TTL responses later in the track.
Write a C program that parses an IPv4 packet supplied on stdin as whitespace-separated hex bytes (header plus optional payload bytes).
Byte 0 packs the version in the high nibble and IHL in the low nibble. IHL counts 32-bit words, so header_len = IHL * 4 (20 bytes when there are no options). Total length is the 16-bit big-endian field at bytes 2-3. TTL is byte 8, protocol is byte 9, source IP is bytes 12-15, destination IP is bytes 16-19.
Print one key=value line each for: version, ihl, header_len, total_len, ttl, protocol, src and dst as dotted decimal, and payload_len = total_len - header_len.