Question regarding NET_BindV6() and the "double bind"

Alan Bateman Alan.Bateman at oracle.com
Tue Apr 26 02:49:45 PDT 2011


Xavier Roche wrote:
> Hi folks,
>
> In the Windows version of NET_BindV6() [jdk/src/windows/native/java/net/
> net_util_md.c], the code seems to be doing the binding twice when 
> using a wildcard address (see b->ipv4_fd and b->ipv6_fd)
>
> The comment says:
>
> (..)
>  * The more complicated case is when the requested address is ::0 or 
> 0.0.0.0.
>  *
>  * Two further cases:
>  * 2. If the reqeusted port is 0 (ie. any port) then we try to bind in 
> v4 space
>  *    first with a wild-card port argument. We then try to bind in v6 
> space
>  *    using the returned port number. If this fails, we repeat the 
> process
>  *    until a free port common to both spaces becomes available.
>  *
>  * 3. If the requested port is a specific port, then we just try to 
> get that
>  *    port in both spaces, and if it is not free in both, then the 
> bind fails.
>
> Why isn't the function simply switching IPV6_V6ONLY to "off" before 
> binding ? 
> (http://msdn.microsoft.com/en-us/library/ms738574(v=vs.85).aspx)
>
> Such as:
>     int off = 0;
>     (void) setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
>                       (char *)&off, sizeof(off));
>
> This would allow NOT to bind two ports, and prevent any troubles with 
> "half-bound" ports.
>
> (Or am I missing something obvious ?)
The net-dev list would be best place to bring this. If it helps, the 
above is only used on older editions of Windows that don't support 
dual-stack sockets. You'll see on Windows Vista on newer that it uses a 
single socket with IPV6_V6ONLY disabled.

-Alan.


More information about the jdk7-dev mailing list