title: How does gcc/cygwin get the DNS server?
body: <p>I have some code I'm writing under cygwin (using GCC) that successfully uses gethostbyname(); however when I try to use the resolver directly to retrieve the IP address of the DNS server it fails (all entries in nsaddr_list[] are null and nscount is -1).
  If gethostbyname() is working, then obviously it is able to connect to the DNS server.<br>
  This code...</p>
  
  <pre><code>    if (res_init() == -1) {
          fprintf(stderr,"res_init() failed\n");
          exit(1);
      }
  
      if (_res.nscount &lt;= 0) {
          fprintf(stderr,"nscount = %d\n",_res.nscount);
      }
      else {
          for(i=0;i&lt;_res.nscount;i++) {
              fprintf(stderr, "dnssrvr: %d.%d.%d.%d\n",
                  (_res.nsaddr_list[i].sin_addr.s_addr &amp; 0xff) &gt;&gt; 0,
                  (_res.nsaddr_list[i].sin_addr.s_addr &amp; 0xff00) &gt;&gt; 8,
                  (_res.nsaddr_list[i].sin_addr.s_addr &amp; 0xff0000) &gt;&gt; 16,
                  (_res.nsaddr_list[i].sin_addr.s_addr &amp; 0xff000000) &gt;&gt; 24);
          }
      }
  </code></pre>
  
  <p>works on unix/linux, but returns nscount=-1 on cygwin.
  Is there some trick to getting the DNS server when using cygwin/gcc?</p>