diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-03 16:27:16 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-03 16:27:16 +0000 |
commit | 73fda5d362f0dd7b9550badf364330b2fd4810db (patch) | |
tree | ea08b5b15fda900711edabf0c67d24225b8a0d1a | |
parent | 98d0bbfbb0128ca7a3209b98abe450a83a7223e2 (diff) |
*.ip6.int PTR lookups. FUGLY AS FUCK. someone please help me tidy (backported from firedns)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4676 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/dns.h | 19 | ||||
-rw-r--r-- | src/dns.cpp | 46 |
2 files changed, 53 insertions, 12 deletions
diff --git a/include/dns.h b/include/dns.h index 7b96f792d..db058be9b 100644 --- a/include/dns.h +++ b/include/dns.h @@ -147,14 +147,21 @@ class Resolver : public Extensible * the object to go 'out of scope' and cause a segfault in the core if the result * arrives at a later time. * @param source The IP or hostname to resolve - * @param forward Set to true to perform a forward lookup (hostname to ip) or false - * to perform a reverse lookup (ip to hostname). Lookups on A records and PTR - * records are supported. CNAME and MX are not supported by this resolver. - * If InspIRCd is compiled with ipv6 support, lookups on AAAA records are preferred - * and supported over A records. + * @param qt The query type to perform. If you just want to perform a forward + * or reverse lookup, and you don't care wether you get ipv4 or ipv6, then use + * the constants DNS_QUERY_FORWARD and DNS_QUERY_REVERSE, which automatically + * select from 'A' record or 'AAAA' record lookups. However, if you want to resolve + * a specific record type, resolution of 'A', 'AAAA', 'PTR' and 'CNAME' records + * is supported. Use one of the QueryType enum values to initiate this type of + * lookup. Resolution of 'AAAA' ipv6 records is always supported, regardless of + * wether InspIRCd is built with ipv6 support. + * If you attempt to resolve a 'PTR' record and InspIRCd is built with ipv6 support, + * the 'PTR' record will be formatted to ipv6 specs, e.g. x.x.x.x.x....ip6.int. + * otherwise it will be formatted to ipv4 specs, e.g. x.x.x.x.in-addr.arpa. * @throw ModuleException This class may throw an instance of ModuleException, in the * event a lookup could not be allocated, or a similar hard error occurs such as - * the network being down. + * the network being down. This will also be thrown if an invalid IP address is + * passed when resolving a 'PTR' record. */ Resolver(const std::string &source, QueryType qt); /** diff --git a/src/dns.cpp b/src/dns.cpp index 3db0c2486..ae0e203cd 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -399,17 +399,52 @@ int DNS::GetCName(const char *alias) /* Start lookup of an IP address to a hostname */ int DNS::GetName(const insp_inaddr *ip) { -#ifdef IPV6 - return -1; -#else char query[29]; 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. */ + 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, + ip->s6_addr[14] & 0x0f, + (ip->s6_addr[14] & 0xf0) >> 4, + ip->s6_addr[13] & 0x0f, + (ip->s6_addr[13] & 0xf0) >> 4, + ip->s6_addr[12] & 0x0f, + (ip->s6_addr[12] & 0xf0) >> 4, + ip->s6_addr[11] & 0x0f, + (ip->s6_addr[11] & 0xf0) >> 4, + ip->s6_addr[10] & 0x0f, + (ip->s6_addr[10] & 0xf0) >> 4, + ip->s6_addr[9] & 0x0f, + (ip->s6_addr[9] & 0xf0) >> 4, + ip->s6_addr[8] & 0x0f, + (ip->s6_addr[8] & 0xf0) >> 4, + ip->s6_addr[7] & 0x0f, + (ip->s6_addr[7] & 0xf0) >> 4, + ip->s6_addr[6] & 0x0f, + (ip->s6_addr[6] & 0xf0) >> 4, + ip->s6_addr[5] & 0x0f, + (ip->s6_addr[5] & 0xf0) >> 4, + ip->s6_addr[4] & 0x0f, + (ip->s6_addr[4] & 0xf0) >> 4, + ip->s6_addr[3] & 0x0f, + (ip->s6_addr[3] & 0xf0) >> 4, + ip->s6_addr[2] & 0x0f, + (ip->s6_addr[2] & 0xf0) >> 4, + ip->s6_addr[1] & 0x0f, + (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; @@ -420,7 +455,6 @@ int DNS::GetName(const insp_inaddr *ip) return -1; return id; -#endif } /* Return the next id which is ready, and the result attached to it */ @@ -718,10 +752,10 @@ Resolver::Resolver(const std::string &source, QueryType qt) : input(source), que break; case DNS_QUERY_PTR: - if (insp_aton(source.c_str(), &binip) > 0) + if (insp_aton(source.c_str(), &binip) > 0) { /* Valid ip address */ - this->myid = ServerInstance->Res->GetName(&binip); + this->myid = ServerInstance->Res->GetName(&binip); } else { |