diff --git a/src/solaris/native/java/net/Inet4AddressImpl.c b/src/solaris/native/java/net/Inet4AddressImpl.c index 0e9969eebe38b016aa1e159eee3343a62c2275bc..d9ddc1d6ef25e5d628f73f82ae8882a546b35548 100644 --- a/src/solaris/native/java/net/Inet4AddressImpl.c +++ b/src/solaris/native/java/net/Inet4AddressImpl.c @@ -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; } diff --git a/src/solaris/native/java/net/Inet6AddressImpl.c b/src/solaris/native/java/net/Inet6AddressImpl.c index 4c5e928c56061b441c04b28a81f2a72d3af2ff30..93572ae293b1dfb2f83fbce4e95a854a3f0f75d1 100644 --- a/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/src/solaris/native/java/net/Inet6AddressImpl.c @@ -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; }