In general, I can to call getaddrinfo with the following parameters:
my_ADDRINFOA = {0};
my_ADDRINFOA.ai_family = AF_UNSPEC;
my_ADDRINFOA.ai_socktype = SOCK_STREAM;
my_ADDRINFOA.ai_protocol = IPPROTO_TCP;
my_ADDRINFOA.ai_flags = AI_V4MAPPED | AI_ALL;
In this case, both IPv4 and IPv6 are returned.
Although rfc3493 says the following about the AI_V4MAPPED and AI_ALL flags:
If the AI_V4MAPPED flag is specified along with an ai_family ofAF_INET6, then getaddrinfo() shall return IPv4-mapped IPv6 addresses on finding no matching IPv6 addresses
In this case, in this case, both the mapping from IPv4 to IPv6 and real IPv6 are returned, although the RFC seems to clearly say that the mapping from IPv4 to IPv6 should be returned only if there are no suitable IPv6 addresses, but they are.
If the AI_ALL flag is used with the AI_V4MAPPED flag, then getaddrinfo() shall return all matching IPv6 and IPv4 addresses.
For example, when using the DNS, queries are made for both AAAArecords and A records, and getaddrinfo() returns the combinedresults of both queries. Any IPv4 addresses found are returned as IPv4-mapped IPv6 addresses.
In this case, I have IPv4 - they are returned exactly as 32-bit regular IPv4.
And IPv6 is like 128 bit.
The AI_ALL flag without the AI_V4MAPPED flag is ignored. When ai_family is not specified (AF_UNSPEC), AI_V4MAPPED and AI_ALL flags will only be used if AF_INET6 is supported.
In general, on the one hand, it worked, on the other, if I understood everything correctly, then not quite clearly following the RFC.