提交 4dae3d03 编写于 作者: C chegar

6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid...

6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid argument" on Linux if run as root
Reviewed-by: alanb
上级 08f7cdd9
......@@ -381,7 +381,15 @@ 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 ) {
NET_ThrowNew(env, errno, "Can't send ICMP packet");
#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;
}
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册