- return "";
- }
-}
-
-std::string DNS::GetResultIP()
-{
- char r[1024];
- log(DEBUG,"DNS: GetResultIP()");
- result = dns_getresult(this->myfd);
- if (this->myfd != -1)
- {
- dns_close(this->myfd);
- this->myfd = -1;
- }
- if (result)
- {
- if (ServerInstance && ServerInstance->stats)
- 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
- {
- if (ServerInstance && ServerInstance->stats)
- ServerInstance->stats->statsDnsBad++;
- log(DEBUG,"DANGER WILL ROBINSON! NXDOMAIN for forward lookup, but we got a reverse lookup!");
- return "";
- }
-}
-
-
-
-#ifdef THREADED_DNS
-
-/* This function is a thread function which can be thought of as a lightweight process
- * to all you non-threaded people. In actuality its so much more, and pretty damn cool.
- * With threaded dns enabled, each user which connects gets a thread attached to their
- * user record when their DNS lookup starts. This function starts in parallel, and
- * commences a blocking dns lookup. Because its a seperate thread, this occurs without
- * actually blocking the main application. Once the dns lookup is completed, the thread
- * checks if the user is still around by checking their fd against the reference table,
- * and if they are, writes the hostname into the struct and terminates, after setting
- * userrec::dns_done to true. Because this is multi-threaded it can make proper use of
- * SMP setups (like the one i have here *grin*).
- * This is in comparison to the non-threaded dns, which must monitor the thread sockets
- * in a nonblocking fashion, consuming more resources to do so.
- *
- * NB: Yes this does scale, thank you. Even with large numbers of connecting clients
- * in any one timeframe, they wont all connect *at the same time* therefore any argument
- * of "but there will be thousands of threads it'll blow up" is moot, ive tested this and
- * there will only ever be somewhere around the listen backlog in number of pending
- * lookups at any one time. This is significant on any modern SMP system.
- */
-void* dns_task(void* arg)
-{
- userrec* u = (userrec*)arg;
- int thisfd = u->fd;
-
- log(DEBUG,"DNS thread for user %s",u->nick);
- DNS dns1(Config->DNSServer);
- DNS dns2(Config->DNSServer);
- std::string host;
- std::string ip;
- int iterations = 0;
-
- if (dns1.ReverseLookup(inet_ntoa(u->ip4),false))
- {
- /* FIX: Dont make these infinite! */
- while ((!dns1.HasResult()) && (++iterations < 20))
- usleep(100);
-
- if (iterations < 20)