[uClibc-cvs] uClibc/libc/inet resolv.c,1.51,1.52

Erik Andersen andersen at uclibc.org
Sat Jan 24 08:33:41 UTC 2004


Update of /var/cvs/uClibc/libc/inet
In directory nail:/tmp/cvs-serv551/libc/inet

Modified Files:
	resolv.c 
Log Message:
Imre Sunyi writes:

Hi Erik

I have corrected a bug in uClibc/libc/inet/resolv.c in function
__dns_lookup(). Have attaced a txt file with my diffs regarding to
uClibc 0.9.26.

If two nameservers are included in /etc/resolv.conf and the first one is
wrong and the secondary is correct the algorithm never
looked up the secondary one. Please review my diff and feel free to
submit the patch onto your CVS.

If reading manual page resolv.conf(5) under nameserver and how the
algorithm should work the previous dns_lookup did not fully followed
that.

Regards

Imre Sunyi



Index: resolv.c
===================================================================
RCS file: /var/cvs/uClibc/libc/inet/resolv.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- resolv.c	4 Jan 2004 09:35:20 -0000	1.51
+++ resolv.c	24 Jan 2004 08:33:39 -0000	1.52
@@ -687,7 +687,7 @@
 	ns %= nscount;
 	UNLOCK;
 
-	while (retries++ < MAX_RETRIES) {
+	while (retries < MAX_RETRIES) {
 		if (fd != -1)
 			close(fd);
 
@@ -732,7 +732,7 @@
 		len = i + j;
 
 		DPRINTF("On try %d, sending query to port %d of machine %s\n",
-				retries, NAMESERVER_PORT, dns);
+				retries+1, NAMESERVER_PORT, dns);
 
 #ifdef __UCLIBC_HAS_IPV6__
 		v6 = inet_pton(AF_INET6, dns, &sa6.sin6_addr) > 0;
@@ -741,6 +741,7 @@
 		fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 #endif
 		if (fd < 0) {
+                    retries++;
 		    continue;
 		}
 
@@ -766,6 +767,7 @@
 			goto tryall;
 		    } else
 			/* retry */
+                        retries++;
 			continue;
 		}
 
@@ -783,7 +785,7 @@
 
 			/* timed out, so retry send and receive, 
 			 * to next nameserver on queue */
-			goto again;
+			goto tryall;
 		}
 
 		i = recv(fd, packet, 512, 0);
@@ -861,14 +863,14 @@
 		/* if there are other nameservers, give them a go,
 		   otherwise return with error */
 		{
-		    int sdomains;
-
-		    BIGLOCK;
-		    sdomains=__searchdomains;
-		    BIGUNLOCK;
 		    variant = 0;
-		    if (retries >= nscount*(sdomains+1))
-			goto fail;
+                    LOCK;
+                    ns = (ns + 1) % nscount;
+                    if (ns == 0)
+                      retries++;
+
+                    UNLOCK;
+                    continue;
 		}
 
 	  again:
@@ -879,13 +881,16 @@
 		    sdomains=__searchdomains;
 		    BIGUNLOCK;
 
-		    if (variant < sdomains) {
+		    if (variant < ((sdomains - 1) && strchr(lookup, '.') == NULL)) {
 			/* next search */
 			variant++;
 		    } else {
 			/* next server, first search */
 			LOCK;
 			ns = (ns + 1) % nscount;
+                        if (ns == 0)
+                          retries++;
+
 			UNLOCK;
 			variant = 0;
 		    }




More information about the uClibc-cvs mailing list