7118907: InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH
Reviewed-by: alanb, chegar
Contributed-by: Charles Lee <littlee@linux.vnet.ibm.com>
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c Fri Dec 09 12:56:22 2011 -0800
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c Mon Dec 12 11:41:10 2011 +0000
@@ -367,11 +367,11 @@
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 @@
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);
--- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c Fri Dec 09 12:56:22 2011 -0800
+++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c Mon Dec 12 11:41:10 2011 +0000
@@ -502,11 +502,11 @@
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 @@
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);