]> granicus.if.org Git - pdns/commitdiff
Portability fix for formatting IPv6 reverse names
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Sat, 8 Mar 2014 23:58:42 +0000 (00:58 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Sun, 9 Mar 2014 01:06:02 +0000 (02:06 +0100)
pdns/ws-auth.cc

index ed8ac960b13f4f6f876457c5b64afab37ce0ec5b..4eaf1012ffe67f96a85d1c1337b175ef3946b747 100644 (file)
@@ -550,17 +550,19 @@ static void makePtr(const DNSResourceRecord& rr, DNSResourceRecord* ptr) {
       ).str();
   } else if (rr.qtype.getCode() == QType::AAAA) {
     ComboAddress ca(rr.content);
-    string tmp;
-    for (int group = 0; group < 8; ++group) {
-      tmp += (boost::format("%04x") % ntohs(ca.sin6.sin6_addr.s6_addr16[group])).str();
-    }
+    char buf[3];
     ostringstream ss;
-    size_t npos = tmp.size();
-    while (npos--) {
-      ss << tmp[npos] << ".";
+    for (int octet = 0; octet < 16; ++octet) {
+      if (snprintf(buf, sizeof(buf), "%02x", ca.sin6.sin6_addr.s6_addr[octet]) != (sizeof(buf)-1)) {
+        // this should be impossible: no byte should give more than two digits in hex format
+        throw PDNSException("Formatting IPv6 address failed");
+      }
+      ss << buf[0] << '.' << buf[1] << '.';
     }
-    ss << "ip6.arpa";
-    ptr->qname = ss.str();
+    string tmp = ss.str();
+    tmp.resize(tmp.size()-1); // remove last dot
+    // reverse and append arpa domain
+    ptr->qname = string(tmp.rbegin(), tmp.rend()) + ".ip6.arpa";
   } else {
     throw ApiException("Unsupported PTR source '" + rr.qname + "' type '" + rr.qtype.getName() + "'");
   }