networking · intermediate · ~15 min
Apply the prefix mask to compare two addresses.
Implement int cidr_contains(uint32_t net, int prefix, uint32_t ip) returning 1 if ip is inside the network net/prefix, else 0.
#include <stdint.h>
int cidr_contains(uint32_t net, int prefix, uint32_t ip) { /* TODO */ return 0; }
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.