networking · beginner · ~15 min
Bound a port to a scan window.
Check whether a port number falls within an inclusive range.
Implement int port_in_range(int port, int lo, int hi).
port: the port number to test.lo, hi: the inclusive bounds of the range.Return 1 if lo <= port <= hi, else 0.
port_in_range(80, 1, 1024) -> 1
port_in_range(1, 1, 1024) -> 1 (inclusive lower bound)
port_in_range(2000, 1, 1024) -> 0
port: the port to test; lo and hi: the inclusive range bounds.
1 if lo <= port <= hi, else 0.
Both ends of the range are inclusive.
int port_in_range(int port, int lo, int hi) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.