networking · intermediate · ~15 min

Is it a DNS response?

Test a single flag bit in a header byte.

Challenge

The QR bit (bit 7 of byte 2) is 0 for a query and 1 for a response. Implement int dns_is_response(const unsigned char *hdr) returning 1 if the QR bit is set.

Starter code

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

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