DnsQuery doesn’t have a parameter to specify the server one wants to query. On the other hand, I’ve seen this sample, which seems to have passed an IP in the parameter marked as “reserved and must be 0” in the MSDN documentation.
Is there some way to query a specific server (as nslookup does?) Or am I going to have to write my own DNS client (or find a library of course)?
The 4th argument of DnsQuery
PVOID pExtraaccepts aPIP4_ARRAYcontaining the specific DNS servers to be queried. This is combined with the 3rd argumentDWORD Optionsof DNS_QUERY_BYPASS_CACHE , in order to bypass the resolver cache.This has worked since Windows 2000, and in Windows XP DnsQuery calls the function
called privateNarrowToWideQuery (in dnsapi.dll) and takes the
pExtraargument is as the PIP4_ARRAY.The MSDN is inaccurate in this regard , resulting in this being an undocumented feature.
In older versions of the DnsQuery API Call
pExtraused to be calledaipServers.Regarding the DNS of IPV6 AAAA records, you can try the function with the second argument
WORD wTypeasDNS_TYPE_AAAAand the fifth argumentPDNS_RECORD *ppQueryResultsSetas a pointer toDNS_AAAA_DATA. Though this still forces you to pass in IPV4 IP address array and not IPV6.Regarding Windows Version support for the IPV6 queries see the following references
In future Windows versions, I believe the correct way to do this for IPV6 will be using
DnsQueryEx, with its first argument ofPDNS_QUERY_REQUEST pQueryRequestwhich containsa member
PDNS_ADDR_ARRAY pDnsServerList;, which contains memberWORD Family;which specifies which type of IP address the DNS server is.Whether DnsQuery already supports a pointer to PDNS_ADDR_ARRAY as an argument to
PVOID pExtraor will be modified in future Windows Versions to do so, I am not sure, but you are welcome to try and see.See How to use the DnsQuery function to resolve host names and host addresses with Visual C++ .NET for sample code, as you have already discovered.
Also see the following similar SO Question.