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

InetAddress.isReachable() returns true when testing through loopback interface

XMLWordPrintable

    • b31
    • generic
    • generic
    • Verified

      The InetAddress.isReachable(nif, ttl, to) API returns true when testing the reachability of a host through the loopback interface of the machine. A loopback interface cannot be used to communicate with other hosts and therefore the API should return false. This problem is seen on a solaris 8 machine as well as a windows XP (ipv6 enabled) machine. The problem does not occur on a windows 2000 machine.

      Steps to reproduce the problem:
      1. Compile the attached code.
      2. Execute the code on a solaris machine while using an ipv4 or an ipv6 address as a command line parameter to the program.
      3. The code returns reachable through the loopback interface.

      ---------------------------BEGIN CODE-------------------------
      import java.net.*;
      import java.util.*;
      import java.io.*;

      public class Ipv6ReachableBugXP{
              public static void main(String args[]){
                      String inputAdd = null;
                      Enumeration nifEnum = null;
                      NetworkInterface nif = null;
                      InetAddress inetAdd = null;

                      if (args.length > 0){
                              inputAdd = args[0];
                      } else {
                              inputAdd = "fe80::a00:20ff:fef7:c4e7";
                      }

                      try{
                              inetAdd = InetAddress.getByName(inputAdd);
                      } catch (UnknownHostException uhe){
                              uhe.printStackTrace();
                              System.exit(1);
                      }

                      try{
                              nifEnum = NetworkInterface.getNetworkInterfaces();
                      } catch (SocketException se){
                              se.printStackTrace();
                              System.exit(1);
                      }

                      while (nifEnum.hasMoreElements()){
                              nif = (NetworkInterface) nifEnum.nextElement();
                              try {
                                      System.out.println("Trying reachability of " +
                                                     inetAdd + " through nif " + nif);
                                      if (inetAdd.isReachable(nif, 20, 20000)){
                                              System.out.println("Reachable through NIF : " + nif);
                                      } else {
                                              System.out.println("FAILURE !!! Unreachable through" +
                                                      " NIF : " + nif);
                                      }
                              } catch (IOException ioe){
                                      ioe.printStackTrace();
                              }
                      }
              }
      }

      ----------------------------END CODE-------------------------

      The output from a solaris 8 machine is given below
      ---------------------------BEGIN OUTPUT-------------------------
      $java -showversion Ipv6ReachableBugXP fe80::a00:20ff:fef7:c4e7
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b18)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b18, mixed mode)

      Trying reachability of /fe80:0:0:0:a00:20ff:fef7:c4e7 through nif name:hme0 (hme0) index: 2 addresses:
      /fe80:0:0:0:a00:20ff:fefe:3440;
      /129.158.229.142;

      Reachable through NIF : name:hme0 (hme0) index: 2 addresses:
      /fe80:0:0:0:a00:20ff:fefe:3440;
      /129.158.229.142;

      Trying reachability of /fe80:0:0:0:a00:20ff:fef7:c4e7 through nif name:lo0 (lo0) index: 1 addresses:
      /0:0:0:0:0:0:0:1;
      /127.0.0.1;

      Reachable through NIF : name:lo0 (lo0) index: 1 addresses:
      /0:0:0:0:0:0:0:1;
      /127.0.0.1;

      $
      -----------------------------END OUTPUT-------------------------

            jccollet Jean-Christophe Collet (Inactive)
            kjethisunw Kanishk Jethi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: