title: How to use getaddrinfo() on windows
body: <p>I'm trying to build my APP with mingw+msys.</p>
  
  <p>My code usee winsock. When I compile it I take following error message:</p>
  
  <pre><code>$ gcc -o sample sample.c -lws2_32
      C:\Users\user\AppData\Local\Temp\ccsdWlQR.o:sample.c:(.text+0xeb): undefined reference to `getaddrinfo'
      collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>This is my code that is migrated from Linux with changing some headers.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;WinSock2.h&gt;
  #include &lt;WS2tcpip.h&gt;
  
  main(int argc,char *argv[])
  {
      WSADATA wsaData;
      WSAStartup(MAKEWORD(2,2), &amp;wsaData);
  
      printf("Hello world with winsock");
  
      int sock;
      char *hostAddress;
      struct addrinfo hints,*res;
      int err;
      memset(&amp;hints,0,sizeof(hints));
      hints.ai_family = AF_UNSPEC; 
      hints.ai_socktype = SOCK_DGRAM;
      getaddrinfo("127.0.0.1",12345,&amp;hints,&amp;res);
  
      printf("getaddrinfo %s\n",strerror(errno));
      printf("getaddrinfo : %s \n",gai_strerror(err));
  
  
      struct sockaddr_in *addr;
      struct addrinfo *rp;
      for (rp = res; rp != NULL; rp = rp-&gt;ai_next) {
          addr = (struct sockaddr_in *)rp-&gt;ai_addr; 
          printf("dstPort  = %d\n",ntohs(addr-&gt;sin_port));
          printf("dstAddr  = %s\n",inet_ntoa((struct in_addr)addr-&gt;sin_addr));
          hostAddress = inet_ntoa((struct in_addr)addr-&gt;sin_addr);    
      }
      WSACleanup( );                                    
  
  }
  </code></pre>
  
  <p>How can I use <code>gettarrinfo()</code> in Windows?</p>
  
  <p>This is the additional information that message is changed after trying  dgreenday's article.</p>
  
  <pre><code>sample.c:22:2: warning: passing argument 2 of 'getaddrinfo' makes pointer from i
  nteger without a cast [enabled by default]
    getaddrinfo("124.0.0.1",12345,&amp;hints,&amp;res);
    ^
  In file included from sample.c:4:0:
  c:\mingw\include\ws2tcpip.h:391:12: note: expected 'const char *' but argument i
  s of type 'int'
   int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
  </code></pre>