title: winsock weirdness (c++)
body: <p>I am trying to implement a function called "inet_pton" which will convert a string representation of an IPv4 or IPv6 (like "66.102.1.147" [google]) into binary network-byte ordered form.  Here is the relevant part of my code:</p>
  
  <pre><code>#if defined WIN32
  int inet_pton (int af, const char *src, void *dst)
  
  {
      const void *data;
      size_t      len;
      struct      addrinfo hints, *res;
  
      hints.ai_family   = af;
      hints.ai_socktype = SOCK_STREAM; 
      hints.ai_protocol = IPPROTO_UDP;
      hints.ai_flags    = AI_NUMERICHOST;
  
      if (getaddrinfo (src, NULL, &amp;hints, &amp;res))
      {
          std::cout &lt;&lt; "ERROR : inet_pton() in " &lt;&lt; __FILE__ &lt;&lt; " at line " &lt;&lt; __LINE__ &lt;&lt; std::endl;
          std::cout &lt;&lt; "      : getaddrinfo() failed to get IP address info for \"" &lt;&lt; src &lt;&lt; "\"" &lt;&lt; std::endl;
          return 0;
      }
  ...
  </code></pre>
  
  <p>So src is the incoming IP string.  However, I always get an error like</p>
  
  <p>getaddrinfo() failed to get IP address info for "66.102.1.147"</p>
  
  <p>Can anyone with winsock experience comment?  I also tried another method, the function</p>
  
  <pre><code>WSAStringToAddress ((LPTSTR)src, af, NULL, (LPSOCKADDR) &amp;sa, &amp;address_length)
  </code></pre>
  
  <p>But it always returns the error code WSAEINVAL, indicating an invalid IP string.  This makes no sense to me.  I'm using VS2005 as my IDE.</p>