From: Pieter Lexis Date: Fri, 22 May 2015 14:31:41 +0000 (+0200) Subject: Shrink QType from 8 to 2 bytes X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~77^2~4^2~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=792402a9d98db40872e05127f692f3c7c53fcd15;p=thirdparty%2Fpdns.git Shrink QType from 8 to 2 bytes This should always be 2 bytes :), additionally, add an assert that this is always 2 bytes (and stop compiling if it isn't). --- diff --git a/pdns/qtype.cc b/pdns/qtype.cc index 885e35b867..6f70be9498 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -28,6 +28,8 @@ #include "qtype.hh" #include "misc.hh" +static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!"); + vector QType::names; // XXX FIXME we need to do something with initializer order here! QType::init QType::initializer; diff --git a/pdns/qtype.hh b/pdns/qtype.hh index 5ea1ab6e67..7a170d24e6 100644 --- a/pdns/qtype.hh +++ b/pdns/qtype.hh @@ -79,9 +79,9 @@ public: static int chartocode(const char *p); //!< convert a character string to a code // more solaris fun #undef DS - enum typeenum {A=1, NS=2, CNAME=5, SOA=6, MR=9, WKS=11, PTR=12, HINFO=13, MINFO=14, MX=15, TXT=16, RP=17, AFSDB=18, SIG=24, KEY=25, AAAA=28, LOC=29, SRV=33, NAPTR=35, KX=36, + enum typeenum : uint16_t {A=1, NS=2, CNAME=5, SOA=6, MR=9, WKS=11, PTR=12, HINFO=13, MINFO=14, MX=15, TXT=16, RP=17, AFSDB=18, SIG=24, KEY=25, AAAA=28, LOC=29, SRV=33, NAPTR=35, KX=36, CERT=37, A6=38, DNAME=39, OPT=41, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46, NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51, - TLSA=52, SPF=99, EUI48=108, EUI64=109, TKEY=249, TSIG=250, IXFR=251, AXFR=252, MAILB=253, MAILA=254, ANY=255, ADDR=259, ALIAS=260, DLV=32769} types; + TLSA=52, SPF=99, EUI48=108, EUI64=109, TKEY=249, TSIG=250, IXFR=251, AXFR=252, MAILB=253, MAILA=254, ANY=255, ADDR=259, ALIAS=260, DLV=32769}; typedef pair namenum; static vector names; diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 1c58066316..2e6c22cb71 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(test_packetParse) { uint16_t qtype, qclass; DNSName dn((char*)&packet[0], packet.size(), 12, false, &qtype, &qclass); BOOST_CHECK_EQUAL(dn.toString(), "www.ds9a.nl."); - BOOST_CHECK_EQUAL(qtype, QType::AAAA); + BOOST_CHECK(qtype == QType::AAAA); BOOST_CHECK_EQUAL(qclass, 1); dpw.startRecord("ds9a.nl.", DNSRecordContent::TypeToNumber("NS")); @@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(test_packetParse) { DNSName dn2((char*)&packet[0], packet.size(), 12+13+4, true, &qtype, &qclass); BOOST_CHECK_EQUAL(dn2.toString(), "ds9a.nl."); - BOOST_CHECK_EQUAL(qtype, QType::NS); + BOOST_CHECK(qtype == QType::NS); BOOST_CHECK_EQUAL(qclass, 1); DNSName dn3((char*)&packet[0], packet.size(), 12+13+4+2 + 4 + 4 + 2, true);