changeset 2988:549257d35662

6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid argument" on Linux if run as root Reviewed-by: alanb
author chegar
date Fri, 22 Oct 2010 09:20:09 +0100
parents 19cbbf152335
children 3740c2da7cc5
files src/solaris/native/java/net/Inet4AddressImpl.c src/solaris/native/java/net/Inet6AddressImpl.c
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/net/Inet4AddressImpl.c	Thu Oct 21 16:51:09 2010 +0100
+++ b/src/solaris/native/java/net/Inet4AddressImpl.c	Fri Oct 22 09:20:09 2010 +0100
@@ -381,7 +381,15 @@
       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;
       }
--- a/src/solaris/native/java/net/Inet6AddressImpl.c	Thu Oct 21 16:51:09 2010 +0100
+++ b/src/solaris/native/java/net/Inet6AddressImpl.c	Fri Oct 22 09:20:09 2010 +0100
@@ -506,7 +506,16 @@
       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;
       }