From 671d0dad5ce04fd243e8e3bda49f7e6be0ac1f94 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 23 Feb 2001 01:08:27 +0000 Subject: 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 --- libc/inet/resolv.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'libc/inet') diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index 900783fbf..30e555db0 100644 --- a/libc/inet/resolv.c +++ b/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] = ∈ 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); -- cgit v1.2.3