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

java.net.NetworkInterface.getNetworkInterfaces() does not list IPv6 network interfaces correctly

XMLWordPrintable

    • b50
    • sparc
    • solaris_9
    • Not verified

      OPERATING SYSTEM
      ----------------
      Solaris

      JAVA VERSION
      ------------
      java version "1.6.0_11"
      Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
      Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode)

      PROBLEM DESCRIPTION
      -------------------

      When IPv6 configured Network Interfaces are used, getNetworkInterfaces() lists all the interfaces including the Base/physical interface and the logical interfaces. Logical Interfaces are not listed by getNetworkInterfaces() when Network Interfaces are configured with IPv4. This is seen on Java 6 (160_11).

      We configured our test system with both IPv4 and IPv6 interfaces. Here is the output from "ifconfig -a" on that system:

      --------------------------------------------------
      lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
              inet 127.0.0.1 netmask ff000000
      bge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
              inet 9.184.112.183 netmask fffff800 broadcast 9.184.119.255
              ether 0:3:ba:48:2e:b7
      bge2: flags=1000803<UP,BROADCAST,MULTICAST,IPv4> mtu 1500 index 4
              inet 192.168.1.10 netmask ffffff00 broadcast 192.168.1.255
              ether 0:3:ba:48:2e:b9
      bge2:1: flags=1000803<UP,BROADCAST,MULTICAST,IPv4> mtu 1500 index 4
              inet 192.168.1.11 netmask ffffff00 broadcast 192.168.1.255
      bge0: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 2
              inet6 fe80::203:baff:fe48:2eb7/10
              ether 0:3:ba:48:2e:b7
      bge0:1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 2
              inet6 2002:92a:8f7a:532:9:184:112:183/64
      bge1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
              inet6 fe80::203:baff:fe48:2eb8/10
              ether 0:3:ba:48:2e:b8
      bge1:1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
              inet6 2002:92a:8f7a:532:9:184:112:22/64
      bge1:2: flags=2000840<RUNNING,MULTICAST,IPv6> mtu 1500 index 3
              inet6 ::/0
      --------------------------------------------------

      So, when the attached test case was run with Java 6 on the above machine, this was the result:

      --------------------------------------------------
      jnic : name:bge1:2 (bge1:2) index: 3 addresses:
      /0:0:0:0:0:0:0:0%3;

      jnic : name:bge1:1 (bge1:1) index: 3 addresses:
      /2002:92a:8f7a:532:9:184:112:22%3;

      jnic : name:bge1 (bge1) index: 3 addresses:
      /fe80:0:0:0:203:baff:fe48:2eb8%3;

      jnic : name:bge2 (bge2) index: 4 addresses:
      /192.168.1.11;
      /192.168.1.10;

      jnic : name:bge0 (bge0) index: 2 addresses:
      /2002:92a:8f7a:532:9:184:112:183%2;
      /fe80:0:0:0:203:baff:fe48:2eb7%2;
      /9.184.112.183;

      jnic : name:lo0 (lo0) index: 1 addresses:
      /127.0.0.1;
      --------------------------------------------------

      It can be seen for bge1 (which is IPv6 configured) all (base(bge1)+ alias(bge1:1 and bge1:2)) interfaces are listed by getNetworkInterfaces(), but this is not the case with Interfaces configured with IPv4 (bge2) and Interfaces configured with both IPV4 and IPv6 (bge0). The same test case when run with Java 5 (1.5.0_17) provided the following results:

      --------------------------------------------------
      jnic : name:bge1 (bge1) index: 3 addresses:
      /0:0:0:0:0:0:0:0;
      /2002:92a:8f7a:532:9:184:112:22;
      /fe80:0:0:0:203:baff:fe48:2eb8;

      jnic : name:bge2 (bge2) index: 4 addresses:
      /192.168.1.11;
      /192.168.1.10;

      jnic : name:bge0 (bge0) index: 2 addresses:
      /2002:92a:8f7a:532:9:184:112:183;
      /fe80:0:0:0:203:baff:fe48:2eb7;
      /9.184.112.183;

      jnic : name:lo0 (lo0) index: 1 addresses:
      /127.0.0.1;
      --------------------------------------------------

      Here, for the IPv6 configured Network Interface (bge1) only the base interface is listed and not all the aliases. The same is the result with Java 1.4.2. So, the way in which IPv6 Network Interfaces are listed has changed in Java 6 compared to Java 5.0.


      TESTCASE SOURCE
      ---------------

      import java.net.*;

      class NicTest {
          public static void listNics()
          {
              java.net.NetworkInterface jnic;
              java.util.Enumeration nics;
              try {
                  nics = java.net.NetworkInterface.getNetworkInterfaces();
                  while (nics.hasMoreElements()) {
                      jnic = (java.net.NetworkInterface)nics.nextElement();
                      System.out.println("jnic : " + jnic);
                  }
              } catch (java.lang.Exception e) {
                  return;
              }
          }

          public static void main(String args[] )
          {
              NicTest.listNics();
          }
      }

            chegar Chris Hegarty
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: