2018-04-01 23:31:41 +07:00
|
|
|
#pragma once
|
2018-04-15 01:16:56 +07:00
|
|
|
#include <stdint.h>
|
|
|
|
// note - some platforms are confused over these #defines. Specifically, BYTE_ORDER without __ is a false prophet and may lie!
|
2018-04-01 23:31:41 +07:00
|
|
|
struct dnsheader {
|
|
|
|
unsigned id :16; /* query identification number */
|
2018-04-13 20:23:00 +07:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2018-04-01 23:31:41 +07:00
|
|
|
/* fields in third byte */
|
|
|
|
unsigned qr: 1; /* response flag */
|
|
|
|
unsigned opcode: 4; /* purpose of message */
|
|
|
|
unsigned aa: 1; /* authoritative answer */
|
|
|
|
unsigned tc: 1; /* truncated message */
|
|
|
|
unsigned rd: 1; /* recursion desired */
|
|
|
|
/* fields in fourth byte */
|
|
|
|
unsigned ra: 1; /* recursion available */
|
|
|
|
unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
|
|
|
|
unsigned ad: 1; /* authentic data from named */
|
|
|
|
unsigned cd: 1; /* checking disabled by resolver */
|
|
|
|
unsigned rcode :4; /* response code */
|
2018-04-13 20:23:00 +07:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2018-04-01 23:31:41 +07:00
|
|
|
/* fields in third byte */
|
|
|
|
unsigned rd :1; /* recursion desired */
|
|
|
|
unsigned tc :1; /* truncated message */
|
|
|
|
unsigned aa :1; /* authoritative answer */
|
|
|
|
unsigned opcode :4; /* purpose of message */
|
|
|
|
unsigned qr :1; /* response flag */
|
|
|
|
/* fields in fourth byte */
|
|
|
|
unsigned rcode :4; /* response code */
|
|
|
|
unsigned cd: 1; /* checking disabled by resolver */
|
|
|
|
unsigned ad: 1; /* authentic data from named */
|
|
|
|
unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
|
|
|
|
unsigned ra :1; /* recursion available */
|
|
|
|
#endif
|
|
|
|
/* remaining bytes */
|
2018-04-15 01:16:56 +07:00
|
|
|
uint16_t qdcount; /* number of question entries */
|
|
|
|
uint16_t ancount; /* number of answer entries */
|
|
|
|
uint16_t nscount; /* number of authority entries */
|
|
|
|
uint16_t arcount; /* number of resource entries */
|
2018-04-01 23:31:41 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(dnsheader) == 12, "dnsheader size must be 12");
|