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 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 computes and verifies the IPv4 header checksum (RFC 1071 one's complement sum) on a header read from stdin as whitespace-separated hex bytes.
Step 1: take the header exactly as supplied, replace the checksum field (bytes 10-11) with 00 00, sum all 16-bit big-endian words into a 32-bit accumulator, fold carries back (while sum > 0xFFFF: sum = (sum & 0xFFFF) + (sum >> 16)), take the one's complement, and print it as computed=0xXXXX.
Step 2: re-sum the header exactly as supplied, checksum field included. A correct header folds to 0xFFFF, so the complement of that sum is 0x0000. Print verify=ok when the recomputation yields 0x0000, otherwise verify=fail.