]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
also extract the qclass from a dnspacket
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 19 Feb 2015 15:16:54 +0000 (16:16 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 19 Feb 2015 15:16:54 +0000 (16:16 +0100)
pdns/dnsname.cc
pdns/dnsname.hh
pdns/test-dnsname_cc.cc

index e1afb12b25fdf8c10509a71f2ecd8c8ce0a79304..36faa8a3f29fbba42549b3b7251b86e4b6c0a98e 100644 (file)
@@ -12,7 +12,7 @@ DNSName::DNSName(const char* p)
       throw std::range_error("label too long");
 }
 
-DNSName::DNSName(const char* pos, int len, uint16_t* qtype)
+DNSName::DNSName(const char* pos, int len, uint16_t* qtype, uint16_t* qclass)
 {
   unsigned char labellen;
   const char* end = pos + len;
@@ -23,6 +23,10 @@ DNSName::DNSName(const char* pos, int len, uint16_t* qtype)
   if(qtype && pos + labellen + 2 <= end)  
     *qtype=(*(const unsigned char*)pos)*256 + *((const unsigned char*)pos+1);
 
+  pos+=2;
+  if(qclass && pos + labellen + 2 <= end)  
+    *qclass=(*(const unsigned char*)pos)*256 + *((const unsigned char*)pos+1);
+
 }
 
 std::string DNSName::toString() const
index c478ce9849b421eb18b2fb589e7b834c8414a498..f043364635a8cb5c84fe89bd2f53865e54a4735a 100644 (file)
@@ -24,7 +24,7 @@ public:
   DNSName() {}                 //!< Constructs the root name
   DNSName(const char* p);      //!< Constructs from a human formatted, escaped presentation
   DNSName(const std::string& str) : DNSName(str.c_str()) {}   //!< Constructs from a human formatted, escaped presentation
-  DNSName(const char* p, int len, uint16_t* qtype); //!< Construct from a DNS Packet, taking the first question
+  DNSName(const char* p, int len, uint16_t* qtype=0, uint16_t* qclass=0); //!< Construct from a DNS Packet, taking the first question
   
   bool isPartOf(const DNSName& rhs) const;   //!< Are we part of the rhs name?
   bool operator==(const DNSName& rhs) const; //!< DNS-native comparison (case insensitive)
index 947d6075ec35ae53e791440b568d2b7836437a2f..b1212f77bf8452e19e564f47bbedb6a7ed0b82a1 100644 (file)
@@ -127,10 +127,11 @@ BOOST_AUTO_TEST_CASE(test_packetParse) {
   vector<unsigned char> packet;
   DNSPacketWriter dpw(packet, "www.ds9a.nl.", QType::AAAA);
 
-  uint16_t qtype;
-  DNSName dn((char*)&packet[12], packet.size() - 12, &qtype);
+  uint16_t qtype, qclass;
+  DNSName dn((char*)&packet[12], packet.size() - 12, &qtype, &qclass);
   BOOST_CHECK_EQUAL(dn.toString(), "www.ds9a.nl.");
   BOOST_CHECK_EQUAL(qtype, QType::AAAA);
+  BOOST_CHECK_EQUAL(qclass, 1);
 }
 
 BOOST_AUTO_TEST_CASE(test_suffixmatch) {