On 07/12/2011 11:12, Alan Bateman wrote:
On 07/12/2011 08:11, Charles Lee wrote:
:

I'd like to raise this issue again. The patch is on the [1]:

When a loopback network interface is bound to sendto and connect, in
some linuxes it will throw an EINVAL errno, in other linuxes (AIX,
iSeries) it will throw an EHOSTUNREACH errno. The man page of sendto
on Aix and solaris is [2][3].
In such situation, EHOSTUNREACH should treat as the same as EINVAL:
not throw an exception but return false.

Below is the simple test case can test this situation in 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));
}
}/

Any thoughts, guys?
APIs that return a boolean to indicate success/failure and can also
throw IOException when there is a failure can be awkward as there will
be cases where IOException is thrown when false might seem to be more
correct. In this case, if sendto can fail with EHOSTUNREACH on Linux
then the proposed patch looks okay to me. I'm kinda surprised that
EINVAL is returned in some cases, that seems misleading to me.

Ugh, I remember this one. Not pretty, but we found not better alternative, see
  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6947677

I filed a new CR for this issue:
7118907: "InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH"

I approved the proposed changes.

Trivially can you put a new line in the comment after EHOSTUNREACH.

  /*
  * On some Linuxes, when bound to the loopback interface, sendto
  * will fail and errno will be set to EINVAL or EHOSTUNREACH.
  * When that happens, don't throw an exception, just return false.
  */

I assume Neil can push this for you? If not, I can help with the push.

-Chris.


-Alan



Reply via email to