cybersecurity · beginner · ~15 min · safe pentest lab
Restrict a scanner to loopback.
Restrict a scanner to loopback so it can never accidentally touch someone else's host.
Implement int scan_allowed(const char *host) that returns 1 only for the three loopback spellings, else 0.
Allowed hosts: "127.0.0.1", "localhost", "::1".
host: a NUL-terminated host string the grader passes.Returns int: 1 if host is exactly one of the loopback spellings, else 0.
scan_allowed("127.0.0.1") -> 1
scan_allowed("localhost") -> 1
scan_allowed("::1") -> 1
scan_allowed("scanme.example") -> 0
A NUL-terminated host string host.
An int: 1 for a loopback host, else 0.
Allow only 127.0.0.1, localhost, ::1 (exact match).
#include <string.h>
int scan_allowed(const char *host) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.