diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-02-05 23:59:58 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-02-05 23:59:58 +0000 |
commit | ac36ca514e1be51d3ca7ce73bb8653ca2f08f0ce (patch) | |
tree | 3446e0b81de6af4738a48e83fa1a74d89e0c9172 | |
parent | acd24151ceaa6d01655ae39470111adae3a4fba4 (diff) |
No gaurantees on this atm
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6508 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/dns.h | 18 | ||||
-rw-r--r-- | src/dns.cpp | 46 |
2 files changed, 40 insertions, 24 deletions
diff --git a/include/dns.h b/include/dns.h index 54cdf5672..f12dbdb1e 100644 --- a/include/dns.h +++ b/include/dns.h @@ -335,15 +335,6 @@ class DNS : public EventHandler static const int MAX_REQUEST_ID = 0xFFFF; /** - * Server address being used currently - */ - int socketfamily; -#ifdef IPV6 - in6_addr myserver6; -#endif - in_addr myserver4; - - /** * A counter used to form part of the pseudo-random id */ int currid; @@ -373,6 +364,15 @@ class DNS : public EventHandler public: + /** + * Server address being used currently + */ + int socketfamily; +#ifdef IPV6 + in6_addr myserver6; +#endif + in_addr myserver4; + /** * Currently active Resolver classes */ diff --git a/src/dns.cpp b/src/dns.cpp index ea6b000a9..4cf6b1968 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -36,6 +36,7 @@ using irc::sockets::insp_sockaddr; using irc::sockets::insp_inaddr; using irc::sockets::insp_ntoa; using irc::sockets::insp_aton; +using irc::sockets::OpenTCPSocket; /** Masks to mask off the responses we get from the DNSRequest methods */ @@ -91,12 +92,11 @@ class DNSRequest unsigned char* res; /* Result processing buffer */ unsigned int rr_class; /* Request class */ QueryType type; /* Request type */ - insp_inaddr myserver; /* DNS server address*/ DNS* dnsobj; /* DNS caller (where we get our FD from) */ unsigned long ttl; /* Time to live */ std::string orig; /* Original requested name/ip */ - DNSRequest(InspIRCd* Instance, DNS* dns, insp_inaddr server, int id, const std::string &original); + DNSRequest(InspIRCd* Instance, DNS* dns, int id, const std::string &original); ~DNSRequest(); DNSInfo ResultIsReady(DNSHeader &h, int length); int SendRequests(const DNSHeader *header, const int length, QueryType qt); @@ -146,11 +146,10 @@ class RequestTimeout : public InspTimer }; /* Allocate the processing buffer */ -DNSRequest::DNSRequest(InspIRCd* Instance, DNS* dns, insp_inaddr server, int id, const std::string &original) : dnsobj(dns) +DNSRequest::DNSRequest(InspIRCd* Instance, DNS* dns, int id, const std::string &original) : dnsobj(dns) { res = new unsigned char[512]; *res = 0; - memcpy(&myserver, &server, sizeof(insp_inaddr)); orig = original; RequestTimeout* RT = new RequestTimeout(Instance->Config->dns_timeout ? Instance->Config->dns_timeout : 5, Instance, this, id); Instance->Timers->AddTimer(RT); /* The timer manager frees this */ @@ -206,7 +205,6 @@ inline void DNS::EmptyHeader(unsigned char *output, const DNSHeader *header, con /** Send requests we have previously built down the UDP socket */ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryType qt) { - insp_sockaddr addr; unsigned char payload[sizeof(DNSHeader)]; this->rr_class = 1; @@ -214,18 +212,36 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp DNS::EmptyHeader(payload,header,length); - memset(&addr,0,sizeof(addr)); #ifdef IPV6 - memcpy(&addr.sin6_addr,&myserver,sizeof(addr.sin6_addr)); - addr.sin6_family = AF_FAMILY; - addr.sin6_port = htons(DNS::QUERY_PORT); + if (this->dnsobj->socketfamily == AF_INET6) + { + 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_port = htons(DNS::QUERY_PORT); + if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1) + 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_port = htons(DNS::QUERY_PORT); + if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1) + return -1; + } #else - memcpy(&addr.sin_addr.s_addr,&myserver,sizeof(addr.sin_addr)); + 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_port = htons(DNS::QUERY_PORT); -#endif if (sendto(dnsobj->GetFd(), payload, length + 12, 0, (sockaddr *) &addr, sizeof(addr)) == -1) return -1; +#endif return 0; } @@ -244,7 +260,7 @@ DNSRequest* DNS::AddQuery(DNSHeader *header, int &id, const char* original) while (requests[id]) id = this->PRNG() & DNS::MAX_REQUEST_ID; - DNSRequest* req = new DNSRequest(ServerInstance, this, this->myserver, id, original); + DNSRequest* req = new DNSRequest(ServerInstance, this, id, original); header->id[0] = req->id[0] = id >> 8; header->id[1] = req->id[1] = id & 0xFF; @@ -326,9 +342,9 @@ void DNS::Rehash() inet_pton(AF_INET6, &this->myserver6, ServerInstance->Config->DNSServer); } else - inet_aton(&this->myserver4, ServerInstance->Config->DNSServer); + inet_aton(ServerInstance->Config->DNSServer, &this->myserver4); #else - inet_aton(&this->myserver4, ServerInstance->Config->DNSServer); + inet_aton(ServerInstance->Config->DNSServer, &this->myserver4); #endif /* Initialize mastersocket */ @@ -339,7 +355,7 @@ void DNS::Rehash() if (this->GetFd() != -1) { /* Bind the port */ - if (!BindSocket(this->GetFd(), 0, ServerInstance->Config->DNSServer, false)) + if (!ServerInstance->BindSocket(this->GetFd(), 0, ServerInstance->Config->DNSServer, false)) { /* Failed to bind */ shutdown(this->GetFd(),2); |