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

Function mapSystemNamesToFamiliarNames

plugins/check_network.cpp:307–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307static bool mapSystemNamesToFamiliarNames(std::map<std::wstring, std::wstring>& mapNames)
308{
309 /*
310 PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
311 PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL;
312 PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL;
313 PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsServer = NULL;
314 PIP_ADAPTER_PREFIX pPrefix = NULL;
315 */
316 ULONG outBufLen = 15000; //15KB as suggestet by msdn of GetAdaptersAddresses
317
318 if (l_Debug)
319 std::wcout << "Mapping adapter system names to friendly names\n";
320
321 PIP_ADAPTER_ADDRESSES pAddresses;
322
323 unsigned int Iterations = 0;
324 DWORD dwRetVal = 0;
325
326 do {
327 pAddresses = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(new BYTE[outBufLen]);
328
329 dwRetVal = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, pAddresses, &outBufLen);
330
331 if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
332 delete[]pAddresses;
333 pAddresses = NULL;
334 } else
335 break;
336 } while (++Iterations < 3);
337
338 if (dwRetVal != NO_ERROR) {
339 std::wcout << "Failed to collect friendly adapter names\n";
340 delete[]pAddresses;
341 return false;
342 }
343
344 for (PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses; pCurrAddresses; pCurrAddresses = pCurrAddresses->Next) {
345 if (l_Debug)
346 std::wcout << "Got: " << pCurrAddresses->Description << " -- " << pCurrAddresses->FriendlyName << '\n';
347
348 mapNames[pCurrAddresses->Description] = pCurrAddresses->FriendlyName;
349 }
350
351 delete[]pAddresses;
352 return true;
353}
354
355int wmain(int argc, WCHAR **argv)
356{

Callers 1

wmainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected