Sfoglia il codice sorgente

Fix two bugs. First, gethostbyname was doing dns queries when given an IP
address. Secondly, when doing reverse dns lookups, it was appending the
domain, even if a domain was already attached.
-Erik

Eric Andersen 25 anni fa
parent
commit
671d0dad5c
1 ha cambiato i file con 16 aggiunte e 3 eliminazioni
  1. 16 3
      libc/inet/resolv.c

+ 16 - 3
libc/inet/resolv.c

@@ -497,7 +497,7 @@ int dns_lookup(const char *name, int type, int nscount, const char **nsip,
 			goto fail;
 
 		strncpy(lookup,name,MAXDNAME);
-		if (variant < searchdomains)
+		if (variant < searchdomains && strchr(lookup, '.') == NULL)
 		{
 		    strncat(lookup,".", MAXDNAME);
 		    strncat(lookup,searchdomain[variant], MAXDNAME);
@@ -851,14 +851,27 @@ struct hostent *gethostbyname(const char *name)
 
 	if (!name)
 		return 0;
-
+	
 	memset(&h, 0, sizeof(h));
 
 	addr_list[0] = &in;
 	addr_list[1] = 0;
-
+	
 	strcpy(namebuf, name);
 
+	/* First check if this is already an address */
+	if (inet_aton(name, &in)) {
+	    i = inet_aton( name, &in);
+
+	    if (i >= 0) {	
+		h.h_name = namebuf;
+		h.h_addrtype = AF_INET;
+		h.h_length = sizeof(in);
+		h.h_addr_list = (char **) addr_list;
+		return &h;
+	    }
+	}
+
 	for (;;) {
 
 		i = dns_lookup(namebuf, 1, nameservers, nameserver, &packet, &a);