From 4dae3d03d141b9f7d744d4fd237f89fdf8322e01 Mon Sep 17 00:00:00 2001 From: chegar Date: Fri, 22 Oct 2010 09:20:09 +0100 Subject: [PATCH] 6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid argument" on Linux if run as root Reviewed-by: alanb --- src/solaris/native/java/net/Inet4AddressImpl.c | 10 +++++++++- src/solaris/native/java/net/Inet6AddressImpl.c | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/solaris/native/java/net/Inet4AddressImpl.c b/src/solaris/native/java/net/Inet4AddressImpl.c index 0e9969eeb..d9ddc1d6e 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 4c5e928c5..93572ae29 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; } -- GitLab