cybersecurity · intermediate · ~15 min · safe pentest lab
Practise hard-coded scope limits as a defensive guarantee.
Implement int check_local(const char *host, int port) that:
host is not exactly the string "127.0.0.1" (refuses non-localhost).127.0.0.1:port succeeds.This is the canonical defensive shape of a local-only tool: the policy check is the first line of code.
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
int check_local(const char *host, int port) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.