JDK-6658085 : MulticastSocket.setNetworkInterface() doesn't work as expected on vista
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2008-02-01
  • Updated: 2013-09-05
  • Resolved: 2008-02-27
Related Reports
Duplicate :  
Description
On windows Vista invocation of MulticastSocket.setNetworkInterface(ni) doesn't set NetworkInterface as expected, if ni is a real network interface.

The result of the execution of the following lines might be "false":
  ms.setNetworkInterface(ni);
  newNi = ms.getNetworkInterface();
  System.out.println(ni.equals(newNi));

The bug is reproducible only on Vista. JCK tests work fine on Solaris, Linux, win XP.

The minimized test demonstrating the bug:

------ 8< ---------------------------
import java.io.IOException;
import java.net.*;
import java.util.*;

public class Test {
    
    public Test() {
    }

    public static void main(String[] args) {
        boolean passed = true;
        try {
                                    
            MulticastSocket ms = new MulticastSocket();                        
            Enumeration<NetworkInterface> allNI = 
                    NetworkInterface.getNetworkInterfaces();
            while (allNI.hasMoreElements()) {
                NetworkInterface ni = allNI.nextElement();
                if (ni.isUp() && ni.supportsMulticast()) {
                    printNI(ni);
                    ms.setNetworkInterface(ni);
                    NetworkInterface newNI = ms.getNetworkInterface();
                    if (ni.equals(newNI)) {
                        System.out.println("  OK");
                    } else {
                        System.out.println("FAILED!!!");
                        printNI(newNI);
                        passed = false;
                    }
                    System.out.println("------------------");
                }
            }            
        } catch (IOException e) {
            e.printStackTrace(System.out);
            passed = false;
        }
        System.out.println(passed ? "Test passed " : "Test failed");
    }    

    private static void printNI(NetworkInterface ni) throws SocketException {
        System.out.println("Name " + ni.getName()); 
        Enumeration<InetAddress> en = ni.getInetAddresses();
        while (en.hasMoreElements()) {
            System.out.println("  InetAdress: " + en.nextElement());
        }
        System.out.println("HardwareAddress: " + Arrays.toString(ni.getHardwareAddress()));
        System.out.println("loopback: " + ni.isLoopback() + 
                "; pointToPoint: " + ni.isPointToPoint() + 
                "; virtual: " + ni.isVirtual() + 
                "; MTU: " + ni.getMTU());
    }
}
------ 8< ---------------------------

Output from the test


Name lo
  InetAdress: /0:0:0:0:0:0:0:1
  InetAdress: /127.0.0.1
HardwareAddress: []
loopback: true; pointToPoint: false; virtual: false; MTU: -1
  OK
------------------
Name eth2
  InetAdress: /10.16.32.73
HardwareAddress: [0, 15, -22, 56, -37, -16]
loopback: false; pointToPoint: false; virtual: false; MTU: 1500
FAILED!!!
Name null
  InetAdress: 0.0.0.0/0.0.0.0
HardwareAddress: null
loopback: false; pointToPoint: false; virtual: false; MTU: -1
------------------
Test failed

Comments
we're going native ... delving into the socket impls: when I execute a test, as per the test case above on my windows 7 box no IPv6 enabled on each interface the following output is produced Name lo InetAdress: /127.0.0.1 InetAdress: /0:0:0:0:0:0:0:1 HardwareAddress: [] loopback: true; pointToPoint: false; virtual: false; MTU: -1 OK ------------------ Name eth6 HardwareAddress: [8, 0, 39, 0, -64, 107] loopback: false; pointToPoint: false; virtual: false; MTU: 1500 java.net.SocketException: bad argument for IP_MULTICAST_IF2: No IP addresses bound to interface at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(Unknown Source) at java.net.AbstractPlainDatagramSocketImpl.setOption(Unknown Source) at java.net.MulticastSocket.setNetworkInterface(Unknown Source) at MulticastSocketNetworkInterfaceSetterGetterTest.main(MulticastSocketNetworkInterfaceSetterGetterTest.java:27) Test failed And then on a modified jdk8 with a fix for 8021372, the following is produced Name lo InetAdress: /127.0.0.1 InetAdress: /0:0:0:0:0:0:0:1 HardwareAddress: loopback: true; pointToPoint: false; virtual: false; MTU: -1 OK ------------------ Name wlan0 InetAdress: /192.168.1.1 HardwareAddress: 60-67-20-04-1D-70 loopback: false; pointToPoint: false; virtual: false; MTU: 1500 java.net.SocketException: An invalid argument was supplied at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:146) at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:309) at java.net.MulticastSocket.setNetworkInterface(MulticastSocket.java:554) at MulticastSocketNetworkInterfaceSetterGetterTest.main(MulticastSocketNetworkInterfaceSetterGetterTest.java:27) Test failed API says that a SocketException can be thrown for MulticastSocket.setNetworkIntreface() ?? and that's what we get :-) --------------------oOo---------------------------------- the following shows some level of IP multicast awareness C:\Users\msheppar>netsh interface ip show joins Interface 1: Loopback Pseudo-Interface 1 Scope References Last Address ---------- ---------- ---- --------------------------------- 0 2 Yes 239.255.255.250 Interface 16: Wireless Network Connection Scope References Last Address ---------- ---------- ---- --------------------------------- 0 0 No 224.0.0.1 0 1 Yes 224.0.0.252 0 2 Yes 239.255.255.250 Interface 14: Local Area Connection Scope References Last Address ---------- ---------- ---- --------------------------------- 0 0 Yes 224.0.0.1 Interface 18: Local Area Connection 2 Scope References Last Address ---------- ---------- ---- --------------------------------- 0 0 Yes 224.0.0.1 0 1 Yes 224.0.0.252 Interface 23: VirtualBox Host-Only Network Scope References Last Address ---------- ---------- ---- --------------------------------- 0 0 Yes 224.0.0.1 0 1 Yes 224.0.0.252 0 2 Yes 239.255.255.250 I have a virtual box installed also, and this can also cause issues with multicast support on windows.
05-09-2013

EVALUATION This issue is caused by the fact that IPv6 has been disabled on the network interface eth2. You can see this from the output in the description section, only an IPv4 address is being printed. This is a duplicate of CR 6458027.
27-02-2008