32{
33 std::vector<std::string> output;
34
36
37 struct addrinfo* addrinfo = nullptr;
38 auto s = getaddrinfo(hostname.c_str(), nullptr, nullptr, &addrinfo);
39
40 if (s != 0) {
42 return output;
43 }
44
45 for (auto rp = addrinfo; rp != nullptr; rp = rp->ai_next) {
46 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
47
48
49 if (rp->ai_family == AF_INET6)
50 continue;
51
52 getnameinfo(rp->ai_addr, rp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
53 auto ipaddr = std::string(hbuf);
54 bool duplicate = false;
55 for (auto& ip : output) {
56 if (ip == ipaddr) {
57 duplicate = true;
58 break;
59 }
60 }
61 if (!duplicate) {
62 TLOG_DEBUG(13) <<
"Found address " << ipaddr <<
" for hostname " << hostname;
63 output.push_back(ipaddr);
64 }
65 }
66
67 freeaddrinfo(addrinfo);
68
69 return output;
70}
#define TLOG_DEBUG(lvl,...)
void error(const Issue &issue)