MCPcopy Create free account
hub / github.com/actor-framework/actor-framework / resolve

Function resolve

libcaf_net/caf/net/ip.cpp:145–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143} // namespace
144
145std::vector<ip_address> resolve(std::string_view host) {
146 addrinfo hint;
147 memset(&hint, 0, sizeof(hint));
148 hint.ai_socktype = SOCK_STREAM;
149 hint.ai_family = AF_UNSPEC;
150 if (host.empty())
151 hint.ai_flags = AI_PASSIVE;
152 addrinfo* tmp = nullptr;
153 std::string host_str{host.begin(), host.end()};
154 if (getaddrinfo(host.empty() ? nullptr : host_str.c_str(),
155 host.empty() ? dummy_port.data() : nullptr, &hint, &tmp)
156 != 0)
157 return {};
158 std::unique_ptr<addrinfo, decltype(freeaddrinfo)*> addrs{tmp, freeaddrinfo};
159 char buffer[INET6_ADDRSTRLEN];
160 std::vector<ip_address> results;
161 for (auto i = addrs.get(); i != nullptr; i = i->ai_next) {
162 auto family = fetch_addr_str(buffer, i->ai_addr);
163 if (family != AF_UNSPEC) {
164 ip_address ip;
165 if (auto err = parse(buffer, ip))
166 log::net::error("could not parse IP address: {}", buffer);
167 else
168 results.emplace_back(ip);
169 }
170 }
171 // TODO: Should we just prefer ipv6 or use a config option?
172 // std::stable_sort(std::begin(results), std::end(results),
173 // [](const ip_address& lhs, const ip_address& rhs) {
174 // return !lhs.embeds_v4() && rhs.embeds_v4();
175 // });
176 return results;
177}
178
179std::vector<ip_address> resolve(ip_address host) {
180 return resolve(to_string(host));

Callers 2

WITH_FIXTUREFunction · 0.85

Calls 11

fetch_addr_strFunction · 0.70
parseFunction · 0.50
errorClass · 0.50
to_stringFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45
dataMethod · 0.45
getMethod · 0.45
emplace_backMethod · 0.45

Tested by 1

WITH_FIXTUREFunction · 0.68