Question regarding NET_BindV6() and the "double bind"
Xavier Roche
roche+kml2 at exalead.com
Tue Apr 26 02:42:02 PDT 2011
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 ?)
More information about the jdk7-dev
mailing list