src/solaris/native/java/net/Inet4AddressImpl.c

Print this page

        

@@ -379,10 +379,21 @@
        * send it
        */
       n = sendto(fd, sendbuf, plen, 0, (struct sockaddr *)him,
                  sizeof(struct sockaddr));
       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.
+           */
+          close(fd);
+          return JNI_FALSE;
+        }
+#endif /*__linux__ */
         NET_ThrowNew(env, errno, "Can't send ICMP packet");
         close(fd);
         return JNI_FALSE;
       }