# HG changeset patch # User ngmr # Date 1323690070 0 # Node ID d98a111c07b49ce97303b76a29451b4342d3d1e3 # Parent 1914ba5878eada87e0a4516cdfdc83be72c0e694 7118907: InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH Reviewed-by: alanb, chegar Contributed-by: Charles Lee diff -r 1914ba5878ea -r d98a111c07b4 src/solaris/native/java/net/Inet4AddressImpl.c --- a/src/solaris/native/java/net/Inet4AddressImpl.c Tue Jul 17 11:57:37 2012 +0800 +++ b/src/solaris/native/java/net/Inet4AddressImpl.c Mon Dec 12 11:41:10 2011 +0000 @@ -669,11 +669,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"); @@ -828,10 +828,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); diff -r 1914ba5878ea -r d98a111c07b4 src/solaris/native/java/net/Inet6AddressImpl.c --- a/src/solaris/native/java/net/Inet6AddressImpl.c Tue Jul 17 11:57:37 2012 +0800 +++ b/src/solaris/native/java/net/Inet6AddressImpl.c Mon Dec 12 11:41:10 2011 +0000 @@ -512,11 +512,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"); @@ -680,10 +680,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);