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

InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 7
    • core-libs
    • b19
    • generic
    • generic

        On some Linuxes, when bound to the loopback interface, sendto may fail with an EINVAL errno (see CR 6947677), and on others (AIX, iSeries) it will throw an EHOSTUNREACH errno. In such situation, EHOSTUNREACH should be treated the same as EINVAL, not
        throw an exception but return false.

        Below is the simple testcase that can demonstrate this on specific platforms:

        public class IsReachableTest {
             public static void main(String[] args) throws Exception{
                 InetAddress testHost1 = InetAddress.getByName("openjdk.java.net");
                 NetworkInterface loopbackNi = null;
                 Enumeration<NetworkInterface> list =
                     NetworkInterface.getNetworkInterfaces();
                 boolean loopbackFound = false;
                 while (list.hasMoreElements() && !loopbackFound){
                     loopbackNi = list.nextElement();
                     if (loopbackNi.isLoopback() && loopbackNi.isUp()) {
                         loopbackFound = true;
                     }
                 }

                 if (!loopbackFound)
                     return;
                 if (testHost1.isReachable(loopbackNi, 64, 1000))
                     System.out.println(String.format("Fail: external host '%s' is reachable via loopback '%s'!", testHost1, loopbackNi));
             }
        }

        see the mail thread on the net-dev mailing list for further details:
          http://mail.openjdk.java.net/pipermail/net-dev/2011-December/003839.html

              chegar Chris Hegarty
              chegar Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: