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.

-Alan



Reply via email to