title: Why does WSAStringToAddress take a non-const AddressString?
body: <p>The Windows documentation for <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms742214(v=vs.85).aspx">WSAStringToAddress</a> states:</p>
  
  <pre class="lang-c prettyprint-override"><code>INT WSAAPI WSAStringToAddress(
    _In_     LPTSTR             AddressString,
    _In_     INT                AddressFamily,
    _In_opt_ LPWSAPROTOCOL_INFO lpProtocolInfo,
    _Out_    LPSOCKADDR         lpAddress,
    _Inout_  LPINT              lpAddressLength
  );
  </code></pre>
  
  <p><code>AddressString</code> an <strong><em><code>_In_</code></em></strong> parameter, and not an <strong><em><code>_Inout_</code></em></strong> parameter. Its not clear to me why the API takes a non-const pointer, and its causing a compile failure because I have a <code>const char*</code>.</p>
  
  <p>My first question is, why does <code>WSAStringToAddress</code> take a non-const pointer?</p>
  
  <p>My second question is, is it safe to cast the const-ness away? Will <code>WSAStringToAddress</code> modify the <code>char*</code> argument?</p>
  
  <hr>
  
  <p>Here's more of the back story... I'm trying to use <code>WSAStringToAddress</code> in an <code>inet_addr</code> replacement due to deprecated warnings under contemporary versions of Visual Studio.</p>
  
  <p>Here's the same problem detailed in a question with an <a href="https://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found/20816961#20816961">answer provided by Petar Korponaić</a>. Korponaić experienced the same problem. Its the reason for the extra copy:</p>
  
  <pre class="lang-c prettyprint-override"><code>int inet_pton(int af, const char *src, void *dst)
  {
    struct sockaddr_storage ss;
    int size = sizeof(ss);
    char src_copy[INET6_ADDRSTRLEN+1];
  
    ZeroMemory(&amp;ss, sizeof(ss));
    /* stupid non-const API */
    strncpy (src_copy, src, INET6_ADDRSTRLEN+1);
    src_copy[INET6_ADDRSTRLEN] = 0;
  
    if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&amp;ss, &amp;size) == 0)
    ...
  }
  </code></pre>