>>>>> On Sun, 28 May 2000 21:04:23 -0400
>>>>> Will Andrews <[EMAIL PROTECTED]> said:

> What would make ftp(1) think it has an IPv6 connection?

andrews> I have no idea..

It seems ftp(1) think using IPv6.

There is a bug in existing getaddrinfo().  getaddrinfo() returns IPv4
address as IPv4 mapped IPv6 address in some case.  It occures when:

        - INET6 is enabled in kernel
        - host has A RR and AAAA RR

IPv4 connection via mapped address is still IPv6 connection.  In this
case, if ftp(1) doesn't have awareness of using mapped address, your
problem will occur.  And, ftp(1) seems not aware about it.

But, it seems ftp.FreeBSD.org does't have AAAA RR.  So, I believe it
is not applicable to your case.  And, actually I dont' see this
problem here.  However, I have no idea without this case.  So, I
attach the patch to solve getaddrinfo() problem.  Please try it and I
would like to hear the result.

Index: lib/libc/net/getaddrinfo.c
diff -u lib/libc/net/getaddrinfo.c.orig lib/libc/net/getaddrinfo.c
--- lib/libc/net/getaddrinfo.c.orig     Thu Apr 20 12:31:40 2000
+++ lib/libc/net/getaddrinfo.c  Mon Apr 24 21:41:24 2000
@@ -148,6 +148,7 @@
 static int get_portmatch __P((const struct addrinfo *, const char *));
 static int get_port __P((struct addrinfo *, const char *, int));
 static const struct afd *find_afd __P((int));
+static void unmappedaddr __P((struct addrinfo *));
 
 static char *ai_errlist[] = {
        "Success",
@@ -512,6 +513,7 @@
                         */
                        GET_CANONNAME(cur->ai_next, hp->h_name);
                }
+               unmappedaddr(cur->ai_next);
 
                while (cur && cur->ai_next)
                        cur = cur->ai_next;
@@ -903,4 +905,25 @@
                        return afd;
        }
        return NULL;
+}
+
+static void
+unmappedaddr(struct addrinfo *res)
+{
+       struct sockaddr_in6 *sin6;
+       struct sockaddr_in *sin;
+       u_int32_t addr;
+       int port;
+
+       sin6 = (struct sockaddr_in6 *)res->ai_addr;
+       if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
+               sin = (struct sockaddr_in *)res->ai_addr;
+               addr = *(u_int32_t *)&sin6->sin6_addr.s6_addr[12];
+               port = sin6->sin6_port;
+               memset(res->ai_addr, 0, res->ai_addrlen);
+               sin->sin_addr.s_addr = addr;
+               sin->sin_port = port;
+               sin->sin_family = res->ai_family = AF_INET;
+               sin->sin_len = res->ai_addrlen = sizeof(struct sockaddr_in);
+       }
 }
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
[EMAIL PROTECTED]  [EMAIL PROTECTED]  [EMAIL PROTECTED]
http://www.imasy.org/~ume/

Reply via email to