about summary refs log tree commit diff
path: root/resolv/gethnamaddr.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-08-22 22:47:57 +0000
committerRoland McGrath <roland@gnu.org>1995-08-22 22:47:57 +0000
commit3cf595e562f955e399d80ea9d053e41d50469e6b (patch)
tree77ed930262ae9606543c580c4a3d69141c1bd561 /resolv/gethnamaddr.c
parent207eb76afba6503af9c4ab5711bfd76f9697c1ad (diff)
downloadglibc-3cf595e562f955e399d80ea9d053e41d50469e6b.tar.gz
glibc-3cf595e562f955e399d80ea9d053e41d50469e6b.tar.xz
glibc-3cf595e562f955e399d80ea9d053e41d50469e6b.zip
Tue Aug 22 16:49:12 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
	* inet/netdb.h: Moved to resolv.
	* inet/Makefile (headers): Remove netdb.h.
	* resolv/Makefile (headers): Add netdb.h.
	* resolv/gethnamaddr.c, resolv/inet_addr.c, resolv/netdb.h,
	resolv/res_send.c: Updated from BIND-4.9.3-BETA26.

	* hurd/thread-cancel.c: If SS->cancel_hook is not null, call it before
	resuming the thread.
	* hurd/hurd/signal.h (struct hurd_sigstate): New member `cancel_hook'.

	* hurd/Makefile: Removed dep on hurd/signal.h for RPC stub objects.

Mon Aug 21 16:37:09 1995  Roland McGrath  <roland@churchy.gnu.ai.mit.edu>

	* sysdeps/i386/dl-machine.h (elf_machine_rel): Grok R_386_NONE
	relocs, and do nothing.  Why the linker generates them we may
	never know. 

	* sysdeps/mach/hurd/i386/intr-msg.h: New file.
Diffstat (limited to 'resolv/gethnamaddr.c')
-rw-r--r--resolv/gethnamaddr.c82
1 files changed, 56 insertions, 26 deletions
diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c
index d3b68f7d95..87b4db1a6f 100644
--- a/resolv/gethnamaddr.c
+++ b/resolv/gethnamaddr.c
@@ -93,6 +93,7 @@ static const char AskedForGot[] =
 			  "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
 
 static char *h_addr_ptrs[MAXADDRS + 1];
+static struct hostent *gethostbyname_ipv4 __P((const char *));
 
 static struct hostent host;
 static char *host_aliases[MAXALIASES];
@@ -156,7 +157,9 @@ getanswer(answer, anslen, qname, qclass, qtype)
 	int haveanswer, had_error;
 	int toobig = 0;
 	char tbuf[MAXDNAME+1];
+	const char *tname;
 
+	tname = qname;
 	host.h_name = NULL;
 	eom = answer->buf + anslen;
 	/*
@@ -249,19 +252,36 @@ getanswer(answer, anslen, qname, qclass, qtype)
 			buflen -= n;
 			continue;
 		}
+		if (qtype == T_PTR && type == T_CNAME) {
+			n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+			if (n < 0) {
+				had_error++;
+				continue;
+			}
+			cp += n;
+			/* Get canonical name. */
+			n = strlen(tbuf) + 1;	/* for the \0 */
+			if (n > buflen) {
+				had_error++;
+				continue;
+			}
+			strcpy(bp, tbuf);
+			tname = bp;
+			bp += n;
+			buflen -= n;
+			continue;
+		}
 		if (type != qtype) {
-			/* CNAME->PTR should not cause a log message. */
-			if (!(qtype == T_PTR && type == T_CNAME))
-				syslog(LOG_NOTICE|LOG_AUTH,
+			syslog(LOG_NOTICE|LOG_AUTH,
 	       "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
-				       qname, p_class(qclass), p_type(qtype),
-				       p_type(type));
+			       qname, p_class(qclass), p_type(qtype),
+			       p_type(type));
 			cp += n;
 			continue;		/* XXX - had_error++ ? */
 		}
 		switch (type) {
 		case T_PTR:
-			if (strcasecmp(qname, bp) != 0) {
+			if (strcasecmp(tname, bp) != 0) {
 				syslog(LOG_NOTICE|LOG_AUTH,
 				       AskedForGot, qname, bp);
 				cp += n;
@@ -377,6 +397,36 @@ struct hostent *
 gethostbyname(name)
 	const char *name;
 {
+	struct hostent *hp;
+
+#if defined(AF_INET6) && defined(RES_TRY_INET6)
+	if (_res.options & RES_TRY_INET6) {
+		hp = gethostbyname2(name, AF_INET6);
+		if (hp)
+			return (hp);
+	}
+#endif
+	return (gethostbyname2(name, AF_INET));
+}
+
+struct hostent *
+gethostbyname2(name, af)
+	const char *name;
+	int af;
+{
+	switch (af) {
+	case AF_INET:
+		return (gethostbyname_ipv4(name));
+	}
+	errno = EAFNOSUPPORT;
+	h_errno = NETDB_INTERNAL;
+	return (NULL);
+}
+
+static struct hostent *
+gethostbyname_ipv4(name)
+	const char *name;
+{
 	querybuf buf;
 	register const char *cp;
 	int n;
@@ -727,23 +777,3 @@ dn_skipname(comp_dn, eom)
 	return (__dn_skipname(comp_dn, eom));
 }
 #endif /*old-style libc with yp junk in it*/
-
-#ifdef ultrix
-/* more icky libc packaging in ultrix */
-int
-local_hostname_length(hostname)
-	const char *hostname;
-{
-	int len_host, len_domain;
-
-	if (!*_res.defdname)
-		res_init();
-	len_host = strlen(hostname);
-	len_domain = strlen(_res.defdname);
-	if (len_host > len_domain &&
-	    !strcasecmp(hostname + len_host - len_domain, _res.defdname) &&
-	    hostname[len_host - len_domain - 1] == '.')
-		return (len_host - len_domain - 1);
-	return (0);
-}
-#endif