33 std::vector<std::string> output;
37 struct addrinfo* addrinfo =
nullptr;
38 auto s = getaddrinfo(hostname.c_str(),
nullptr,
nullptr, &addrinfo);
45 for (
auto rp = addrinfo; rp !=
nullptr; rp = rp->ai_next) {
46 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
49 if (rp->ai_family == AF_INET6)
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) {
62 TLOG_DEBUG(13) <<
"Found address " << ipaddr <<
" for hostname " << hostname;
63 output.push_back(ipaddr);
67 freeaddrinfo(addrinfo);
75 std::string ipaddr =
"0.0.0.0";
76 char hostname[NI_MAXHOST];
77 if (gethostname(&hostname[0], NI_MAXHOST) == 0) {
78 ipaddr = std::string(hostname);
80 bool eth_found =
false;
81 if (eth_device_name !=
"") {
83 struct ifaddrs* ifaddr =
nullptr;
86 for (
auto ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next) {
87 if (ifa->ifa_addr ==
nullptr || std::string(ifa->ifa_name) != eth_device_name) {
92 int status = getnameinfo(ifa->ifa_addr,
sizeof(
struct sockaddr_in), ip, NI_MAXHOST,
nullptr, 0, NI_NUMERICHOST);
97 ipaddr = std::string(ip);
103 auto err = InterfaceNotFound(
ERS_HERE, eth_device_name);
105 if (throw_if_missing)