networking · beginner · ~15 min
Recognise the loopback range.
Tell whether a dotted-quad IPv4 address is a loopback address (in 127.0.0.0/8).
Implement int is_loopback(int a, int b, int c, int d) where a.b.c.d is the address.
a, b, c, d: the four octets of an IPv4 address.Return 1 if the address is in 127.0.0.0/8 (first octet is 127), else 0.
is_loopback(127, 0, 0, 1) -> 1
is_loopback(127, 5, 5, 5) -> 1 (any 127.x.x.x is loopback)
is_loopback(8, 8, 8, 8) -> 0
a, b, c, d: the four octets of an IPv4 address.
1 if the first octet is 127 (127.0.0.0/8), else 0.
The entire 127.0.0.0/8 block is loopback; only the first octet matters.
int is_loopback(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.