Why does WSAStringToAddress accept a non-constant AddressString?

The Windows documentation for WSAStringToAddress states:

INT WSAAPI WSAStringToAddress( _In_ LPTSTR AddressString, _In_ INT AddressFamily, _In_opt_ LPWSAPROTOCOL_INFO lpProtocolInfo, _Out_ LPSOCKADDR lpAddress, _Inout_ LPINT lpAddressLength ); 

AddressString parameter _In_ , not parameter _Inout_ . I don’t understand why the API accepts a non-constant pointer and causes a compilation failure, because I have const char* .

My first question is: why does WSAStringToAddress accept a non-continent pointer?

My second question is: is it safe to discard the consistency? Will WSAStringToAddress change the char* argument?


Here is more history ... I'm trying to use WSAStringToAddress in replacing inet_addr due to deprecated warnings in modern versions of Visual Studio.

Here is the same problem that is being discussed in the question with the answer provided by Petar Korponaich . A similar problem arose with Korponich. Its reason for the extra copy:

 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(&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 *)&ss, &size) == 0) ... } 
+6
source share

All Articles