networking · beginner · ~15 min

Port to network bytes

Serialise a port in network byte order.

Challenge

Implement void port_to_be(int port, unsigned char *out) writing port as two big-endian bytes into out[0] (high) and out[1] (low).

Starter code

void port_to_be(int port, unsigned char *out) {
    /* TODO */
}

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