]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
Same tweak, again
[user/henk/code/inspircd.git] / src / dns.cpp
index 4cf913f3e63032766ee86e45b2d31bdbefac83f8..49cfa3f1fbc3b380b83cef6b8fcc4654858a3a58 100644 (file)
@@ -21,18 +21,22 @@ Please do not assume that firedns works like this,
 looks like this, walks like this or tastes like this.
 */
 
+#ifndef WIN32
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <errno.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#else
+#include "inspircd_win32wrapper.h"
+#endif
+
 #include "dns.h"
 #include "inspircd.h"
 #include "socketengine.h"
 #include "configreader.h"
 #include "socket.h"
 
-using irc::sockets::insp_sockaddr;
 using irc::sockets::insp_inaddr;
 using irc::sockets::insp_ntoa;
 using irc::sockets::insp_aton;
@@ -239,7 +243,7 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
        memcpy(&addr.sin_addr.s_addr, &dnsobj->myserver4, sizeof(addr.sin_addr));
        addr.sin_family = AF_INET;
        addr.sin_port = htons(DNS::QUERY_PORT);
-       if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12)
+       if (sendto(dnsobj->GetFd(), (const char*)payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12)
                return -1;
 #endif
 
@@ -541,7 +545,6 @@ int DNS::GetName(const insp_inaddr *ip)
 /** Start lookup of an IP address to a hostname */
 int DNS::GetNameForce(const char *ip, ForceProtocol fp)
 {
-       ServerInstance->Log(DEBUG,"GetNameForce: %s", ip);
        char query[128];
        DNSHeader h;
        int id;
@@ -552,7 +555,6 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp)
                in6_addr i;
                if (inet_pton(AF_INET6, ip, &i) > 0)
                {
-                       ServerInstance->Log(DEBUG,"Resolve to ipv6");
                        DNS::MakeIP6Int(query, &i);
                }
                else
@@ -565,7 +567,6 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp)
                in_addr i;
                if (inet_aton(ip, &i))
                {
-                       ServerInstance->Log(DEBUG,"Resolve to ipv4");
                        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]);
                }
@@ -620,13 +621,10 @@ DNSResult DNS::GetResult()
 #else
        socklen_t x = sizeof(sockaddr_in);
 #endif
-       char nbuf[MAXBUF];
        const char* ipaddr_from;
        unsigned short int port_from = 0;
 
-       int length = recvfrom(this->GetFd(),buffer,sizeof(DNSHeader),0,from,&x);
-
-       ServerInstance->Log(DEBUG,"Recv %d.", length);
+       int length = recvfrom(this->GetFd(),(char*)buffer,sizeof(DNSHeader),0,from,&x);
 
        /* Did we get the whole header? */
        if (length < 12)
@@ -646,6 +644,7 @@ DNSResult DNS::GetResult()
         * -- Thanks jilles for pointing this one out.
         */
 #ifdef IPV6
+       char nbuf[MAXBUF];
        if (this->socketfamily == AF_INET6)
        {
                ipaddr_from = inet_ntop(AF_INET6, &((sockaddr_in6*)from)->sin6_addr, nbuf, sizeof(nbuf));
@@ -670,7 +669,6 @@ DNSResult DNS::GetResult()
        {
                if ((port_from != DNS::QUERY_PORT) || (strcasecmp(ipaddr_from, ServerInstance->Config->DNSServer)))
                {
-                       ServerInstance->Log(DEBUG,"Doesnt match security: port_from=%d ipaddr_from=%s",port_from,ipaddr_from);
                        return DNSResult(-1,"",0,"");
                }
        }
@@ -1060,7 +1058,6 @@ Module* Resolver::GetCreator()
 /** Process a socket read event */
 void DNS::HandleEvent(EventType et, int errornum)
 {
-       ServerInstance->Log(DEBUG,"Marshall dns reads");
        /* Fetch the id and result of the next available packet */
        DNSResult res = this->GetResult();
        /* Is there a usable request id? */
@@ -1154,13 +1151,22 @@ void DNS::CleanResolvers(Module* module)
 /** Generate pseudo-random number */
 unsigned long DNS::PRNG()
 {
+#ifndef WIN32
        unsigned long val = 0;
        timeval n;
        serverstats* s = ServerInstance->stats;
        gettimeofday(&n,NULL);
        val = (n.tv_usec ^ getpid() ^ geteuid() ^ (this->currid++)) ^ s->statsAccept + n.tv_sec;
        val = val + s->statsCollisions ^ s->statsDnsGood - s->statsDnsBad;
-       val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv) - s->BoundPortCount;
+       val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv) - ServerInstance->Config->ports.size();
        return val;
+#else
+       unsigned long val = 0;
+       serverstats* s = ServerInstance->stats;
+       val = (time(NULL) ^ GetCurrentProcessId() ^ GetCurrentThreadId() ^ (this->currid++)) ^ s->statsAccept + time(NULL);
+       val = val + s->statsCollisions ^ s->statsDnsGood - s->statsDnsBad;
+       val += (s->statsConnects ^ (unsigned long)s->statsSent ^ (unsigned long)s->statsRecv);
+       return val;
+#endif
 }