> Would it be sufficient for us to just read into a byte array large
> enough to hold all reasonable IPv6 encodings, and then cast it as
> appropriate?  I have not had a chance to follow this idea through yet.

I don't think at most 240 byte larger array has bad influence to
system.  Moreover all of sokcaddr_storage in rsync are auto-variable.

Here is new patch for rsync-current which including compatible
checking. Please try it in missing sockaddr_storage system.

Some systems may not have typedef u_int{8,32}_t.
I'm not sure whether we should use u_short/u_long instead of them.

Regards,

---
Munechika SUMIKAWA @ KAME Project

Index: config.h.in
===================================================================
RCS file: /cvsroot/rsync/config.h.in,v
retrieving revision 1.64
diff -u -r1.64 config.h.in
--- config.h.in 28 Nov 2001 03:12:20 -0000      1.64
+++ config.h.in 4 Dec 2001 06:56:15 -0000
@@ -8,6 +8,7 @@
 #undef HAVE_GETTIMEOFDAY_TZ
 #undef ENABLE_IPV6
 #undef HAVE_SOCKADDR_LEN
+#undef HAVE_SOCKADDR_STORAGE
 #undef HAVE_SOCKETPAIR
 
 /* Define to turn on debugging code that may slow normal operation */
Index: configure.in
===================================================================
RCS file: /cvsroot/rsync/configure.in,v
retrieving revision 1.112
diff -u -r1.112 configure.in
--- configure.in        2 Dec 2001 22:26:09 -0000       1.112
+++ configure.in        4 Dec 2001 06:56:21 -0000
@@ -284,6 +284,14 @@
 #include <sys/socket.h>
 ])
 
+AC_MSG_CHECKING(struct sockaddr_storage)
+AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/socket.h>],
+[struct sockaddr_storage x;],
+       AC_MSG_RESULT(yes)
+       AC_DEFINE(HAVE_SOCKADDR_STORAGE),
+       AC_MSG_RESULT(no))
+
 # if we can't find strcasecmp, look in -lresolv (for Unixware at least)
 #
 AC_CHECK_FUNCS(strcasecmp)
Index: socket.c
===================================================================
RCS file: /cvsroot/rsync/socket.c,v
retrieving revision 1.45
diff -u -r1.45 socket.c
--- socket.c    27 Nov 2001 06:01:05 -0000      1.45
+++ socket.c    4 Dec 2001 06:56:21 -0000
@@ -372,8 +372,8 @@
        while (1) {
                fd_set fds;
                int fd;
-               struct sockaddr addr;
-               int in_addrlen = sizeof(addr);
+               struct sockaddr_storage addr;
+               int addrlen = sizeof(addr);
 
                /* close log file before the potentially very long select so
                   file can be trimmed by another process instead of growing
@@ -389,7 +389,7 @@
 
                if(!FD_ISSET(s, &fds)) continue;
 
-               fd = accept(s,(struct sockaddr *)&addr,&in_addrlen);
+               fd = accept(s,(struct sockaddr *)&addr,&addrlen);
 
                if (fd == -1) continue;
 
@@ -555,7 +555,7 @@
  **/
 char *client_addr(int fd)
 {
-       struct sockaddr ss;
+       struct sockaddr_storage ss;
        int     length = sizeof(ss);
        static char addr_buf[100];
        static int initialised;
@@ -564,11 +564,11 @@
 
        initialised = 1;
 
-       if (getpeername(fd, &ss, &length)) {
+       if (getpeername(fd, (struct sockaddr *)&ss, &length)) {
                exit_cleanup(RERR_SOCKETIO);
        }
 
-       getnameinfo(&ss, length,
+       getnameinfo((struct sockaddr *)&ss, length,
                addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
        return addr_buf;
 }
@@ -579,7 +579,7 @@
  **/
 char *client_name(int fd)
 {
-       struct sockaddr ss;
+       struct sockaddr_storage ss;
        int     length = sizeof(ss);
        static char name_buf[100];
        static char port_buf[100];
@@ -602,7 +602,7 @@
        }
 
 #ifdef INET6
-        if (ss.sa_family == AF_INET6 && 
+        if (ss.ss_family == AF_INET6 && 
            IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&ss)->sin6_addr)) {
                struct sockaddr_in6 sin6;
                struct sockaddr_in *sin;
@@ -646,7 +646,7 @@
 
        /* XXX sin6_flowinfo and other fields */
        for (res = res0; res; res = res->ai_next) {
-               if (res->ai_family != ss.sa_family)
+               if (res->ai_family != ss.ss_family)
                        continue;
                if (res->ai_addrlen != length)
                        continue;
Index: lib/addrinfo.h
===================================================================
RCS file: /cvsroot/rsync/lib/addrinfo.h,v
retrieving revision 1.6
diff -u -r1.6 addrinfo.h
--- lib/addrinfo.h      27 Nov 2001 03:46:03 -0000      1.6
+++ lib/addrinfo.h      4 Dec 2001 06:56:21 -0000
@@ -102,6 +102,18 @@
        struct addrinfo *ai_next;       /* next structure in linked list */
 };
 
+#ifndef HAVE_SOCKADDR_STORAGE
+struct sockaddr_storage {
+#ifdef HAVE_SOCKADDR_LEN
+       u_int8_t        ss_len;         /* address length */
+       u_int8_t        ss_family;      /* address family */
+#else
+       u_int16_t       ss_family;
+#endif
+       u_int8_t fill[126];
+};
+#endif
+
 extern void freehostent(struct hostent *);
 extern char *gai_strerror(int);
 #endif /* AI_PASSIVE */

Reply via email to