提交 b91748e3 编写于 作者: N ngmr

7118907: InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH

Reviewed-by: alanb, chegar
Contributed-by: NCharles Lee <littlee@linux.vnet.ibm.com>
上级 8821938b
......@@ -367,11 +367,11 @@ ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout,
sizeof(struct sockaddr));
if (n < 0 && errno != EINPROGRESS ) {
#ifdef __linux__
if (errno != EINVAL)
if (errno != EINVAL && errno != EHOSTUNREACH)
/*
* 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.
* will fail and errno will be set to EINVAL or EHOSTUNREACH.
* When that happens, don't throw an exception, just return false.
*/
#endif /*__linux__ */
NET_ThrowNew(env, errno, "Can't send ICMP packet");
......@@ -525,10 +525,11 @@ Java_java_net_Inet4AddressImpl_isReachable0(JNIEnv *env, jobject this,
case EADDRNOTAVAIL: /* address is not available on the remote machine */
#ifdef __linux__
case EINVAL:
case EHOSTUNREACH:
/*
* On some Linuxes, when bound to the loopback interface, connect
* will fail and errno will be set to EINVAL. When that happens,
* don't throw an exception, just return false.
* will fail and errno will be set to EINVAL or EHOSTUNREACH.
* When that happens, don't throw an exception, just return false.
*/
#endif /* __linux__ */
close(fd);
......
......@@ -502,11 +502,11 @@ ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout,
n = sendto(fd, sendbuf, plen, 0, (struct sockaddr*) him, sizeof(struct sockaddr_in6));
if (n < 0 && errno != EINPROGRESS) {
#ifdef __linux__
if (errno != EINVAL)
if (errno != EINVAL && errno != EHOSTUNREACH)
/*
* 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.
* will fail and errno will be set to EINVAL or EHOSTUNREACH.
* When that happens, don't throw an exception, just return false.
*/
#endif /*__linux__ */
NET_ThrowNew(env, errno, "Can't send ICMP packet");
......@@ -670,10 +670,11 @@ Java_java_net_Inet6AddressImpl_isReachable0(JNIEnv *env, jobject this,
case EADDRNOTAVAIL: /* address is not available on the remote machine */
#ifdef __linux__
case EINVAL:
case EHOSTUNREACH:
/*
* On some Linuxes, when bound to the loopback interface, connect
* will fail and errno will be set to EINVAL. When that happens,
* don't throw an exception, just return false.
* will fail and errno will be set to EINVAL or EHOSTUNREACH.
* When that happens, don't throw an exception, just return false.
*/
#endif /* __linux__ */
close(fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册