#include <arpa/inet.h>
#include "dns.h"
#include "helperfuncs.h"
+#include "socketengine.h"
-extern int statsAccept,statsRefused,statsUnknown,statsCollisions,statsDns,statsDnsGood,statsDnsBad,statsConnects,statsSent,statsRecv;
+extern SocketEngine* SE;
+extern ServerConfig* Config;
+serverstats* stats;
#define max(a,b) (a > b ? a : b)
#define DNS_MAX 8 /* max number of nameservers used */
DNS::~DNS()
{
- log(DEBUG,"Delete DNS fd=%d",this->myfd);
}
bool DNS::ReverseLookup(std::string ip)
{
- statsDns++;
+ stats->statsDns++;
binip = dns_aton4(ip.c_str());
if (binip == NULL) {
return false;
return false;
}
log(DEBUG,"DNS: ReverseLookup, fd=%d",this->myfd);
+#ifndef THREADED_DNS
+ SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+#endif
return true;
}
bool DNS::ForwardLookup(std::string host)
{
- statsDns++;
+ stats->statsDns++;
this->myfd = dns_getip4(host.c_str());
if (this->myfd == -1)
{
return false;
}
log(DEBUG,"DNS: ForwardLookup, fd=%d",this->myfd);
+#ifndef THREADED_DNS
+ SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+#endif
return true;
}
+bool DNS::HasResult(int fd)
+{
+ return (fd == this->myfd);
+}
+
+/* Only the multithreaded dns uses this poll() based
+ * check now. As its in another thread we dont have
+ * to worry about its performance that much.
+ */
bool DNS::HasResult()
{
log(DEBUG,"DNS: HasResult, fd=%d",this->myfd);
{
log(DEBUG,"DNS: GetResult()");
result = dns_getresult(this->myfd);
+#ifndef THREADED_DNS
+ SE->DelFd(this->myfd);
+#endif
if (result) {
- statsDnsGood++;
+ stats->statsDnsGood++;
dns_close(this->myfd);
return result;
} else {
- statsDnsBad++;
+ stats->statsDnsBad++;
if (this->myfd != -1)
{
dns_close(this->myfd);
result = dns_getresult(this->myfd);
if (this->myfd != -1)
{
+#ifndef THREADED_DNS
+ SE->DelFd(this->myfd);
+#endif
dns_close(this->myfd);
}
if (result)
{
- statsDnsGood++;
+ stats->statsDnsGood++;
unsigned char a = (unsigned)result[0];
unsigned char b = (unsigned)result[1];
unsigned char c = (unsigned)result[2];
}
else
{
- statsDnsBad++;
+ stats->statsDnsBad++;
log(DEBUG,"DANGER WILL ROBINSON! NXDOMAIN for forward lookup, but we got a reverse lookup!");
return "";
}