networking · intermediate · ~15 min

Pack a dotted quad into a 32-bit address

Build sin_addr from octets.

Challenge

Implement unsigned ipv4_to_be32(int a, int b, int c, int d) packing the dotted quad into one 32-bit value with a in the most-significant byte (network order).

Starter code

unsigned ipv4_to_be32(int a, int b, int c, int d) {
    /* TODO */
    return 0;
}

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