From 8ab79420bacc236ad364fc8c2ac48a29f821704e Mon Sep 17 00:00:00 2001 From: Nenad Merdanovic Date: Wed, 13 Jul 2016 14:03:43 +0200 Subject: [PATCH] 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 --- include/types/dns.h | 23 +++++++---------------- src/dns.c | 9 +-------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/include/types/dns.h b/include/types/dns.h index 50636fd1fa..1b240fae4c 100644 --- a/include/types/dns.h +++ b/include/types/dns.h @@ -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 { diff --git a/src/dns.c b/src/dns.c index bf5baa0c72..7f4c59ad97 100644 --- a/src/dns.c +++ b/src/dns.c @@ -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;