DNS message header format

The header is exactly 12 bytes long and is exactly the same for a DNS query or DNS response. The Header Format is illustrated graphically in the following diagram:

As the preceding diagram illustrates, the DNS message header contains 13 fields—ID, QR, OPCODE, AA, TC, RD, RA, Z, RCODE, QDCOUNT, ANCOUNT, NSCOUNT, and ARCOUNT:

  • ID is any 16-bit value that is used to identify the DNS message. The client is allowed to put any 16 bits into the DNS query, and the DNS server copies those same 16 bits into the DNS response ID. This is useful to allow the client to match up which response is in reply to which query, in cases ...

Get Hands-On Network Programming with C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.