SO_REUSEADDR should not also mean SO_REUSEPORT

Arne Juul Arne.Juul at europe.yahoo-inc.com
Thu Feb 16 13:43:52 PST 2006


Description by Håvard Pettersen 
(Havard.Pettersen at europe.yahoo-inc.com) 	> Ticket Opened: 2006-02-02 
13:37 PST
 >
 > In the FreeBSD Java port, setting the reuse_address feature on a
 > server socket also sets the reuse_port feature, which is not a good
 > thing, since it allows multiple server sockets to bind to the same
 > local port.
 >
 > A possible work-around is to also disable reuse_address, but this
 > will disallow listening to an unused local port if a connection
 > established against that port is still active, which is not good
 > either.


I don't know why this code was put into the bsd jdk patches, it just
seems plain wrong to me.  It makes java subtly non-portable in a very
strange manner; I suggest this code is removed.  Below is the patch
I'm currently using :-)


--- ../../j2se/src/solaris/native/java/net/net_util_md.c.orig   Thu Feb 
16 20:24:41 2006
+++ ../../j2se/src/solaris/native/java/net/net_util_md.c        Thu Feb 
16 20:23:24 2006
@@ -1019,17 +1019,20 @@
                 *bufsize = maxsockbuf;
             }
          }
      }

+#if 0
+this is just plain wrong!
      /*
       * If SO_REUSEADDR option requested, unconditionally set SO_REUSEPORT.
       */
      if (level == SOL_SOCKET && opt == SO_REUSEADDR) {
         addopt = SO_REUSEPORT;
         setsockopt(fd, level, addopt, arg, len);
      }
+#endif

      /*
       * Don't allow SO_LINGER value to be too big.
       * Current max value (240) is empiric value based on tcp_timer.h's
       * constant TCP_LINGERTIME, which was doubled.


   -  Arne H. J.



More information about the freebsd-java mailing list