networking · intermediate · ~15 min

Name a socket error

Map common socket errnos to names.

Challenge

Implement const char *sock_err_name(int err) returning "ECONNREFUSED", "ETIMEDOUT", or "EADDRINUSE" for those errno values, else "OTHER".

Starter code

#include <errno.h>

const char *sock_err_name(int err) {
    /* TODO */
    return "OTHER";
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.