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

Reviewed-by: alanb
This commit is contained in:
Chris Hegarty 2010-10-22 09:20:09 +01:00
parent 7d22a39cae
commit 2580a79f30
2 changed files with 18 additions and 1 deletions

View File

@ -381,6 +381,14 @@ ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout,
n = sendto(fd, sendbuf, plen, 0, (struct sockaddr *)him,
sizeof(struct sockaddr));
if (n < 0 && errno != EINPROGRESS ) {
#ifdef __linux__
if (errno != EINVAL)
/*
* On some Linuxes, when bound to the loopback interface, sendto
* will fail and errno will be set to EINVAL. When that happens,
* don't throw an exception, just return false.
*/
#endif /*__linux__ */
NET_ThrowNew(env, errno, "Can't send ICMP packet");
close(fd);
return JNI_FALSE;

View File

@ -506,7 +506,16 @@ ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout,
plen = sizeof(struct icmp6_hdr) + sizeof(tv);
n = sendto(fd, sendbuf, plen, 0, (struct sockaddr*) him, sizeof(struct sockaddr_in6));
if (n < 0 && errno != EINPROGRESS) {
#ifdef __linux__
if (errno != EINVAL)
/*
* On some Linuxes, when bound to the loopback interface, sendto
* will fail and errno will be set to EINVAL. When that happens,
* don't throw an exception, just return false.
*/
#endif /*__linux__ */
NET_ThrowNew(env, errno, "Can't send ICMP packet");
close(fd);
return JNI_FALSE;
}