Hello Alexander, On 7/12/2016 2:57 PM, Nenad Merdanovic wrote: > Hello, > > On 7/12/2016 1:13 PM, Alexander Lebedev wrote: >> Hi! On Solaris10/SPARC I see this issue with 1.6.6 and 1.6.3 (before >> Vincent commit). >> Haproxy sends queries with "response" bit. >> Maybe it is again alignment issue?
Can you try the attached patch? I don't have access to a SPARC machine (or anything big-endian TBH), so can't test myself. I tested on Linux/x86 and it works correctly. Cheers, Nenad
>From b9e5371ff782c21c1b8e5867b6b87adc24f2d8ee Mon Sep 17 00:00:00 2001 From: Nenad Merdanovic <nmer...@anine.io> Date: Wed, 13 Jul 2016 02:31:36 +0200 Subject: [PATCH] BUG/MINOR dns: Fix endianess troubles once and for all --- 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 50636fd..1b240fa 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 3b3dfc5..2e4d889 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); dns->qdcount = htons(1); /* 1 question */ dns->ancount = 0; dns->nscount = 0; -- 2.8.1