diff options
-rw-r--r-- | include/dns.h | 5 | ||||
-rw-r--r-- | src/dns.cpp | 40 | ||||
-rw-r--r-- | src/modules/m_testcommand.cpp | 12 |
3 files changed, 39 insertions, 18 deletions
diff --git a/include/dns.h b/include/dns.h index db058be9b..8550e5e70 100644 --- a/include/dns.h +++ b/include/dns.h @@ -318,6 +318,11 @@ class DNS : public Extensible * counter (currid) */ unsigned long PRNG(); + + /** + * Turn an in6_addr into a .ip6.int domain + */ + static void MakeIP6Int(char* query, const in6_addr *ip); }; #endif diff --git a/src/dns.cpp b/src/dns.cpp index ae0e203cd..9788284b7 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -399,13 +399,32 @@ int DNS::GetCName(const char *alias) /* Start lookup of an IP address to a hostname */ int DNS::GetName(const insp_inaddr *ip) { - char query[29]; + char query[128]; DNSHeader h; int id; int length; #ifdef IPV6 - /* XXX: This SUCKS. and i mean REALLY, REALLY sucks. Anyone who rewrites it pretty gets a cookie. */ + DNS::MakeIP6Int(query, (in6_addr*)ip); +#else + unsigned char* c = (unsigned char*)&ip->s_addr; + + sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]); +#endif + + if ((length = this->MakePayload(query, DNS_QUERY_PTR, 1, (unsigned char*)&h.payload)) == -1) + return -1; + + DNSRequest* req = this->AddQuery(&h, id); + + if ((!req) || (req->SendRequests(&h, length, DNS_QUERY_PTR) == -1)) + return -1; + + return id; +} + +void DNS::MakeIP6Int(char* query, const in6_addr *ip) +{ sprintf(query,"%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.ip6.int", ip->s6_addr[15] & 0x0f, (ip->s6_addr[15] & 0xf0) >> 4, @@ -439,22 +458,7 @@ int DNS::GetName(const insp_inaddr *ip) (ip->s6_addr[1] & 0xf0) >> 4, ip->s6_addr[0] & 0x0f, (ip->s6_addr[0] & 0xf0) >> 4 - ); -#else - unsigned char* c = (unsigned char*)&ip->s_addr; - - sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]); -#endif - - if ((length = this->MakePayload(query, DNS_QUERY_PTR, 1, (unsigned char*)&h.payload)) == -1) - return -1; - - DNSRequest* req = this->AddQuery(&h, id); - - if ((!req) || (req->SendRequests(&h, length, DNS_QUERY_PTR) == -1)) - return -1; - - return id; + ); } /* Return the next id which is ready, and the result attached to it */ diff --git a/src/modules/m_testcommand.cpp b/src/modules/m_testcommand.cpp index ebb09a19d..cca30de5d 100644 --- a/src/modules/m_testcommand.cpp +++ b/src/modules/m_testcommand.cpp @@ -33,6 +33,18 @@ class MyV6Resolver : public Resolver virtual void OnLookupComplete(const std::string &result) { log(DEBUG,"*** RESOLVER COMPLETED LOOKUP, IP IS: '%s'",result.c_str()); + + char query[128]; + in6_addr n; + if (inet_pton(AF_INET6, result.c_str(), &n) > 0) + { + DNS::MakeIP6Int(query, &n); + log(DEBUG,"Translation: %s",query); + } + else + { + log(DEBUG,"Bad IPV6 IP: %s",result.c_str()); + } } virtual void OnError(ResolverError e, const std::string &errormessage) |