Dear Maintainer,
Under certain circumstances, when calling getaddrinfo with hints.ai_family = AF_UNSPEC, the first result is an AF_INET address. When calling it with hints.ai_family = AF_INET, however, it returns 251 (No address associated with hostname).
Here is a short program that reproduces the issue:
```c
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
int main(int argc, char *argv[]) {
const char hostname[] = "SomeHostname";
const char service[] = "1433";
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
int ret = getaddrinfo(hostname, service, &hints, &res);
assert(ret == 0);
assert(res->ai_family == AF_INET);
freeaddrinfo(res);
hints.ai_family = AF_INET;
ret = getaddrinfo(hostname, service, &hints, &res);
if (ret != 0) {
printf(gai_strerror(ret));
printf("\n");
} else {
freeaddrinfo(res);
}
return ret;
}
```
I have only been able to reproduce the bug when all of the following criteria are met:
- Running in a Docker container on a Windows host
- The hostname is unqualified
- The container's /etc/resolv.conf does not include the correct search option to resolve the hostname
- The Windows host is set up to resolve unqualified names by applying the correct DNS suffix
getaddrinfo() also returns 251 if the AI_ADDRCONFIG flag is set, even though the container has an IPV4 address.
The bug is also present in 2.34-0experimental3.
Symptoms are superficially similar to #854301, but the container is online and passing AI_ADDRCONFIG returns no result.