1
--- maradns-1.3.03/server/recursive.c 2007-02-14 07:25:28.000000000 -0800
2
+++ maradns-1.3.04/server/recursive.c 2007-02-16 13:46:29.000000000 -0800
4
printf("Bind failed, trying again\n");
7
- /* XXX read some kvars which determine the range of this
9
+ /* To add: Read mararc parameters which determine the range of this */
10
dns_udp.sin_port = htons(15000 + (srng() & 4095));
12
} while(bind(s,(struct sockaddr *)&dns_udp,sizeof(dns_udp)) < 0 &&
13
@@ -1707,8 +1706,16 @@
14
/* (End code snippet removed in rng-disabled version) */
16
/* And send, on the same socket, the message to the server */
17
- counter = sendto(s,outdata->string,outdata->unit_count,0,
18
- (struct sockaddr *)&server,len_inet);
19
+ /* Thanks to Rani Assaf for pointing out that you can actually
20
+ * connect with a UDP connection */
21
+#ifdef SELECT_PROBLEM
22
+ /* Set socket to non-blocking mode to work around select() being
23
+ unreliable in linux; packet may have been dropped.
25
+ fcntl(s, F_SETFL, O_NONBLOCK);
27
+ connect(s, (struct sockaddr *)&server, sizeof(server));
28
+ counter = send(s,outdata->string,outdata->unit_count,0);
32
@@ -1726,8 +1733,13 @@
34
tv.tv_sec = timeout_seconds;
36
+ /* Since a number of different threads will be at this point waiting
37
+ * for a reply from a remote DNS server on a heavily loaded resolver,
38
+ * we let each thread do a select() at the same time */
40
n = select(maxd,&rx_set,NULL,NULL,&tv);
41
+ /* OK, we're done waiting for the slow remote DNS server. Lock the
44
if(n == -1) /* select error */ {
46
@@ -1749,16 +1761,8 @@
50
-#ifdef SELECT_PROBLEM
51
- /* Set socket to non-blocking mode to work around select() being
52
- unreliable in linux; packet may have been dropped.
54
- fcntl(s, F_SETFL, O_NONBLOCK);
56
/* Get the actual reply from the DNS server */
57
- if((count = recvfrom(s,indata->string,indata->max_count,0,
58
- (struct sockaddr *)&dns_udp,
59
- (socklen_t *)&len_inet)) < 0) {
60
+ if((count = recv(s,indata->string,indata->max_count,0)) < 0) {