cybersecurity · beginner · ~15 min · safe pentest lab
Combine loopback and private checks for lab safety.
Decide whether an address is safe to practise against: only loopback or your own private lab network.
Implement int lab_safe(int a, int b, int c, int d) that returns 1 if the address a.b.c.d is loopback or private, else 0.
Safe when:
10.x, 192.168.x, or 172.16-31.x.a, b, c, d: the four octets of the address. The grader passes fixed values (only a and b affect the result).Returns int: 1 if the address is loopback or private, else 0.
lab_safe(127, 0, 0, 1) -> 1 (loopback)
lab_safe(192, 168, 1, 5) -> 1 (private)
lab_safe(1, 1, 1, 1) -> 0 (public)
The four octets a, b, c, d of an address.
An int: 1 if the address is loopback or private, else 0.
Loopback 127.x or private (10.x / 192.168.x / 172.16-31.x).
int lab_safe(int a, int b, int c, int d) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.