提交 feb5c899 编写于 作者: A asaha

Merge

...@@ -631,6 +631,7 @@ e915a408ebf7ba05b36d1b714e166a1d9e5c7edd jdk8u102-b11 ...@@ -631,6 +631,7 @@ e915a408ebf7ba05b36d1b714e166a1d9e5c7edd jdk8u102-b11
e3839fe291add6e0ea199457fb31c9312cc5dd77 jdk8u102-b32 e3839fe291add6e0ea199457fb31c9312cc5dd77 jdk8u102-b32
275fcb7d4e3e70a37ac70c33d087a805ba182f1e jdk8u102-b33 275fcb7d4e3e70a37ac70c33d087a805ba182f1e jdk8u102-b33
d783f00bb04a6fff7ddf1555572c1f3cdfd21e59 jdk8u102-b34 d783f00bb04a6fff7ddf1555572c1f3cdfd21e59 jdk8u102-b34
958684c9f1e73d9310511559c770823180d33e4b jdk8u102-b35
ebc56c2e803597ef409a5296addc986b390d934d jdk8u111-b00 ebc56c2e803597ef409a5296addc986b390d934d jdk8u111-b00
c4f03717831993e4658b8366810ca4682ece952d jdk8u111-b01 c4f03717831993e4658b8366810ca4682ece952d jdk8u111-b01
de1d09f09e571e38afdf1fb72984ec210e7c19e6 jdk8u111-b02 de1d09f09e571e38afdf1fb72984ec210e7c19e6 jdk8u111-b02
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <process.h> #include <process.h>
#include <iphlpapi.h> #include <iphlpapi.h>
#include <icmpapi.h> #include <icmpapi.h>
#include <WinError.h>
#include "java_net_InetAddress.h" #include "java_net_InetAddress.h"
#include "java_net_Inet4AddressImpl.h" #include "java_net_Inet4AddressImpl.h"
...@@ -481,7 +482,15 @@ ping4(JNIEnv *env, ...@@ -481,7 +482,15 @@ ping4(JNIEnv *env,
DWORD ReplySize = 0; DWORD ReplySize = 0;
jboolean ret = JNI_FALSE; jboolean ret = JNI_FALSE;
ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366051%28v=vs.85%29.aspx
ReplySize = sizeof(ICMP_ECHO_REPLY) // The buffer should be large enough
// to hold at least one ICMP_ECHO_REPLY
// structure
+ sizeof(SendData) // plus RequestSize bytes of data.
+ 8; // This buffer should also be large enough
// to also hold 8 more bytes of data
// (the size of an ICMP error message)
ReplyBuffer = (VOID*) malloc(ReplySize); ReplyBuffer = (VOID*) malloc(ReplySize);
if (ReplyBuffer == NULL) { if (ReplyBuffer == NULL) {
IcmpCloseHandle(hIcmpFile); IcmpCloseHandle(hIcmpFile);
...@@ -517,10 +526,45 @@ ping4(JNIEnv *env, ...@@ -517,10 +526,45 @@ ping4(JNIEnv *env,
(timeout < 1000) ? 1000 : timeout); // DWORD Timeout (timeout < 1000) ? 1000 : timeout); // DWORD Timeout
} }
if (dwRetVal != 0) { if (dwRetVal == 0) { // if the call failed
TCHAR *buf;
DWORD err = WSAGetLastError();
switch (err) {
case ERROR_NO_NETWORK:
case ERROR_NETWORK_UNREACHABLE:
case ERROR_HOST_UNREACHABLE:
case ERROR_PROTOCOL_UNREACHABLE:
case ERROR_PORT_UNREACHABLE:
case ERROR_REQUEST_ABORTED:
case ERROR_INCORRECT_ADDRESS:
case ERROR_HOST_DOWN:
case WSAEHOSTUNREACH: /* Host Unreachable */
case WSAENETUNREACH: /* Network Unreachable */
case WSAENETDOWN: /* Network is down */
case WSAEPFNOSUPPORT: /* Protocol Family unsupported */
case IP_REQ_TIMED_OUT:
break;
default:
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, NULL);
NET_ThrowNew(env, err, buf);
LocalFree(buf);
break;
}
} else {
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer; PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
if ((int)pEchoReply->RoundTripTime <= timeout)
// This is to take into account the undocumented minimum
// timeout mentioned in the IcmpSendEcho call above.
// We perform an extra check to make sure that our
// roundtrip time was less than our desired timeout
// for cases where that timeout is < 1000ms.
if (pEchoReply->Status == IP_SUCCESS
&& (int)pEchoReply->RoundTripTime <= timeout)
{
ret = JNI_TRUE; ret = JNI_TRUE;
}
} }
free(ReplyBuffer); free(ReplyBuffer);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册