Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net - do not make query for AFs that are not suppor...



details:   https://anonhg.NetBSD.org/src/rev/0f8f8fa55871
branches:  trunk
changeset: 474660:0f8f8fa55871
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Jul 14 22:10:03 1999 +0000

description:
- do not make query for AFs that are not supported by kernel.
  i.e. do not make query for IPv6 addresses, when running on non-IPv6 kernel,
  or, do not query for IPv4 address on IPv6-only kernel :-)

  This kind of behavior is not very well documented in RFC2553.  This
  may violate the spec.

- on EAI_AGAIN, only retry 3 times (3 is a magic number).  Previous code
  made retries forever.  This solves situation where name server is wrongly
  configured and nameserver:53 returns icmp port unreach.

The only proper fix for all getaddrinfo() related twists would be to
implement getipnodebyname() and get rid of wacky get_addr().
We need to contribute bind8 development for this.

diffstat:

 lib/libc/net/getaddrinfo.c |  27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diffs (57 lines):

diff -r bab1f7b7e4fa -r 0f8f8fa55871 lib/libc/net/getaddrinfo.c
--- a/lib/libc/net/getaddrinfo.c        Wed Jul 14 22:08:52 1999 +0000
+++ b/lib/libc/net/getaddrinfo.c        Wed Jul 14 22:10:03 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getaddrinfo.c,v 1.8 1999/07/06 02:00:41 itojun Exp $   */
+/*     $NetBSD: getaddrinfo.c,v 1.9 1999/07/14 22:10:03 itojun Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -527,20 +527,34 @@
        int i, error, ekeep;
        struct addrinfo *cur;
        struct addrinfo **res;
+       int retry;
+       int s;
 
        res = res0;
        ekeep = 0;
        for (i = 0; afdl[i].a_af; i++) {
-               if (af == AF_UNSPEC || af == afdl[i].a_af) 
-                       ;
-               else
-                       continue;
+               retry = 0;
+               if (af == AF_UNSPEC) {
+                       /*
+                        * filter out AFs that are not supported by the kernel
+                        * XXX errno?
+                        */
+                       s = socket(afdl[i].a_af, SOCK_DGRAM, 0);
+                       if (s < 0)
+                               continue;
+                       close(s);
+               } else {
+                       if (af != afdl[i].a_af)
+                               continue;
+               }
                /* It is WRONG, we need getipnodebyname(). */
 again:
                error = get_addr0(hostname, afdl[i].a_af, res, pai, port0);
                switch (error) {
                case EAI_AGAIN:
-                       goto again;
+                       if (++retry < 3)
+                               goto again;
+                       /* FALL THROUGH*/
                default:
                        if (ekeep == 0)
                                ekeep = error;
@@ -612,6 +626,7 @@
                        error = EAI_AGAIN;
                        break;
                case NO_RECOVERY:
+               case NETDB_INTERNAL:
                default:
                        error = EAI_FAIL;
                        break;



Home | Main Index | Thread Index | Old Index