networking · beginner · ~15 min
Interpret bind()'s 0/-1 return.
Interpret the return code of bind(), which follows the usual POSIX 0/-1 convention.
Implement int bind_succeeded(int rc).
rc: the value bind() returned.Return 1 if rc == 0 (success), else 0.
bind_succeeded(0) -> 1
bind_succeeded(-1) -> 0
rc: the return value of bind().
1 if rc == 0, else 0.
bind() returns 0 on success, -1 on error.
int bind_succeeded(int rc) {
/* TODO */
return 0;
}
Forgetting to set SO_REUSEADDR on listening socket; omitting error checks on bind() or listen(); blocking indefinitely on single connection.
Port already in use (EADDRINUSE); client disconnecting before accept(); interrupted accept calls (EINTR); multiple back-to-back incoming connections.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.