]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
Remove some debug
[user/henk/code/inspircd.git] / src / dns.cpp
index d22c60c00dd3f8b0d81ba3fce67a9d113182acd8..33dba1abb72a2e14f3838379bde0185a034e4690 100644 (file)
@@ -32,7 +32,6 @@ looks like this, walks like this or tastes like this.
 #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;
@@ -218,9 +217,9 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
                sockaddr_in6 addr;
                memset(&addr,0,sizeof(addr));
                memcpy(&addr.sin6_addr,&dnsobj->myserver6,sizeof(addr.sin6_addr));
-               addr.sin6_family = AF_FAMILY;
+               addr.sin6_family = AF_INET6;
                addr.sin6_port = htons(DNS::QUERY_PORT);
-               if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1)
+               if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12)
                        return -1;
        }
        else
@@ -228,18 +227,18 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
                sockaddr_in addr;
                memset(&addr,0,sizeof(addr));
                memcpy(&addr.sin_addr.s_addr,&dnsobj->myserver4,sizeof(addr.sin_addr));
-               addr.sin_family = AF_FAMILY;
+               addr.sin_family = AF_INET;
                addr.sin_port = htons(DNS::QUERY_PORT);
-               if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1)
+               if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12)
                        return -1;
        }
 #else
        sockaddr_in addr;
        memset(&addr,0,sizeof(addr));
        memcpy(&addr.sin_addr.s_addr, &dnsobj->myserver4, sizeof(addr.sin_addr));
-       addr.sin_family = AF_FAMILY;
+       addr.sin_family = AF_INET;
        addr.sin_port = htons(DNS::QUERY_PORT);
-       if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1)
+       if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) != length+12)
                return -1;
 #endif
 
@@ -308,6 +307,7 @@ int DNS::PruneCache()
 void DNS::Rehash()
 {
        ip6munge = false;
+       int portpass = 0;
 
        if (this->GetFd() > -1)
        {
@@ -339,10 +339,13 @@ void DNS::Rehash()
        if (strchr(ServerInstance->Config->DNSServer,':'))
        {
                this->socketfamily = AF_INET6;
-               inet_pton(AF_INET6, &this->myserver6, ServerInstance->Config->DNSServer);
+               inet_pton(AF_INET6, ServerInstance->Config->DNSServer, &this->myserver6);
        }
        else
+       {
                inet_aton(ServerInstance->Config->DNSServer, &this->myserver4);
+               portpass = -1;
+       }
 #else
        inet_aton(ServerInstance->Config->DNSServer, &this->myserver4);
 #endif
@@ -355,7 +358,7 @@ void DNS::Rehash()
        if (this->GetFd() != -1)
        {
                /* Bind the port - port 0 INADDR_ANY */
-               if (!ServerInstance->BindSocket(this->GetFd(), 0, "", false))
+               if (!ServerInstance->BindSocket(this->GetFd(), portpass, "", false))
                {
                        /* Failed to bind */
                        shutdown(this->GetFd(),2);
@@ -537,7 +540,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;
@@ -548,7 +550,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
@@ -561,7 +562,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]);
                }
@@ -610,17 +610,22 @@ DNSResult DNS::GetResult()
        DNSHeader header;
        DNSRequest *req;
        unsigned char buffer[sizeof(DNSHeader)];
-       sockaddr from;
-       socklen_t x = sizeof(from);
-       const char* ipaddr_from = "";
+       sockaddr* from = new sockaddr[2];
+#ifdef IPV6
+       socklen_t x = this->socketfamily == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
+#else
+       socklen_t x = sizeof(sockaddr_in);
+#endif
+       const char* ipaddr_from;
        unsigned short int port_from = 0;
 
-       int length = recvfrom(this->GetFd(),buffer,sizeof(DNSHeader),0,&from,&x);
+       int length = recvfrom(this->GetFd(),buffer,sizeof(DNSHeader),0,from,&x);
 
        /* Did we get the whole header? */
        if (length < 12)
        {
                /* Nope - something screwed up. */
+               delete[] from;
                return DNSResult(-1,"",0,"");
        }
 
@@ -634,13 +639,24 @@ DNSResult DNS::GetResult()
         * -- Thanks jilles for pointing this one out.
         */
 #ifdef IPV6
-       ipaddr_from = insp_ntoa(((sockaddr_in6*)&from)->sin6_addr);
-       port_from = ntohs(((sockaddr_in6*)&from)->sin6_port);
+       char nbuf[MAXBUF];
+       if (this->socketfamily == AF_INET6)
+       {
+               ipaddr_from = inet_ntop(AF_INET6, &((sockaddr_in6*)from)->sin6_addr, nbuf, sizeof(nbuf));
+               port_from = ntohs(((sockaddr_in6*)from)->sin6_port);
+       }
+       else
+       {
+               ipaddr_from = inet_ntoa(((sockaddr_in*)from)->sin_addr);
+               port_from = ntohs(((sockaddr_in*)from)->sin_port);
+       }
 #else
-       ipaddr_from = insp_ntoa(((sockaddr_in*)&from)->sin_addr);
-       port_from = ntohs(((sockaddr_in*)&from)->sin_port);
+       ipaddr_from = inet_ntoa(((sockaddr_in*)from)->sin_addr);
+       port_from = ntohs(((sockaddr_in*)from)->sin_port);
 #endif
 
+       delete[] from;
+
        /* We cant perform this security check if you're using 4in6.
         * Tough luck to you, choose one or't other!
         */