title: GetAddrInfo example from Wikipedia won't work
body: <p>I've been learning how to use getaddrinfo() recently. I referred to Wikipedia for an example:
  <a href="http://en.wikipedia.org/wiki/Getaddrinfo" rel="nofollow">http://en.wikipedia.org/wiki/Getaddrinfo</a><br/>
  I made some small modifications to the example code to compile it with Visual C++ 2005.<br/>
  The modified version is as follows:<br/></p>
  
  <pre><code>int main(){
  
  // Initialize Winsock
  iResult = WSAStartup(MAKEWORD(2,2), &amp;wsaData);
  
  if (iResult != 0) {
      printf("WSAStartup failed with error: %d\n", iResult);
      return 1;
  }
  
  struct addrinfo *res;
  int error;
  
  /* resolve the domain name into a list of addresses */
  error = getaddrinfo("www.example.com", NULL, NULL, &amp;result);
  if (error != 0)
  {
      fprintf(stderr, "%d\n", error); 
      fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
  
      exit(EXIT_FAILURE);
  }   
  
  /* loop over all returned results and do inverse lookup */
  for (res = result; res != NULL; res = res-&gt;ai_next)
  {   
      char hostname[NI_MAXHOST] = "";
  
      error = getnameinfo(res-&gt;ai_addr, res-&gt;ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0); 
      if (error != 0)
      {
          fprintf(stderr, "%d\n", WSAGetLastError());
          fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
          continue;
      }
      if (*hostname != '\0')
          printf("hostname: %s\n", hostname);
  }   
  
  freeaddrinfo(result);
  
  getchar();
  
  return 0;
  }
  </code></pre>
  
  <p>The execution result is surprisingly failed with a return error:<code>WSANO_DATA</code>.
  Nevertheless, I can connect to <code>www.example.com</code> with Google Chrome.<br/>
  I've also replaced <code>www.example.com</code> with other domain names in the code and done tests. Some of the results are expected while some others are strange:</p>
  
  <blockquote>
    <p>test: localhost<br/>
    hostname: localhost<br/>
    <br/>
    test: www.yahoo.com.tw<br/>
    hostname: w2.rc.vip.gq1.yahoo.com<br/>
    hostname: w2.rc.vip.sp1.yahoo.com<br/></p>
  </blockquote>
  
  <p>The first result is as expected, but the second(www.yahoo.com.tw) is strange. I can't connect to "w2.rc.vip.gq1.yahoo.com" and "w2.rc.vip.sp1.yahoo.com" via the browser.</p>
  
  <p><b>Could anyone explain why I got the above results and why the original example from Wikipedia didn't work? Thanks a lot.</b></p>