From: Wouter Wijngaards Date: Tue, 3 Apr 2007 09:29:09 +0000 (+0000) Subject: use constants for bitflags. X-Git-Tag: release-0.2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=290f94369f97b65b0c6b2003b21c056274975abf;p=thirdparty%2Funbound.git use constants for bitflags. git-svn-id: file:///svn/unbound/trunk@214 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/worker.c b/daemon/worker.c index 0007e1618..431881bbf 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -102,8 +102,8 @@ replyerror(int r, struct work_query* w) ldns_buffer_clear(buf); ldns_buffer_write(buf, &w->query_id, sizeof(uint16_t)); - flags = (uint16_t)(0x8000 | r); /* QR and retcode*/ - flags |= (w->query_flags & 0x0100); /* copy RD bit */ + flags = (uint16_t)(BIT_QR | r); /* QR and retcode*/ + flags |= (w->query_flags & (BIT_RD|BIT_CD)); /* copy RD and CD bit */ ldns_buffer_write_u16(buf, flags); flags = 1; ldns_buffer_write_u16(buf, flags); diff --git a/doc/Changelog b/doc/Changelog index 72d9bfa59..e562f6c08 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -3,6 +3,7 @@ in netevent (which is there to please lint) can be correct. The type on several OSes ranges from int, int32, uint32, size_t. Detects unsigned or signed using math trick. + - constants for DNS flags. 2 April 2007: Wouter - check sizes of udp received messages, not too short. diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 17cb1907c..9d3974148 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -44,6 +44,7 @@ #include "util/storage/lookup3.h" #include "util/log.h" #include "util/netevent.h" +#include "util/net_help.h" /** determine length of a dname in buffer, no compression pointers allowed. */ size_t @@ -202,8 +203,8 @@ reply_info_answer(struct reply_info* rep, uint16_t qflags, uint16_t flags; ldns_buffer_clear(buffer); ldns_buffer_skip(buffer, 2); /* ID */ - flags = rep->flags | (qflags & 0x0100); /* copy RD bit */ - log_assert(flags & 0x8000); /* QR bit must be on in our replies */ + flags = rep->flags | (qflags & BIT_RD); /* copy RD bit */ + log_assert(flags & BIT_QR); /* QR bit must be on in our replies */ ldns_buffer_write_u16(buffer, flags); ldns_buffer_write(buffer, rep->reply, rep->replysize); ldns_buffer_flip(buffer); @@ -220,12 +221,12 @@ reply_info_answer_iov(struct reply_info* rep, uint16_t qid, iov[1].iov_len = sizeof(uint16_t); if(!cached) { /* original flags, copy RD bit from query. */ - qflags = rep->flags | (qflags & 0x0100); + qflags = rep->flags | (qflags & BIT_RD); } else { /* remove AA bit, copy RD and CD bits from query. */ - qflags = (rep->flags & ~0x0400) | (qflags & 0x0110); + qflags = (rep->flags & ~BIT_AA) | (qflags & (BIT_RD|BIT_CD)); } - log_assert(qflags & 0x8000); /* QR bit must be on in our replies */ + log_assert(qflags & BIT_QR); /* QR bit must be on in our replies */ qflags = htons(qflags); iov[2].iov_base = &qflags; iov[2].iov_len = sizeof(uint16_t); diff --git a/util/net_help.h b/util/net_help.h index 6ea82ba2a..f5d9c8037 100644 --- a/util/net_help.h +++ b/util/net_help.h @@ -42,6 +42,16 @@ #ifndef NET_HELP_H #define NET_HELP_H +/** DNS constants for uint16_t style flag manipulation. host byteorder. */ +/** AA flag */ +#define BIT_AA 0x0400 +/** RD flag */ +#define BIT_RD 0x0100 +/** CD flag */ +#define BIT_CD 0x0010 +/** QR flag */ +#define BIT_QR 0x8000 + /** * See if string is ip4 or ip6. * @param str: IP specification.