Master the fundamental concepts of network stack fundamentals through this focused micro-challenge.
An IPv4 address like 192.168.1.10 is just a 32-bit number displayed as four 8-bit octets. Every router, firewall rule, and socket API call works with the numeric form; the dotted string exists for humans. For example, 8.8.8.8 packs into four bytes: 08 08 08 08 in hex.
The functions inet_aton and inet_pton in every C network program do exactly what you are about to do: split the string on dots, validate each part fits in 0-255, and pack the result. Common pitfalls include:
010.0.0.1 (some parsers treat leading zeros as octal)192..1.1Get this wrong and you connect to the wrong host or accept malformed input, which has caused real CVEs in address parsers.
This task asks you to implement the first step of every network client: turn a human-readable address into four integers. You will need this same split-and-validate logic when you parse IP headers in later tasks and when you fill sockaddr_in structures by hand. The dotted string is a presentation format; the four integers are what bind(), routing tables, and firewall rules actually store.
An IPv4 address is a 32-bit number; dotted-quad notation writes its four bytes in decimal, most significant first. Parse the address and build that 32-bit value, the way it travels on the wire in network byte order.
One IPv4 address in dotted-quad form, for example 192.168.1.1. Each octet is 0-255.
Two lines:
cLoading…
The second line is (a << 24) | (b << 16) | (c << 8) | d as eight lowercase hex digits with leading zeros.
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