cybersecurity · advanced · ~15 min · safe pentest lab
Deduplicate the source IPs in a log.
Count how many distinct client IPs appear in an access log — this sizes the scope of activity in an authorized review.
Implement int distinct_ips(const char *log) that returns the number of distinct leading IP strings. Each line begins with the client IP: the token up to the first space.
log: a NUL-terminated, newline-separated access-log string baked into the harness. Each line starts with an IP, a space, then the rest.Returns int: the count of distinct leading-IP tokens across all lines.
log: "10.0.0.1 GET /\n10.0.0.2 GET /\n10.0.0.1 GET /x\n"
distinct_ips(log) -> 2
A NUL-terminated newline-separated access-log string log; each line starts with an IP token.
An int: the count of distinct leading-IP tokens.
The IP is the token before the first space on each line. Static buffer only.
#include <string.h>
int distinct_ips(const char *log) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.