Hi, While reading through rebound, I noticed the author uses a lot of magic numbers in DNS flags field. I present OpenBSD a set of #defines that I wrote in 2002 on an OpenBSD/macppc iBook in Montreal. If I didn't write all of it then, I followed up with it in 2005 when my own DNS server came into fruition. The defines can also be gotten from here and are under a BSD license:
http://centroid.eu/cgi-bin/cvsweb/~checkout~/delphinusdns/delphinusdnsd/ddd-dns.h?rev=1.6&content-type=text/plain patch which defines magic numbers in rebound follows after my sig. I won't cry if you don't like it. Regards, -peter Index: rebound.c =================================================================== RCS file: /cvs/src/usr.sbin/rebound/rebound.c,v retrieving revision 1.98 diff -u -p -u -r1.98 rebound.c --- rebound.c 1 May 2018 15:14:43 -0000 1.98 +++ rebound.c 13 Jul 2018 13:33:28 -0000 @@ -43,6 +43,29 @@ #define MINIMUM(a,b) (((a)<(b))?(a):(b)) +/* + * flags RFC 1035, page 26 + */ + +#define DNS_REPLY 0x8000 /* if set response if not set query */ +#define DNS_NOTIFY 0x2000 /* a NOTIFY query RFC 1996 */ +#define DNS_SREQ 0x1000 /* if set a server status request (STATUS) */ +#define DNS_INV 0x800 /* if set an inverse query */ +#define DNS_AUTH 0x400 /* Authoritative Answer (AA) in replies */ +#define DNS_TRUNC 0x200 /* Truncated (TC) */ +#define DNS_RECURSE 0x100 /* if set Recursion Desired (RD) */ +#define DNS_RECAVAIL 0x80 /* if set Recursion Available (RA) */ +#define DNS_BADTIME 0x12 /* RCODE (18) BADTIME RFC 2845 p. 3 */ +#define DNS_BADKEY 0x11 /* RCODE (17) BADKEY RFC 2845 p. 3 */ +#define DNS_BADSIG 0x10 /* RCODE (16) BADSIG RFC 2845 p. 3 */ +#define DNS_BADVERS 0x10 /* RCODE (16) BADVERS RFC 2671 p. 6 */ +#define DNS_REFUSED 0x5 /* RCODE - Refused */ +#define DNS_NOTIMPL 0x4 /* RCODE - Not Implemented */ +#define DNS_NAMEERR 0x3 /* RCODE - Name Error, NXDOMAIN */ +#define DNS_SERVFAIL 0x2 /* RCODE - Server Failure */ +#define DNS_FORMATERR 0x1 /* RCODE - Format Error */ +#define DNS_NOERR 0x0 /* RCODE - No error */ + uint16_t randomid(void); union sockun { @@ -335,7 +358,7 @@ servfail(int ud, uint16_t id, struct soc memset(&pkt, 0, sizeof(pkt)); pkt.id = id; - pkt.flags = htons(1 << 15 | 0x2); + pkt.flags = htons(DNS_REPLY | DNS_SERVFAIL); sendto(ud, &pkt, sizeof(pkt), 0, fromaddr, fromlen); } @@ -645,7 +668,7 @@ preloadcache(const char *name, uint16_t req = malloc(reqlen); req->id = 0; - req->flags = htons(0x100); + req->flags = htons(DNS_RECURSE); req->qdcount = htons(1); req->ancount = 0; req->nscount = 0; @@ -662,7 +685,7 @@ preloadcache(const char *name, uint16_t resplen = reqlen + 2 + 2 + 2 + 4 + 2 + rdatalen; resp = malloc(resplen); memcpy(resp, req, reqlen); - resp->flags = htons(0x100 | 0x8000); /* response */ + resp->flags = htons(DNS_RECURSE | DNS_REPLY); /* response */ resp->ancount = htons(1); p = (char *)resp + reqlen; len = htons(sizeof(*req));