BUG/MINOR: Fix endiness issue in DNS header creation code

Alexander Lebedev reported that the response bit is set on SPARC when
DNS queries are sent. This has been tracked to the endianess issue, so
this patch makes the code portable.

Signed-off-by: Nenad Merdanovic <nmerdan@anine.io>
This commit is contained in:
Nenad Merdanovic 2016-07-13 14:03:43 +02:00 committed by Willy Tarreau
parent eec1d3869d
commit 8ab79420ba
2 changed files with 8 additions and 24 deletions

View File

@ -62,22 +62,13 @@
/* DNS request or response header structure */
struct dns_header {
unsigned short id:16; /* identifier */
unsigned char rd :1; /* recursion desired 0: no, 1: yes */
unsigned char tc :1; /* truncation 0:no, 1: yes */
unsigned char aa :1; /* authoritative answer 0: no, 1: yes */
unsigned char opcode :4; /* operation code */
unsigned char qr :1; /* query/response 0: query, 1: response */
unsigned char rcode :4; /* response code */
unsigned char cd :1; /* checking disabled */
unsigned char ad :1; /* authentic data */
unsigned char z :1; /* not used */
unsigned char ra :1; /* recursion available 0: no, 1: yes */
unsigned short qdcount :16; /* question count */
unsigned short ancount :16; /* answer count */
unsigned short nscount :16; /* authority count */
unsigned short arcount :16; /* additional count */
};
uint16_t id;
uint16_t flags;
uint16_t qdcount;
uint16_t ancount;
uint16_t nscount;
uint16_t arcount;
} __attribute__ ((packed));
/* short structure to describe a DNS question */
struct dns_question {

View File

@ -988,14 +988,7 @@ int dns_build_query(int query_id, int query_type, char *hostname_dn, int hostnam
/* set dns query headers */
dns = (struct dns_header *)ptr;
dns->id = (unsigned short) htons(query_id);
dns->qr = 0; /* query */
dns->opcode = 0;
dns->aa = 0;
dns->tc = 0;
dns->rd = 1; /* recursion desired */
dns->ra = 0;
dns->z = 0;
dns->rcode = 0;
dns->flags = htons(0x0100); /* qr=0, opcode=0, aa=0, tc=0, rd=1, ra=0, z=0, rcode=0 */
dns->qdcount = htons(1); /* 1 question */
dns->ancount = 0;
dns->nscount = 0;