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 worksUDP is connectionless with just four fields. For example, a DNS query to 8.8.8.8 uses destination port 53, source port some ephemeral value like 49152, length covering header plus query data, and an optional checksum.
cLoading…
ICMP sits directly on IP (protocol 1) with no port numbers. Instead it uses type and code:
8, code 0: Echo Request (ping)0, code 0: Echo Reply11, code 0: Time Exceeded (traceroute)Echo requests add a 16-bit identifier and 16-bit sequence number after the checksum, plus optional payload data echoed back in the reply.
This task requires you to parse simulated UDP and ICMP packets. DNS resolvers and every ping utility on Linux depend on exactly these two lightweight formats, and you will craft raw ICMP echo requests in the next subtrack.
Write a C program whose stdin starts with a word selecting the packet type (udp or icmp), followed by the packet as whitespace-separated hex bytes.
For udp: the 8-byte header (RFC 768) holds source port (bytes 0-1), destination port (bytes 2-3), length (bytes 4-5, counting header plus payload), and checksum (bytes 6-7), all 16-bit big-endian. Print src_port, dst_port, length, payload_len = length - 8, and checksum as 0x%04x.
For icmp: the first 8 bytes hold type (byte 0), code (byte 1), checksum (bytes 2-3), then the 16-bit big-endian identifier and sequence number (bytes 4-7) used by echo messages. Print type, code, kind (echo-request for type 8, echo-reply for type 0, other otherwise), id, seq, and checksum.