From: bert hubert Date: Thu, 11 Feb 2016 20:08:10 +0000 (+0100) Subject: add lua hook to get a 'raw' IP address (in binary) for rapid lookups X-Git-Tag: auth-4.0.0-alpha2~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6232ff130d4c60d2b875e2b4434cf45bc0e6d47a;p=thirdparty%2Fpdns.git add lua hook to get a 'raw' IP address (in binary) for rapid lookups --- diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index c8e9dad3dd..39c61b43bb 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -216,6 +216,13 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("toString", [](const ComboAddress& ca) { return ca.toString(); }); d_lw->registerFunction("toStringWithPort", [](const ComboAddress& ca) { return ca.toStringWithPort(); }); d_lw->registerFunction("getPort", [](const ComboAddress& ca) { return ntohs(ca.sin4.sin_port); } ); + d_lw->registerFunction("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 cas_t;