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

Function resolveHostname

plugins/check_ping.cpp:234–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234static bool resolveHostname(const std::wstring& hostname, bool ipv6, std::wstring& ipaddr)
235{
236 ADDRINFOW hints;
237 ZeroMemory(&hints, sizeof(hints));
238
239 if (ipv6)
240 hints.ai_family = AF_INET6;
241 else
242 hints.ai_family = AF_INET;
243
244 if (l_Debug)
245 std::wcout << L"Resolving hostname \"" << hostname << L"\"\n";
246
247 ADDRINFOW *result = NULL;
248 DWORD ret = GetAddrInfoW(hostname.c_str(), NULL, &hints, &result);
249
250 if (ret) {
251 std::wcout << L"Failed to resolve hostname. Error " << ret << L": " << formatErrorInfo(ret) << L"\n";
252 return false;
253 }
254
255 wchar_t ipstringbuffer[46];
256
257 if (ipv6) {
258 struct sockaddr_in6 *address6 = (struct sockaddr_in6 *)result->ai_addr;
259 InetNtop(AF_INET6, &address6->sin6_addr, ipstringbuffer, 46);
260 }
261 else {
262 struct sockaddr_in *address4 = (struct sockaddr_in *)result->ai_addr;
263 InetNtop(AF_INET, &address4->sin_addr, ipstringbuffer, 46);
264 }
265
266 if (l_Debug)
267 std::wcout << L"Resolved to \"" << ipstringbuffer << L"\"\n";
268
269 ipaddr = ipstringbuffer;
270 return true;
271}
272
273static int check_ping4(const printInfoStruct& pi, response& response)
274{

Callers 1

wmainFunction · 0.85

Calls 1

formatErrorInfoFunction · 0.85

Tested by

no test coverage detected