129extern "C" int getaddrinfo(
const char* nodename,
const char* service,
const addrinfo* hints, addrinfo** result) {
130 if (result ==
nullptr) {
134 if (nodename ==
nullptr) {
138 const bool negative = std::strcmp(nodename, kNegativeHost) == 0;
140 const bool positive = std::strcmp(nodename, kPositiveHost) == 0;
141 const bool partial = std::strcmp(nodename, kPartialHost) == 0;
142 const bool link_local = std::strcmp(nodename, kLinkLocalHost) == 0;
143 const bool queued_cancel = std::strcmp(nodename, kQueuedCancelHost) == 0;
144 if (!positive && !negative && !partial && !link_local && !queued_cancel) {
160 std::this_thread::sleep_for(std::chrono::milliseconds(1));
165 const int family = hints ==
nullptr ? AF_UNSPEC : hints->ai_family;
166 if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6) {
170 const unsigned short port = ParsePort(service);
171 if (partial && family == AF_INET) {
175 std::this_thread::sleep_for(std::chrono::milliseconds(4));
177 addrinfo* head =
nullptr;
178 addrinfo* tail =
nullptr;
180 if (positive || partial || queued_cancel) {
181 if (family == AF_UNSPEC || family == AF_INET6) {
182 ok = AppendAddress(&head, &tail, AF_INET6, hints, port,
"::1") &&
183 AppendAddress(&head, &tail, AF_INET6, hints, port,
"::2");
185 if (ok && (family == AF_UNSPEC || family == AF_INET)) {
186 ok = AppendAddress(&head, &tail, AF_INET, hints, port,
"127.0.0.1") &&
187 AppendAddress(&head, &tail, AF_INET, hints, port,
"127.0.0.2");
189 }
else if (family == AF_INET6) {
190 ok = AppendAddress(&head, &tail, AF_INET6, hints, port,
"fe80::1");
191 }
else if (family == AF_UNSPEC) {
192 ok = AppendAddress(&head, &tail, AF_INET6, hints, port,
"fe80::1") &&
193 AppendAddress(&head, &tail, AF_INET, hints, port,
"127.0.0.1");
195 ok = AppendAddress(&head, &tail, AF_INET, hints, port,
"127.0.0.1");
198 if (!ok || head ==
nullptr) {
199 FreeAddressList(head);