From 49b4d6dd9d4d35adc9f02df4010a1a6b33faba63 Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 1 Nov 2006 14:44:34 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@12 4f64403b-2f21-0410-a795-97e2b3489a10 --- ping_protocol/icmp.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ping_protocol/icmp.h (limited to 'ping_protocol/icmp.h') diff --git a/ping_protocol/icmp.h b/ping_protocol/icmp.h new file mode 100644 index 0000000..19aca1d --- /dev/null +++ b/ping_protocol/icmp.h @@ -0,0 +1,66 @@ +// adapted 23/9/2004 from public domain code at http://tangentsoft.net/wskfaq/examples/dllping.html + +#ifndef _ICMP_H +#define _ICMP_H + +#include + +// Structures required to use functions in ICMP.DLL + +typedef struct { + unsigned char Ttl; // Time To Live + unsigned char Tos; // Type Of Service + unsigned char Flags; // IP header flags + unsigned char OptionsSize; // Size in bytes of options data + unsigned char *OptionsData; // Pointer to options data +} IP_OPTION_INFORMATION, * PIP_OPTION_INFORMATION; + +typedef struct { + DWORD Address; // Replying address + unsigned long Status; // Reply status + unsigned long RoundTripTime; // RTT in milliseconds + unsigned short DataSize; // Echo data size + unsigned short Reserved; // Reserved for system use + void *Data; // Pointer to the echo data + IP_OPTION_INFORMATION Options; // Reply options + unsigned char ReplyData[8]; +} IP_ECHO_REPLY, * PIP_ECHO_REPLY; + + +typedef HANDLE (WINAPI* pfnHV)(VOID); +typedef BOOL (WINAPI* pfnBH)(HANDLE); +typedef DWORD (WINAPI* pfnDHDPWPipPDD)(HANDLE, DWORD, LPVOID, WORD, PIP_OPTION_INFORMATION, LPVOID, DWORD, DWORD); // evil, no? + +class ICMP { +protected: + pfnHV pIcmpCreateFile; + pfnBH pIcmpCloseHandle; + pfnDHDPWPipPDD pIcmpSendEcho; + + HMODULE hDLL; + + HANDLE hIP; + + unsigned int timeout; + bool functions_loaded; + + // protected constructor - singleton class + ICMP(); + static ICMP instance; + +public: + ~ICMP(); + static ICMP *get_instance() {return &instance;} + + bool ping(char *host, IP_ECHO_REPLY &reply); + + void set_timeout(unsigned int t) { + timeout = t; + } + + void stop(); + + unsigned int get_timeout() {return timeout;} + +}; +#endif //_ICMP_H \ No newline at end of file -- cgit v1.2.3