Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6658085

MulticastSocket.setNetworkInterface() doesn't work as expected on vista

XMLWordPrintable

    • x86
    • windows_vista

      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

            Unassigned Unassigned
            dfazunen Dmitry Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: