networking · intermediate · ~15 min

DNS question count

Read a big-endian field at a fixed offset.

Challenge

A DNS message header is 12 bytes; the question count QDCOUNT is the big-endian 16-bit value at offset 4. Implement int dns_qdcount(const unsigned char *hdr) returning it.

Starter code

int dns_qdcount(const unsigned char *hdr) {
    /* TODO */
    return 0;
}

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