Code Review 6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid argument" on Linux if run as root

Chris Hegarty chris.hegarty at oracle.com
Thu Oct 21 07:41:22 PDT 2010



On 21/10/2010 15:25, Alan Bateman wrote:
> Chris Hegarty wrote:
>> :
>> It appears to be specific to the loopback interface. You can reproduce
>> the very same behavior using DatagramSocket and DatagramChannel; bind
>> to the loopback address and send a packet to a remote address.
>>
>> I was not too happy about doing this until I found that we do the very
>> same thing in non raw sockets case.
>>
> The main concern is that you are hide a real "invalid argument" case. It
> would be good to follow this up with the Linux folks to clarify if the
> error make sense for this case.

Agreed.

> So have you considered any other solution to this? I'm just wondering if
> it would be saner to check if the network interface is the loopback
> interface, and if so, just return false when the address is something
> other than the loopback. As regards the current fix - it's probably okay

I did think about this, but the local interface addresses are reachable, 
isReachable returns true, even if the lookback interface is specified. 
We'd have to maintain a list of "reachable" addresses. Which I didn't 
think would be an nicer solution.

> although it would be nicer if you didn't have to repeat the close and
> return JNI_FALSE.

I've removed the extra code and made the change simpler.
   http://cr.openjdk.java.net/~chegar/6947677/webrev.01/webrev/

-Chris.

>
> -Alan.



More information about the net-dev mailing list