Master the fundamental concepts of network stack fundamentals through this focused micro-challenge.
The IPv4 header checksum is a 16-bit field for error detection on the header only. Every router recomputes it because the TTL byte changes at each hop. For example, a packet from 192.168.1.1 to 192.168.0.199 with TTL 64 has header words like 0x4500, 0x003C, 0xC0A8, 0x0001.
cLoading…
Verification sums the header including the stored checksum. A valid header yields 0xFFFF.
Carry folding example: 0xFFFF + 0x0001 = 0x10000, fold to 0x0001.
This task requires you to implement ipv4_checksum() and verify it on a simulated header. The same one's-complement algorithm appears in TCP and UDP checksums, and NIC offload hardware recomputes it in silicon on every outgoing packet. Linux's csum_partial() and BSD's in_cksum() exist because naive 16-bit summation silently drops carry overflow without the fold step.
Write a C program that implements the IPv4 header checksum algorithm. Compute the checksum on a simulated header, then verify it.
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.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it works