summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2008-04-28 04:07:22 +0000
committer(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2008-04-28 04:07:22 +0000
commit764413b9dd8818cb61390fe6ecbdd409af043779 (patch)
tree36b5e28f9b32e6850ed37747743b438464d587ad
parent5eb6349322266f60f88c6b6753d29ed65fb9e217 (diff)
fix for 'error no resources' annoying message
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@407 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r--ping/icmp.cpp35
1 files changed, 23 insertions, 12 deletions
diff --git a/ping/icmp.cpp b/ping/icmp.cpp
index 4dab823..77ae976 100644
--- a/ping/icmp.cpp
+++ b/ping/icmp.cpp
@@ -2,9 +2,10 @@
#include "icmp.h"
char data[] = "AAAABBBBCCCCDDDDEEEEFFFFGGGGHHH";
-#define EXTRA (12)
ICMP *ICMP::instance = 0;
+#define BUFFER_SIZE (8 * (sizeof(ICMP_ECHO_REPLY) + sizeof(data)))
+
ICMP::ICMP():
timeout(2000),
functions_loaded(false)
@@ -36,21 +37,23 @@ ICMP::ICMP():
return;
}
+ /*
hIP = pIcmpCreateFile();
if (hIP == INVALID_HANDLE_VALUE) {
pIcmpCloseHandle(hIP);
return;
}
+ */
- buff = new char[sizeof(ICMP_ECHO_REPLY) + sizeof(data) + EXTRA];
+ buff = new char[BUFFER_SIZE];
functions_loaded = true;
}
void ICMP::stop() {
- if(hIP) {
- pIcmpCloseHandle(hIP);
- hIP = 0;
- }
+ //if(hIP) {
+ // pIcmpCloseHandle(hIP);
+ // hIP = 0;
+ //}
}
ICMP::~ICMP() {
@@ -83,16 +86,24 @@ bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply) {
reply.Status = 0;
+ hIP = pIcmpCreateFile();
+ 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, sizeof(ICMP_ECHO_REPLY) + sizeof(data) + EXTRA, timeout) == 0) {
- char winmsg[512], msg[1024];
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, winmsg, 512, 0);
- mir_snprintf(msg, 1024, "Ping error: %s\nICMP_ECHO_REPLY: %d\ndata: %d\ngiven: %d", winmsg, sizeof(ICMP_ECHO_REPLY), sizeof(data), sizeof(ICMP_ECHO_REPLY) + sizeof(data) + EXTRA);
- PUShowMessage(msg, SM_NOTIFY);
- return false;
+ if(pIcmpSendEcho2(hIP, 0, 0, 0, address, data, sizeof(data), 0, buff, BUFFER_SIZE, timeout) == 0) {
+ DWORD code = GetLastError();
+ 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);
+ PUShowMessage(msg, SM_NOTIFY);
+ return false;
+ }
}
memcpy(&reply, buff, sizeof(ICMP_ECHO_REPLY));
+ pIcmpCloseHandle(hIP);
+
return (reply.Status == 0);
}