Witam,
Znalazłem na internecie taka funkcje do do sprawdzania pingu na danym serwerze, działa prawidłowo lecz lekko scina mój program za każdym razem gdy wywołuje się ta funkcja, czym to może być spowodowane?
int Game::getNewPing(const std::string& ip)
{
HANDLE hIcmpFile;
unsigned long ipaddr = inet_addr(ip.c_str());
DWORD dwRetVal = 0;
char SendData[32] = "Data Buffer";
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;
// Validate the parameters
if (ipaddr == INADDR_NONE) {
return 0;
}
hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE) {
g_logger.info(stdext::format("\tUnable to open handle.\n"));
g_logger.info(stdext::format("IcmpCreatefile returned error: %ld\n", GetLastError()));
return 0;
}
ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
ReplyBuffer = (VOID*)malloc(ReplySize);
if (ReplyBuffer == NULL) {
g_logger.info(stdext::format("\tUnable to allocate memory\n"));
return 0;
}
dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
NULL, ReplyBuffer, ReplySize, 5000);
if (dwRetVal != 0) {
PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
struct in_addr ReplyAddr;
ReplyAddr.S_un.S_addr = pEchoReply->Address;
return pEchoReply->RoundTripTime;
}
else {
g_logger.info(stdext::format("\tCall to IcmpSendEcho failed.\n"));
g_logger.info(stdext::format("\tIcmpSendEcho returned error: %ld\n", GetLastError()));
return 0;
}
return 0;
}