networking · intermediate · ~15 min

Does CIDR contain IP?

Apply the prefix mask to compare two addresses.

Challenge

Implement int cidr_contains(uint32_t net, int prefix, uint32_t ip) returning 1 if ip is inside the network net/prefix, else 0.

Starter code

#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.