Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As <a href="https://stackoverflow.com/a/10773280/134633">n.m. says</a>, on Cygwin <code>res_init()</code> does not populate <code>_res.nsaddr_list</code> if it is using the Windows resolver. It uses the Windows resolver if either <code>/etc/resolv.conf</code> does not exist, or <code>/etc/resolv.conf</code> contains <code>options osquery</code>.</p> <p>In my opinion this is a Cygwin bug - returning a negative <code>nscount</code> is bogus - but nonetheless we are stuck with working around it.</p> <p>The solution is to call <code>GetNetworkParams()</code> just as Cygwin does itself - here's what I'm doing as a fallback:</p> <pre><code>#include &lt;windows.h&gt; #include &lt;iphlpapi.h&gt; #include &lt;netinet/in.h&gt; #include &lt;arpa/inet.h&gt; if (_res.nscount &lt; 0) { ULONG buflen = 0; FIXED_INFO *buf = NULL; if (GetNetworkParams(NULL, &amp;buflen) == ERROR_BUFFER_OVERFLOW) buf = malloc(buflen); if (buf &amp;&amp; GetNetworkParams(buf, &amp;buflen) == NO_ERROR) { _res.nscount = 1; _res.nsaddr_list[0].sin_family = AF_INET; _res.nsaddr_list[0].sin_addr.s_addr = inet_addr(buf-&gt;DnsServerList.IpAddress.String); _res.nsaddr_list[0].sin_port = htons(53); } free(buf); } </code></pre> <p>You need to link against <code>-liphlpapi</code> for the <code>GetNetworkParams()</code> function.</p> <p>This only takes the first Windows DNS address, but if you want the rest of them you can follow the linked list that <code>GetNetworkParams()</code> returns. <code>GetNetworkParams()</code> only returns IPv4 addresses, I'm not sure what you're supposed to do if the machine has an IPv6 DNS server address configured.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload