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;
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
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)
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) {