6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid argument" on Linux if run as root
authorchegar
Fri, 22 Oct 2010 09:20:09 +0100
changeset 7024 25bd21af28bf
parent 7023 9509e6a18f6e
child 7025 6e002f9a2899
6947677: InetAddress.isReachable() throws "java.net.SocketException:Invalid argument" on Linux if run as root Reviewed-by: alanb
jdk/src/solaris/native/java/net/Inet4AddressImpl.c
jdk/src/solaris/native/java/net/Inet6AddressImpl.c
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c	Thu Oct 21 16:51:09 2010 +0100
+++ b/jdk/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/jdk/src/solaris/native/java/net/Inet6AddressImpl.c	Thu Oct 21 16:51:09 2010 +0100
+++ b/jdk/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;
       }