'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS

Just to make the conversion clear. Let's say you have code using the deprecated inet_addr as in this example:

RecvAddr.sin_addr.s_addr = inet_addr("192.168.1.1");

It could be converted to the newer InetPton as follows:

InetPton(AF_INET, _T("192.168.1.1"), &RecvAddr.sin_addr.s_addr);

The _T macro prevents the "const char incompatible with PCWSTR" error.


The ip string can be converted to the in_addr structure with the InetPton function. It is used like this:

InetPton(AF_INET, strIP, &ipv4addr)

You need to include the "Ws2tcpip.h" header file, use the library "Ws2_32.lib" and DLL "Ws2_32.dll".


You can try

#pragma warning(disable:4996) 

for using inet_addr().

Tags:

C++

Winsock