Master the fundamental concepts of raw sockets through this focused micro-challenge.
UDP's 8-byte header is defined by RFC 768. For example, a DNS query from ephemeral port 49152 to 53 on 8.8.8.8 packs source port, destination port, total length, and checksum into exactly eight bytes.
The four fields:
4915253 for DNSEvery multi-byte field must be in network byte order via htons().
When computing the UDP checksum, you prepend a pseudo-header that never goes on the wire:
192.168.1.10)8.8.8.8)17)This protects against misrouted packets. Sum pseudo-header + UDP header + payload using one's-complement arithmetic.
IPPROTO_UDP: you supply UDP header and payload, kernel builds IPIPPROTO_RAW + IP_HDRINCL: you build the entire IP datagram tooThis task requires you to construct a UDP packet byte by byte and print each field in hex. Packet crafters like hping3 and Scapy build datagrams exactly this way, including the pseudo-header trick for checksums. The same field-by-field construction underlies UDP-based DNS amplification attacks where a small forged query triggers a large reflected response.
Implement a C program that constructs a raw UDP packet byte by byte.
Requirements:
Success Criteria:
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