networking · beginner · ~15 min
Enforce the authorized-scope rule in code.
Encode the authorized-scope rule in code: only loopback is a safe target without explicit authorization.
Implement int safe_test_target(const char *host).
host: a NUL-terminated host string.Return 1 only if host is a localhost address ("localhost", "127.0.0.1", or "::1"); any other host returns 0.
safe_test_target("127.0.0.1") -> 1
safe_test_target("8.8.8.8") -> 0
safe_test_target("victim.example") -> 0
host: a NUL-terminated host string.
1 only for a localhost address ("localhost", "127.0.0.1", "::1"); else 0.
Only loopback is in scope; refuse every other host.
#include <string.h>
int safe_test_target(const char *host) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.