networking · beginner · ~15 min

Port from network bytes

Reassemble a 16-bit big-endian port.

Challenge

A port is stored big-endian in sockaddr. Implement int port_from_be(unsigned char hi, unsigned char lo) returning the port value (hi << 8 | lo).

Starter code

int port_from_be(unsigned char hi, unsigned char lo) {
    /* TODO */
    return 0;
}

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