networking · beginner · ~15 min
Know which ports require privilege to bind.
Tell whether binding a given port requires elevated privilege.
Implement int needs_root_to_bind(int port).
port: the port number to bind.Return 1 if port is a privileged port (1..1023), else 0.
needs_root_to_bind(80) -> 1 (privileged)
needs_root_to_bind(8080) -> 0
port: the port number to bind.
1 if port is in 1..1023 (privileged), else 0.
Binding ports below 1024 needs root or CAP_NET_BIND_SERVICE.
int needs_root_to_bind(int port) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.