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

InetAddress.isReachable returns true for unreachable addresses

XMLWordPrintable

    • b22
    • generic
    • generic

      Name: akR10050 Date: 09/12/2003



      InetAddress.isReachable(int) returns true for unreachable addresses.

      Here is the testcase:
      ------------------- Test31.java ---------------------

      import java.net.InetAddress;
      import java.io.IOException;

      public class Test31 {
          public static void main(String[] args) {
              /* STEP 1: get an unreachable host. */
              InetAddress ia = null;
              try {
                  ia = InetAddress.getByName("2.2.2.1");
              } catch (IOException ioe) {
                  System.err.println("WRONG: " + ioe);
              }

              /* STEP 2: declare the timeout value. 5 seconds is more than enough to
               * access a host on LAN. */
              int timeout = 5;

              /* STEP 3: test reachability of the host. */
              try {
                  if ( ia.isReachable(timeout) ) {
                      System.err.println("WRONG: true returned with timeout value "
                              + timeout + " for host " + ia);
                  } else {
                      System.err.println("CORRECT: false returned");
                  }
              } catch (IOException ioe) {
                  System.err.println("WRONG: " + ioe);
              }
          }
      }
      -----------------------------------------------------

      The following is the output running the test:

      ----------------- sample output ---------------------

      $ java -version
      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)

      $ java Test31
      WRONG: true returned with timeout value 5 for host /2.2.2.1

      $ ping 2.2.2.1 5
      no answer from 2.2.2.1

      -----------------------------------------------------

      This output was achieved on a solaris box (therefore ping command is one of
      solaris). However, isReachable(int) exposes the same behaviour on other
      platforms.

      ======================================================================

            jccollet Jean-Christophe Collet (Inactive)
            kaisunw Kai Kai (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: