Code Review Request: 7084030 DatagramSocket.getLocalAddress inconsistent on XP/2003 when IPv6 enabled and socket is connected

Kurchi Hazra kurchi.subhra.hazra at oracle.com
Fri Sep 23 13:13:03 PDT 2011


Hi,

     The DatagramSocket.getLocalAddress() method was returning a 
wildcard address when a DatagramSocket is created and then connected to 
a remote address, on windows XP/Server 2003 machines with IPv6 enabled. 
However, for adhering to the spec as well as being consistent across all 
platforms, it is desirable for DatagramSocket.getLocalAddress() to 
return the local address that it is bound to on being connected. The 
cause of the problem was incorrect handling of the file descriptors 
representing the two stacks of IPv4 and IPv6 in Windows XP/Server 2003 
specific native code.
     In order to fix this, a new native method socketLocalAddress() has 
been introduced in 
src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c which 
takes care of handling the file descriptors correctly when the 
DatagramSocket in question is connected to a remote address. The method 
accepts the family of the address to which it is connected (IPv4 or 
IPv6) and picks up the localAddress information from the concerned file 
descriptor (fd for IPv4 and fd1 for IPv6). 
src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java has 
been modified accordingly to call the socketLocalAddress() instead of 
socketGetOption() when the option passed to DatagramSocket.getOption() 
is SocketOptions.SO_BINDADDR as in the case of 
DatagramSocket.getLocalAddress().

The fix involves updates in:
src/share/classes/java/net/AbstractPlainDatagramSocket
src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java
src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c

Webrev: http://cr.openjdk.java.net/~chegar/7084030/webrev.00/


Thanks,
Kurchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20110923/222bd910/attachment.html 


More information about the net-dev mailing list