20#pragma comment(user,"T-Coverage Disable")
26#ifndef _TnbWINSOCK2_ENABLE
30 #pragma comment(lib,"Wsock32.lib")
32 #pragma comment(lib,"Winsock.lib")
35 #pragma message("message : Winsock2.0 を使用します。")
37 #define _WSPIAPI_COUNTOF
40 #pragma comment(lib,"WS2_32.lib")
42 #pragma comment(lib,"WS2.lib")
51 struct IP_OPTION_INFORMATION {
58 struct ICMP_ECHO_REPLY {
65 struct IP_OPTION_INFORMATION Options;
98 CIcmpFunction(
void) : m_hModule(NULL), m_pCreateFile(NULL), m_pCloseHandle(NULL), m_pSendEcho(NULL)
105 if ( m_hModule != NULL )
107 ::FreeLibrary(m_hModule);
119 return m_hModule != NULL;
130 if ( m_hModule != NULL ){
return true; }
132 m_hModule = ::LoadLibraryW(L
"ICMP.dll");
134 m_hModule = ::LoadLibraryW(L
"Iphlpapi.dll");
136 if ( m_hModule != NULL )
138 m_pCreateFile =
reinterpret_cast<P_IcmpCreateFile
>(::GetProcAddressA(m_hModule,
"IcmpCreateFile"));
139 m_pCloseHandle =
reinterpret_cast<P_IcmpCloseHandle
>(::GetProcAddressA(m_hModule,
"IcmpCloseHandle"));
140 m_pSendEcho =
reinterpret_cast<P_IcmpSendEcho
>(::GetProcAddressA(m_hModule,
"IcmpSendEcho"));
142 return m_pCreateFile != NULL && m_pCloseHandle != NULL && m_pSendEcho != NULL;
154 return m_pCreateFile();
168 return !! m_pCloseHandle(hHandle);
187 IPAddr destinationAddress,
190 IP_OPTION_INFORMATION* pRequestOptions,
209 typedef HANDLE (WINAPI *P_IcmpCreateFile)(VOID);
210 typedef BOOL (WINAPI *P_IcmpCloseHandle)(HANDLE);
211 typedef DWORD (WINAPI *P_IcmpSendEcho)(HANDLE, IPAddr, LPVOID, WORD, IP_OPTION_INFORMATION*,
void*, DWORD, DWORD);
213 P_IcmpCreateFile m_pCreateFile;
214 P_IcmpCloseHandle m_pCloseHandle;
215 P_IcmpSendEcho m_pSendEcho;
234 CPing(
void) : m_hPing(INVALID_HANDLE_VALUE), m_buf(BUFFER_LEN)
247 if ( m_hPing != INVALID_HANDLE_VALUE )
250 m_hPing = INVALID_HANDLE_VALUE;
266 int Echo(IPAddr ipAddr, DWORD timeout = 1000,
int tryCount = 5)
276 if ( m_SendEcho(ipAddr, timeout) )
287 BUFFER_LEN =
sizeof(ICMP_ECHO_REPLY) +
sizeof(DWORD)
292 if ( m_hPing == INVALID_HANDLE_VALUE )
299 if ( m_hPing == INVALID_HANDLE_VALUE )
314 bool m_SendEcho(IPAddr ipAddr, DWORD timeout)
318 m_hPing, ipAddr, &dummy,
sizeof(DWORD),
319 NULL, m_buf.
Ref(), BUFFER_LEN, timeout
321 return dwRetVal != 0;
335#pragma comment(user,"T-Coverage Enable")
#define loop(VAR, CNT)
loop構文.
CIcmpFunction(void)
コンストラクタ
bool LoadModule(void)
[確認] モジュールロード.
HANDLE CreateFile(void)
[実行] IcmpCreateFileの実行
DWORD SendEcho(HANDLE icmpHandle, IPAddr destinationAddress, LPVOID pRequestData, WORD requestSize, IP_OPTION_INFORMATION *pRequestOptions, LPVOID pReplyBuffer, DWORD replySize, DWORD timeout)
[実行] IcmpSendEchoの実行
~CIcmpFunction(void)
デストラクタ
bool CloseHandle(HANDLE hHandle)
[実行] IcmpCloseHandleの実行
bool HasModule(void) const
[確認] ロード済み確認
void Close(void)
[操作] ハンドルクローズ
int Echo(IPAddr ipAddr, DWORD timeout=1000, int tryCount=5)
[実行] ECHO送信
const TYP * Ref(void) const
[取得] ポインタ取得