IPv6 and FreeBSD

Julien ÉLIE julien at trigofacile.com
Fri Oct 24 20:11:55 UTC 2008


Hi Johan,

> So the type of ssa is defined at compile time, depending on
> whether INET6 is available or not.

All right, thanks!


> No, the memset earlier has no effect at all on the value of
> sizeof(ssa) here. If INET6 is available, then the third argument
> will be sizeof(ssa) = sizeof(struct sockaddr_storage) = 128
> even when an IPv4 address is used as second argument.

INN defines the following function:

#if !HAVE_SA_LEN_MACRO
# if HAVE_SOCKADDR_LEN
#  define SA_LEN(s)     ((s)->sa_len)
# else
/* Hack courtesy of the USAGI project. */
#  if HAVE_INET6
#   define SA_LEN(s) \
    ((((struct sockaddr *)(s))->sa_family == AF_INET6)          \
        ? sizeof(struct sockaddr_in6)                           \
        : ((((struct sockaddr *)(s))->sa_family == AF_INET)     \
            ? sizeof(struct sockaddr_in)                        \
            : sizeof(struct sockaddr)))
#  else
#   define SA_LEN(s) \
    ((((struct sockaddr *)(s))->sa_family == AF_INET)           \
        ? sizeof(struct sockaddr_in)                            \
        : sizeof(struct sockaddr))
#  endif
# endif /* HAVE_SOCKADDR_LEN */
#endif /* !HAVE_SA_LEN_MACRO */



I suggest this patch in order to solve the problem we have.


Index: nnrpd/nnrpd.c
===================================================================
--- nnrpd/nnrpd.c       (révision 7953)
+++ nnrpd/nnrpd.c       (copie de travail)
@@ -804,9 +804,9 @@
     struct             timeval tv;
     unsigned short     ListenPort = NNTP_PORT;
 #ifdef HAVE_INET6
-    char               ListenAddr[INET6_ADDRSTRLEN];
+    char               ListenAddr[INET6_ADDRSTRLEN] = "::0";
 #else
-    char               ListenAddr[16];
+    char               ListenAddr[16] = "0.0.0.0";
 #endif
     int                        lfd, fd;
     socklen_t          clen;
@@ -979,7 +979,7 @@
            exit(1);
        }

-       if (bind(lfd, (struct sockaddr *) &ssa, sizeof(ssa)) < 0) {
+        if (bind(lfd, (struct sockaddr *) &ssa, SA_LEN((struct sockaddr *) &ssa)) < 0) {
            fprintf(stderr, "%s: can't bind (%s)\n", argv[0], strerror(errno));
            syslog(L_FATAL, "can't bind local address (%m)");
            exit(1);

-- 
Julien ÉLIE

« César, c'est un Jules tout de même ! » (Astérix) 



More information about the inn-workers mailing list