Master the fundamental concepts of network stack fundamentals through this focused micro-challenge.
The 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 a simulated IPv4 packet byte array. Print the version, IHL, total length, TTL, protocol, and source/destination IP addresses.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github