From spatula@flag.blackened.net  Sat Oct 21 12:41:43 2000
Return-Path: <spatula@flag.blackened.net>
Received: from flag.blackened.net (flag.blackened.net [208.206.78.232])
	by hub.freebsd.org (Postfix) with ESMTP id 8693D37B479
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 21 Oct 2000 12:41:43 -0700 (PDT)
Received: by flag.blackened.net (Postfix, from userid 1008)
	id B95566790; Sat, 21 Oct 2000 12:41:39 -0700 (PDT)
Message-Id: <20001021194139.B95566790@flag.blackened.net>
Date: Sat, 21 Oct 2000 12:41:39 -0700 (PDT)
From: freebsd@spatula.net
Sender: spatula@flag.blackened.net
Reply-To: freebsd@spatula.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: gethostbyname fails for first lookup if ipv6
X-Send-Pr-Version: 3.2

>Number:         22196
>Category:       bin
>Synopsis:       if the first gethostbyname is for an ipv6 host it will fail
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ume
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 21 12:50:01 PDT 2000
>Closed-Date:    Fri Oct 27 05:35:41 PDT 2000
>Last-Modified:  Fri Oct 27 05:37:12 PDT 2000
>Originator:     Nick Johnson
>Release:        FreeBSD 4.1.1-RELEASE i386
>Organization:
Spatula Systems 
>Environment:

options inet6 in /etc/resolv.conf or RES_OPTIONS env set to "inet6"

	

>Description:

gethostbyname checks to see if _res.options & RES_USE_INET6 is nonzero,
but for the first call to gethostbyname, the resolver has not yet been
initialized, so this test always fails the first time unless the right
kind of junk is in _res.

	

>How-To-Repeat:

struct hostent *foo;
setenv("RES_OPTIONS","inet6",1);
foo = gethostbyname("spatula.none.freenet6.net");
printf("%p",foo);  /* foo will be null */
foo = gethostbyname("spatula.none.freenet6.net");
printf("%p",foo);  /* foo will have an address */

	

>Fix:

either explicitly call res_init() from the program before calling
gethostbyname, or the following patch to 
/usr/src/lib/libc/net/gethostnamadr.c also works, although it's not
pretty:

--- gethostnamadr.c.orig	Sat Oct 21 12:03:52 2000
+++ gethostnamadr.c	Sat Oct 21 12:06:49 2000
@@ -123,6 +123,10 @@
 {
 	struct hostent *hp;
 
+	if ((_res.options && RES_INIT) == 0) {
+		res_init();				/* XXX */
+	}
+
 	if (_res.options & RES_USE_INET6) {		/* XXX */
 		hp = gethostbyname2(name, AF_INET6);	/* XXX */
 		if (hp)					/* XXX */

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: dcs 
Responsible-Changed-When: Sat Oct 21 13:32:33 PDT 2000 
Responsible-Changed-Why:  
Moved from pending. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22196 
Responsible-Changed-From-To: freebsd-bugs->ume 
Responsible-Changed-By: johan 
Responsible-Changed-When: Sun Oct 22 11:13:35 PDT 2000 
Responsible-Changed-Why:  
Let our IPv6 maintainer have a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22196 
State-Changed-From-To: open->closed 
State-Changed-By: ume 
State-Changed-When: Fri Oct 27 05:35:41 PDT 2000 
State-Changed-Why:  
Thanks!  I just committed it with slightly modified. (1.16 -> 1.17) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22196 
>Unformatted:
