]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add lua hook to get a 'raw' IP address (in binary) for rapid lookups
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Feb 2016 20:08:10 +0000 (21:08 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Feb 2016 20:08:10 +0000 (21:08 +0100)
pdns/lua-recursor4.cc

index c8e9dad3dd40add0fc88e8b3a9f8486e62eaef9e..39c61b43bbc5932dcc63aa33004431b32a7089e9 100644 (file)
@@ -216,6 +216,13 @@ RecursorLua4::RecursorLua4(const std::string& fname)
   d_lw->registerFunction<string(ComboAddress::*)()>("toString", [](const ComboAddress& ca) { return ca.toString(); });
   d_lw->registerFunction<string(ComboAddress::*)()>("toStringWithPort", [](const ComboAddress& ca) { return ca.toStringWithPort(); });
   d_lw->registerFunction<uint16_t(ComboAddress::*)()>("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } );
+  d_lw->registerFunction<string(ComboAddress::*)()>("getRaw", [](const ComboAddress& ca) { 
+      if(ca.sin4.sin_family == AF_INET) {
+        auto t=ca.sin4.sin_addr.s_addr; return string((const char*)&t, 4); 
+      }
+      else 
+        return string((const char*)&ca.sin6.sin6_addr.s6_addr, 16);
+    } );
 
   d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); });
   typedef std::unordered_set<ComboAddress,ComboAddress::addressOnlyHash,ComboAddress::addressOnlyEqual> cas_t;