+/** Start lookup of an IP address to a hostname */
+int DNS::GetNameForce(const char *ip, ForceProtocol fp)
+{
+ char query[128];
+ DNSHeader h;
+ int id;
+ int length;
+
+ if (fp == PROTOCOL_IPV6)
+ {
+ in6_addr i;
+ if (inet_pton(AF_INET6, ip, &i) > 0)
+ {
+ DNS::MakeIP6Int(query, &i);
+ }
+ else
+ {
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce IPv6 bad format for '%s'", ip);
+ /* Invalid IP address */
+ return -1;
+ }
+ }
+ else
+ {
+ in_addr i;
+ if (inet_aton(ip, &i))
+ {
+ unsigned char* c = (unsigned char*)&i.s_addr;
+ sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]);
+ }
+ else
+ {
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce IPv4 bad format for '%s'", ip);
+ /* Invalid IP address */
+ return -1;
+ }
+ }
+
+ length = this->MakePayload(query, DNS_QUERY_PTR, 1, (unsigned char*)&h.payload);
+ if (length == -1)
+ {
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce can't query '%s' using '%s' because it's too long", ip, query);
+ return -1;
+ }
+
+ DNSRequest* req = this->AddQuery(&h, id, ip);
+
+ if (!req)
+ {
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce can't add query (resolver down?)");
+ return -1;
+ }
+
+ if (req->SendRequests(&h, length, DNS_QUERY_PTR) == -1)
+ {
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"DNS::GetNameForce can't send (firewall?)");
+ return -1;
+ }
+
+ return id;
+}
+
+/** Build an ipv6 reverse domain from an in6_addr
+ */
+void DNS::MakeIP6Int(char* query, const in6_addr *ip)
+{
+ const char* hex = "0123456789abcdef";
+ for (int index = 31; index >= 0; index--) /* for() loop steps twice per byte */
+ {
+ if (index % 2)
+ /* low nibble */
+ *query++ = hex[ip->s6_addr[index / 2] & 0x0F];
+ else
+ /* high nibble */
+ *query++ = hex[(ip->s6_addr[index / 2] & 0xF0) >> 4];
+ *query++ = '.'; /* Seperator */
+ }
+ strcpy(query,"ip6.arpa"); /* Suffix the string */
+}
+
+/** Return the next id which is ready, and the result attached to it */