+
+std::string DNS::GetResultIP()
+{
+ char r[1024];
+ log(DEBUG,"DNS: GetResultIP()");
+ result = dns_getresult(this->myfd);
+ if (this->myfd != -1)
+ {
+ dns_close(this->myfd);
+ }
+ if (result)
+ {
+ ServerInstance->stats->statsDnsGood++;
+ unsigned char a = (unsigned)result[0];
+ unsigned char b = (unsigned)result[1];
+ unsigned char c = (unsigned)result[2];
+ unsigned char d = (unsigned)result[3];
+ snprintf(r,1024,"%u.%u.%u.%u",a,b,c,d);
+ return r;
+ }
+ else
+ {
+ ServerInstance->stats->statsDnsBad++;
+ log(DEBUG,"DANGER WILL ROBINSON! NXDOMAIN for forward lookup, but we got a reverse lookup!");
+ return "";
+ }
+}
+
+
+
+#ifdef THREADED_DNS
+void* dns_task(void* arg)
+{
+ userrec* u = (userrec*)arg;
+ log(DEBUG,"DNS thread for user %s",u->nick);
+ DNS dns1;
+ DNS dns2;
+ std::string host;
+ std::string ip;
+ if (dns1.ReverseLookup((char*)inet_ntoa(u->ip4)))
+ {
+ while (!dns1.HasResult())
+ {
+ usleep(100);
+ }
+ host = dns1.GetResult();
+ if (host != "")
+ {
+ if (dns2.ForwardLookup(host))
+ {
+ while (!dns2.HasResult())
+ {
+ usleep(100);
+ }
+ ip = dns2.GetResultIP();
+ if (ip == std::string((char*)inet_ntoa(u->ip4)))
+ {
+ if (host.length() < 160)
+ {
+ strcpy(u->host,host.c_str());
+ strcpy(u->dhost,host.c_str());
+ }
+ }
+ }
+ }
+ }
+ u->dns_done = true;
+ return NULL;
+}
+#endif