changeset 11640:661cdd57ac8d

8143397: It looks like InetAddress.isReachable(timeout) works incorrectly Reviewed-by: xuelei, msheppar
author robm
date Wed, 09 Dec 2015 15:59:20 +0000
parents 8c001d375832
children 9e6c76d365aa
files src/windows/native/java/net/Inet4AddressImpl.c
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/Inet4AddressImpl.c	Thu Dec 10 11:54:42 2015 -0800
+++ b/src/windows/native/java/net/Inet4AddressImpl.c	Wed Dec 09 15:59:20 2015 +0000
@@ -480,6 +480,7 @@
     char SendData[32] = {0};
     LPVOID ReplyBuffer = NULL;
     DWORD ReplySize = 0;
+    jboolean ret = JNI_FALSE;
 
     hIcmpFile = IcmpCreateFile();
     if (hIcmpFile == INVALID_HANDLE_VALUE) {
@@ -503,7 +504,11 @@
                                 NULL,       // PIP_OPTION_INFORMATION RequestOptions,
                                 ReplyBuffer,// LPVOID ReplyBuffer,
                                 ReplySize,  // DWORD ReplySize,
-                                timeout);   // DWORD Timeout
+                                // Note: IcmpSendEcho and its derivatives
+                                // seem to have an undocumented minimum
+                                // timeout of 1000ms below which the
+                                // api behaves inconsistently.
+                                (timeout < 1000) ? 1000 : timeout);   // DWORD Timeout
     } else {
         dwRetVal = IcmpSendEcho2Ex(hIcmpFile,  // HANDLE IcmpHandle,
                                    NULL,       // HANDLE Event
@@ -516,17 +521,19 @@
                                    NULL,       // PIP_OPTION_INFORMATION RequestOptions,
                                    ReplyBuffer,// LPVOID ReplyBuffer,
                                    ReplySize,  // DWORD ReplySize,
-                                   timeout);   // DWORD Timeout
+                                   (timeout < 1000) ? 1000 : timeout);   // DWORD Timeout
+    }
+
+    if (dwRetVal != 0) {
+        PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
+        if ((int)pEchoReply->RoundTripTime <= timeout)
+            ret = JNI_TRUE;
     }
 
     free(ReplyBuffer);
     IcmpCloseHandle(hIcmpFile);
 
-    if (dwRetVal != 0) {
-        return JNI_TRUE;
-    } else {
-        return JNI_FALSE;
-    }
+    return ret;
 }
 
 /*