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

java.net.NetworkInterface.getNetworkInterfaces ignores unconfigured interfaces.

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version 1.8.0_60
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
       3.18.9-hardened #2 SMP Wed Jun 3 16:59:24 PDT 2015 x86_64 Intel(R) Pentium(R) CPU G3440 @ 3.30GHz GenuineIntel GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      On Linux, calls to java.net.NetworkInterface.getNetworkInterfaces do not return any interfaces which have no address or only an ipv6 link-local address configured.

      On Windows, calls to the same function return all network interfaces, regardless of what kinds of addresses are configured.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      call java.net.NetworkInterface.getNetworkInterfaces and compare the returned values to the interfaces installed in the system.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Ideally I would expect it to return all network interfaces on the system, regardless of configuration state, like it does on Windows.

      ACTUAL -
      Windows returns all interfaces while Linux returns only interfaces with a configured IPv4 address. (Note: I didn't actually test with an IPv6 address other than link-local, but I can't think of a good reason to be ignoring link-local addresses specifically, and that's still not the behaviour presented on the other platform anyway)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.net.NetworkInterface;
      import java.net.SocketException;
      import java.util.Enumeration;

      public class Main {
          /**
           * Program entry point
           *
           * @param args Command line arguments
           */
          public static void main(String[] args) {
              Enumeration<NetworkInterface> netInterfaces = null;
              try {
                  netInterfaces = NetworkInterface.getNetworkInterfaces();
              } catch (SocketException e) {
                  return;
              }
              while (netInterfaces.hasMoreElements()) {
                  NetworkInterface iface = netInterfaces.nextElement();
                  System.out.println("NIC " + iface.getName() + "\n");
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Write a helper program in something other than Java...

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: