Hi Is this the right place to discuss/post patches for Java 1.7? If not, what is? Sun's websites are so confusing...
Has there been any work on the bug I referred to in the subject? If not, read on. On most operating systems (Windows being the exception as usual), binding to a non-0.0.0.0 IP address prevents you receiving UDP broadcasts, while binding to 0.0.0.0 makes it harder (or, in Java, currently impossible) to tell which network interface the UDP datagram arrived from. There is 2 ways to determine the interface without resorting to raw sockets: you can use SO_BINDTODEVICE (on systems that support it) to limit the socket to accept datagrams from only the given interface, or you can use recvmsg() and look at the IP_PKTINFO ancillary data. SO_BINDTODEVICE doesn't exist on Windows and requires root access on Linux so that's out of the question, but recvmsg() and equivalents exist on Windows >= XP and Linux (and probably Solaris too). Now you'd think that's all, problem solved, but in fact it's only the beginning. The in_pktinfo and in6_pktinfo structures have (overall) 3 fields: ipi_ifindex (the 1-based network interface index), ipi_spec_dst (the IP address of ipi_ifindex), and ipi_addr (the destination IP address in the packet's header). ipi_spec_dst is not equal to ipi_addr in the case of UDP broadcasts. The fun starts when you observe that IPv6, and on Windows even IPv4, has no ipi_spec_dst, and it's impossible to tell the interface from ipi_addr (which could be eg. 255.255.255.255 or 0.0.0.0), which leaves only ipi_ifindex. I'm concerned that looking up and building java.net.NetworkInterface from ipi_ifindex is too costly in CPU time and memory to do for each java.net.DatagramPacket, especially since most UDP sockets don't deal with broadcasts. Is it okay if I put the index into java.net.DatagramPacket, and provide a java.net.NetworkInterface.getByIndex() method that will do that for applications that need it? Also java.nio.channels.DatagramChannel seems very limited compared to java.net.DatagramSocket, is it worth patching? >From what I've observed in Java 1.6 on Linux, java.net.NetworkInterface.getNetworkInterfaces() doesn't list interfaces without an IP address, even if they are up. The documentation says it will list all interfaces, so is this a bug? Bye Damjan