networking · intermediate · ~15 min
Bitmask arithmetic on IPv4 addresses.
Implement uint32_t network_address(uint32_t ip, int prefix_len) returning the network base by zeroing the host bits. ip is in host byte order; prefix_len is 0..32.
#include <stdint.h>
uint32_t network_address(uint32_t ip, int prefix_len) { /* TODO */ return 0; }
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.