Programming Tips - MSVC: warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead

Date: 2023jan11 Language: C/C++ Q. MSVC: warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead A. Its best not to hide this warning. inet_addr() doesn't support IPv6 and doesn't return a nice error. So replace:
if ((addr = inet_addr("192.168.1.1")) == (in_addr_t)-1) { // Invalid address }
With:
#include <Ws2tcpip.h> ... if ((inet_pton(AF_INET, "192.168.1.1", &addr)) != 1) { // Invalid address perror("inet_pton"); }