summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-09 23:43:32 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-09 23:43:32 +0000
commit1c6241ecd36b1f5492c71569492f54c22a8cb96b (patch)
tree434c4fb9ad964906652559ac3ada0631c35501f2 /src
parent8399a0bede79afd8f8a7cb23a4ded974584d437a (diff)
Hit dns with spork. Repeat until crispy.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1349 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/dns.cpp82
-rw-r--r--src/dnsqueue.cpp6
-rw-r--r--src/inspircd.cpp3
3 files changed, 26 insertions, 65 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index bf6c16396..73566cf89 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -29,6 +29,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include "dns.h"
extern int statsAccept,statsRefused,statsUnknown,statsCollisions,statsDns,statsDnsGood,statsDnsBad,statsConnects,statsSent,statsRecv;
@@ -202,16 +206,16 @@ static int dns_send_requests(const s_header *h, const s_connection *s, const int
dns_empty_header(payload,h,l);
- for (i = 0; i < i4; i++) {
- /* otherwise send via standard ipv4 boringness */
- memset(&addr4,0,sizeof(addr4));
- memcpy(&addr4.sin_addr,&servers4[i],sizeof(addr4.sin_addr));
- addr4.sin_family = AF_INET;
- addr4.sin_port = htons(DNS_PORT);
- if (sendto(s->fd, payload, l + 12, 0, (sockaddr *) &addr4, sizeof(addr4)) == -1)
- {
- return -1;
- }
+ i = 0;
+
+ /* otherwise send via standard ipv4 boringness */
+ memset(&addr4,0,sizeof(addr4));
+ memcpy(&addr4.sin_addr,&servers4[i],sizeof(addr4.sin_addr));
+ addr4.sin_family = AF_INET;
+ addr4.sin_port = htons(DNS_PORT);
+ if (sendto(s->fd, payload, l + 12, 0, (sockaddr *) &addr4, sizeof(addr4)) == -1)
+ {
+ return -1;
}
return 0;
@@ -307,7 +311,7 @@ static int dns_build_query_payload(const char * const name, const unsigned short
}
in_addr* DNS::dns_aton4(const char * const ipstring) { /* ascii to numeric: convert string to static 4part IP addr struct */
- in_addr ip;
+ static in_addr ip;
return dns_aton4_s(ipstring,&ip);
}
@@ -322,53 +326,8 @@ in_addr* DNS::dns_aton4_r(const char *ipstring) { /* ascii to numeric (reentrant
}
in_addr* DNS::dns_aton4_s(const char *ipstring, in_addr *ip) { /* ascii to numeric (buffered): convert string to given 4part IP addr struct */
- unsigned char *myip;
- int i,part = 0;
- myip = (unsigned char *)ip;
-
- memset(myip,'\0',4);
- for (i = 0; i < 16; i++) {
- switch (ipstring[i]) {
- case '\0':
- if (part != 3)
- return NULL;
- return ip;
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (myip[part] > 25)
- return NULL;
- myip[part] *= 10;
- if (myip[part] == 250 && ipstring[i] - '0' > 6)
- return NULL;
- myip[part] += ipstring[i] - '0';
- break;
- case '.':
- if (part == 3)
- return ip;
- else
- part++;
- break;
- default:
- if (part == 3)
- return ip;
- else
- return NULL;
- break;
- }
- }
- if (part == 3)
- return ip;
- else
- return NULL;
+ inet_aton(ipstring,ip);
+ return ip;
}
int DNS::dns_getip4(const char *name) { /* build, add and send A query; retrieve result with dns_getresult() */
@@ -423,8 +382,6 @@ int DNS::dns_getname4(const in_addr *ip) { /* build, add and send PTR query; ret
unsigned char *c;
int l;
- dns_init();
-
c = (unsigned char *)&ip->s_addr;
sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]);
@@ -696,9 +653,12 @@ bool DNS::ReverseLookup(std::string ip)
if (binip == NULL) {
return false;
}
+
this->fd = dns_getname4(binip);
if (this->fd == -1)
+ {
return false;
+ }
return true;
}
@@ -722,7 +682,7 @@ int DNS::GetFD()
std::string DNS::GetResult()
{
- result = dns_getresult(this->fd);
+ result = dns_getresult(this->fd);
if (result) {
statsDnsGood++;
dns_close(this->fd);
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp
index 1e1aa33c8..aca0b07a9 100644
--- a/src/dnsqueue.cpp
+++ b/src/dnsqueue.cpp
@@ -193,8 +193,8 @@ public:
if (usr)
{
log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
- resolver.SetNS(DNSServer);
- if (!resolver.ReverseLookup(usr->host))
+ resolver.SetNS(std::string(DNSServer));
+ if (!resolver.ReverseLookup(std::string(usr->host)))
return false;
strlcpy(u,nick.c_str(),NICKMAX);
return true;
@@ -210,6 +210,7 @@ public:
if (resolver.GetFD() != 0)
{
std::string hostname = resolver.GetResult();
+ log(DEBUG,"RESULT! %s",hostname.c_str());
usr = Find(u);
if (usr)
{
@@ -307,4 +308,3 @@ void dns_poll()
max_fd_alloc = p;
}
-
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 79b34247c..f82be162e 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -4294,6 +4294,7 @@ int InspIRCd(char** argv, int argc)
endingiter = count2;
count2 = xcount; // roll back to where we were
#else
+ dns_poll();
// KQUEUE: We don't go through a loop to fill the fd_set so instead we must manually do this loop every now and again.
// TODO: We dont need to do all this EVERY loop iteration, tone down the visits to this if we're using kqueue.
while (count2 != clientlist.end())
@@ -4314,7 +4315,7 @@ int InspIRCd(char** argv, int argc)
}
if ((TIME > curr->signon) && (curr->registered == 3) && (AllModulesReportReady(curr)))
{
- log(DEBUG,"signon exceed, registered=3, and modules ready, OK");
+ log(DEBUG,"signon exceed, registered=3, and modules ready, OK: %d %d",TIME,curr->signon);
curr->dns_done = true;
statsDnsBad++;
FullConnectUser(curr);