1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
int main()
{
HANDLE hIcmp;
char *SendData = "7897897564651321546894564654651";
LPVOID ReplyBuffer;
DWORD dwRetVal;
DWORD buflen;
PICMP_ECHO_REPLY pIcmpEchoReply;
hIcmp = IcmpCreateFile();
buflen = sizeof(ICMP_ECHO_REPLY) + strlen(SendData) + 1;
ReplyBuffer = (VOID*) malloc(buflen);
if (ReplyBuffer == NULL)
{
return 1;
}
memset(ReplyBuffer, 0, buflen);
pIcmpEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
//dwRetVal = IcmpSendEcho(hIcmp,inet_addr("suzhoupingjiangfu.com"), SendData, strlen(SendData), NULL, ReplyBuffer, buflen,1000);
LARGE_INTEGER t1 = { 0 };
LARGE_INTEGER t2 = { 0 };
//QueryPerformanceCounter(&t1);
dwRetVal = IcmpSendEcho(hIcmp,inet_addr("suzhoupingjiangfu.com"), SendData, strlen(SendData), NULL, ReplyBuffer, buflen,1000);
QueryPerformanceCounter(&t1);
//t2 = t1;
cout << t1.QuadPart << endl;
//if (dwRetVal != 0)
//{
printf("Received %ld messages.\n", dwRetVal);
printf("\n");
printf("RTT: %d\n", pIcmpEchoReply->RoundTripTime);
printf("Data Size: %d\n", pIcmpEchoReply->DataSize);
printf("Message: %s\n", pIcmpEchoReply->Data);
//}
/*
else
{
printf("Call to IcmpSendEcho() failed.\n");
printf("Error: %ld\n", GetLastError());
}
*/
cout << t1.QuadPart << endl;
IcmpCloseHandle(hIcmp);
system("pause");
return 0;
}
|