summaryrefslogtreecommitdiff
path: root/plugins/Ping/src/icmp.cpp
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2013-03-03 14:04:30 +0000
committerKirill Volinsky <mataes2007@gmail.com>2013-03-03 14:04:30 +0000
commit22f052f313379a8e864e61fdd3593126e088ded4 (patch)
tree4b089d5d0e5a75a3af00d5cfb256065c82c23d9c /plugins/Ping/src/icmp.cpp
parenta7c5d18647c0dd188eaa723df3f73e4250a61920 (diff)
removed not used headers
added version info fixed crash #169 (patch from $ergi0) git-svn-id: http://svn.miranda-ng.org/main/trunk@3873 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Ping/src/icmp.cpp')
-rw-r--r--plugins/Ping/src/icmp.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/plugins/Ping/src/icmp.cpp b/plugins/Ping/src/icmp.cpp
index af9a3605e4..bdf8776d22 100644
--- a/plugins/Ping/src/icmp.cpp
+++ b/plugins/Ping/src/icmp.cpp
@@ -1,10 +1,9 @@
#include "common.h"
-#include "icmp.h"
char data[] = "AAAABBBBCCCCDDDDEEEEFFFFGGGGHHH";
ICMP *ICMP::instance = 0;
-#define BUFFER_SIZE (8 * (sizeof(ICMP_ECHO_REPLY) + sizeof(data)))
+#define BUFFER_SIZE (16 * (sizeof(ICMP_ECHO_REPLY) + sizeof(data)))
ICMP::ICMP():
timeout(2000),
@@ -30,8 +29,8 @@ ICMP::ICMP():
} else
DBWriteContactSettingString(0, PLUG, "PingLib", "IPHLPAPI.DLL"); // for debugging
- WSAData wsaData;
- if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
+ WSAData wsaData;
+ if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
WSACleanup();
FreeLibrary((HMODULE)hDLL);
return;
@@ -44,7 +43,7 @@ ICMP::ICMP():
return;
}
*/
-
+
buff = new char[BUFFER_SIZE];
functions_loaded = true;
}
@@ -60,21 +59,27 @@ ICMP::~ICMP() {
if(hIP) stop();
WSACleanup();
if(hDLL)
- FreeLibrary(hDLL);
+ FreeLibrary(hDLL);
delete[] buff;
}
-bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply) {
- if(!functions_loaded) return false;
+
+bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply)
+{
+ if (!functions_loaded)
+ return false;
HOSTENT *rec;
IP_OPTION_INFORMATION ipoi;
unsigned long address = inet_addr(host);
- if (address == INADDR_NONE) {
+ if (address == INADDR_NONE)
+ {
rec = gethostbyname(host);
- if(rec) address = *(unsigned long *)(*rec->h_addr_list);
- else return false;
+ if (rec != NULL)
+ address = *(unsigned long *)(*rec->h_addr_list);
+ else
+ return false;
}
ipoi.Ttl = 255;
@@ -83,15 +88,19 @@ bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply) {
ipoi.OptionsSize = 0;
ipoi.OptionsData = 0;
- reply.Status = 0;
+ reply.Status = 0;
hIP = pIcmpCreateFile();
- if (hIP == INVALID_HANDLE_VALUE) return false;
+ if (hIP == INVALID_HANDLE_VALUE)
+ return false;
//pIcmpSendEcho2(hIP, 0, 0, 0, address, data, sizeof(data), &ipoi, buff, sizeof(ICMP_ECHO_REPLY) + sizeof(data), timeout);
- if(pIcmpSendEcho2(hIP, 0, 0, 0, address, data, sizeof(data), 0, buff, BUFFER_SIZE, timeout) == 0) {
+ DWORD rep_cnt = pIcmpSendEcho2(hIP, 0, 0, 0, address, data, sizeof(data), 0, buff, BUFFER_SIZE, timeout);
+ if (rep_cnt == 0)
+ {
DWORD code = GetLastError();
- if(code != 11010) {
+ if (code != 11010)
+ {
char winmsg[512], msg[1024];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, code, 0, winmsg, 512, 0);
mir_snprintf(msg, 1024, "Ping error (%d): %s", code, winmsg);