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:
parent
eec1d3869d
commit
8ab79420ba
@ -62,22 +62,13 @@
|
|||||||
|
|
||||||
/* DNS request or response header structure */
|
/* DNS request or response header structure */
|
||||||
struct dns_header {
|
struct dns_header {
|
||||||
unsigned short id:16; /* identifier */
|
uint16_t id;
|
||||||
unsigned char rd :1; /* recursion desired 0: no, 1: yes */
|
uint16_t flags;
|
||||||
unsigned char tc :1; /* truncation 0:no, 1: yes */
|
uint16_t qdcount;
|
||||||
unsigned char aa :1; /* authoritative answer 0: no, 1: yes */
|
uint16_t ancount;
|
||||||
unsigned char opcode :4; /* operation code */
|
uint16_t nscount;
|
||||||
unsigned char qr :1; /* query/response 0: query, 1: response */
|
uint16_t arcount;
|
||||||
unsigned char rcode :4; /* response code */
|
} __attribute__ ((packed));
|
||||||
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 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* short structure to describe a DNS question */
|
/* short structure to describe a DNS question */
|
||||||
struct dns_question {
|
struct dns_question {
|
||||||
|
@ -988,14 +988,7 @@ int dns_build_query(int query_id, int query_type, char *hostname_dn, int hostnam
|
|||||||
/* set dns query headers */
|
/* set dns query headers */
|
||||||
dns = (struct dns_header *)ptr;
|
dns = (struct dns_header *)ptr;
|
||||||
dns->id = (unsigned short) htons(query_id);
|
dns->id = (unsigned short) htons(query_id);
|
||||||
dns->qr = 0; /* query */
|
dns->flags = htons(0x0100); /* qr=0, opcode=0, aa=0, tc=0, rd=1, ra=0, z=0, rcode=0 */
|
||||||
dns->opcode = 0;
|
|
||||||
dns->aa = 0;
|
|
||||||
dns->tc = 0;
|
|
||||||
dns->rd = 1; /* recursion desired */
|
|
||||||
dns->ra = 0;
|
|
||||||
dns->z = 0;
|
|
||||||
dns->rcode = 0;
|
|
||||||
dns->qdcount = htons(1); /* 1 question */
|
dns->qdcount = htons(1); /* 1 question */
|
||||||
dns->ancount = 0;
|
dns->ancount = 0;
|
||||||
dns->nscount = 0;
|
dns->nscount = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user