MCPcopy Create free account
hub / github.com/Icinga/icinga2 / check_ping4

Function check_ping4

plugins/check_ping.cpp:273–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273static int check_ping4(const printInfoStruct& pi, response& response)
274{
275 if (l_Debug)
276 std::wcout << L"Parsing ip address" << '\n';
277
278 in_addr ipDest4;
279 LPCWSTR term;
280 if (RtlIpv4StringToAddress(pi.ip.c_str(), TRUE, &term, &ipDest4) == STATUS_INVALID_PARAMETER) {
281 std::wcout << pi.ip << " is not a valid ip address\n";
282 return 3;
283 }
284
285 if (*term != L'\0') {
286 std::wcout << pi.ip << " is not a valid ip address\n";
287 return 3;
288 }
289
290 if (l_Debug)
291 std::wcout << L"Creating Icmp File\n";
292
293 HANDLE hIcmp;
294 if ((hIcmp = IcmpCreateFile()) == INVALID_HANDLE_VALUE)
295 goto die;
296
297 DWORD dwRepSize = sizeof(ICMP_ECHO_REPLY) + 8;
298 void *repBuf = reinterpret_cast<VOID *>(new BYTE[dwRepSize]);
299
300 if (repBuf == NULL)
301 goto die;
302
303 unsigned int rtt = 0;
304 int num = pi.num;
305
306 LARGE_INTEGER frequency;
307 QueryPerformanceFrequency(&frequency);
308
309 do {
310 LARGE_INTEGER timer1;
311 QueryPerformanceCounter(&timer1);
312
313 if (l_Debug)
314 std::wcout << L"Sending Icmp echo\n";
315
316 if (!IcmpSendEcho2(hIcmp, NULL, NULL, NULL, ipDest4.S_un.S_addr,
317 NULL, 0, NULL, repBuf, dwRepSize, pi.timeout)) {
318 response.dropped++;
319 if (l_Debug)
320 std::wcout << L"Dropped: Response was 0" << '\n';
321 continue;
322 }
323
324 if (l_Debug)
325 std::wcout << "Ping recieved" << '\n';
326
327 PICMP_ECHO_REPLY pEchoReply = static_cast<PICMP_ECHO_REPLY>(repBuf);
328
329 if (pEchoReply->Status != IP_SUCCESS) {
330 response.dropped++;

Callers 1

wmainFunction · 0.85

Calls 1

printErrorInfoFunction · 0.85

Tested by

no test coverage detected