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

The Count picture The Count · Apr 18, 2016 · Viewed 43.6k times · Source

I'm using Visual Studio 2015 and attempting to compile code that has worked before I updated from VS 2013.

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

partner.sin_addr.s_addr = inet_addr(ip.c_str());

I attempted to use the functions mentioned but they were undefined. I attempted to define the macro in many different spots but nothing happened. Another thread said that I should include Ws2tcpip.h instead of WinSock2 & add Ws2_32.lib. I already have the library added, and when I used the include nothing happened. What is going on?!

Answer

Florian Haupt picture Florian Haupt · Apr 18, 2016

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".