title: getaddrinfo: A non-recoverable error occurred during a database lookup
body: <p>I'm getting this weird error from <code>getaddrinfo()</code> on Windows 10 when running the following C program:</p>
  
  <p><a href="https://gist.github.com/anonymous/4406cb031791afba29e5" rel="nofollow">https://gist.github.com/anonymous/4406cb031791afba29e5</a></p>
  
  <p>Here is the relevant part of the code that calls <code>getaddrinfo()</code>:</p>
  
  <pre><code>  int error;
    socket_t sock;
    struct sockaddr_in addr;
    struct addrinfo ai_hints, *ai_result, *ai_cur;
    #ifdef _WIN32
      int wsa_error;
      WSADATA wsa_data;
    #endif
  
    if (argc &lt; 3) {
      fprintf(stderr, "Usage: %s &lt;host&gt; &lt;port&gt;\n", argv[0]);
      return 1;
    }
  
    #ifdef _WIN32
      wsa_error = WSAStartup(MAKEWORD(2, 2), &amp;wsa_data);
      if (wsa_error != 0) {
        fprintf(stderr, "WSAStartup: %s\n",
            get_error_string(wsa_error, NULL, 0));
        return 2;
      }
    #endif
  
    puts("Hello, World!");
  
    sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (sock == -1) {
      fprintf(stderr, "socket: %s\n",
          get_error_string(get_socket_error(), NULL, 0));
      return 3;
    }
  
    memset(&amp;ai_hints, sizeof(ai_hints), 0);
    ai_hints.ai_family = AF_UNSPEC;
    ai_hints.ai_protocol = IPPROTO_TCP;
    ai_hints.ai_socktype = SOCK_STREAM;
  
    error = getaddrinfo(argv[1], argv[2], &amp;ai_hints, &amp;ai_result);
    if (error != 0) {
      fprintf(stderr, "getaddrinfo: %s\n", error);
      close(sock);
      return 4;
    }
  </code></pre>
  
  <p>Each time the program gets run it no matter what hostname and port I pass through the command line it outputs the following:</p>
  
  <pre><code>Hello, World!
  getaddrinfo: A non-recoverable error occurred during a database lookup.
  </code></pre>
  
  <p>I've also written a corresponding server program and it worked great (checked with telnet!).</p>
  
  <p>Can you see anything wrong with my code?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It appears to work fine on Linux, <code>getaddrinfo()</code> is not giving any errors there and the client is able to connect to my server.</p>