3

When building a solution in Visual Studio 2013 of a project, I noticed that I am getting warnings for the following references:

warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\JCSocket.cpp 77 1
warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\JCSocket.cpp 82 1
warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\JCSocket.cpp 121 1
warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings src\core\MuninNodeServer.cpp 64 1
warning C4996: 'GetVersionExW': was declared deprecated src\plugins\disk\DiskTimeMuninNodePlugin.cpp 48 1
warning C4996: 'GetVersion': was declared deprecated src\plugins\external\ConsolePipe.cpp 12 1
warning C4996: 'GetVersionExW': was declared deprecated src\plugins\PerfCounterMuninNodePlugin.cpp 56 1
warning C4996: 'GetVersionExW': was declared deprecated src\plugins\uptime\UptimeMuninNodePlugin.cpp 34 1

Whenever I try to change it to the recommended IntelliSense command, it is saying:

IntelliSense: identifier "inet_ntop" is undefined \src\core\MuninNodeServer.cpp 64 31

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
Dean
  • 43
  • 1
  • 1
  • 6

2 Answers2

3

These errors are telling you what to do. Microsoft is nice like that.

gethostbyname -> getaddrinfo
inet_addr -> inet_pton
inet_ntoa -> inet_ntop

As far as GetVersionExW and GetVersion Microsoft recommends using the appropriate Version Helper Function.

thnee
  • 5,817
  • 3
  • 27
  • 23
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 1
    I am still getting an error that the new replaced command is undefined when I change for instance inet_ntoa -> inet_ntop. Where shall I define it? – Dean Nov 15 '14 at 15:51
  • @Dean Meaning you're still getting the same errors? If so use Ctrl + Shift + F and search all your source files in the solution for `gethostname`, `inet_addr`, `inet_ntoa`, `GetVersionExW` and `GetVersion`. Also make sure you rebuilt your code, Ctrl + F7. – Jonathan Mee Nov 15 '14 at 15:55
  • Thanks for the hints, tried replacing only one and still getting Error 1 error C3861: 'inet_ntop': identifier not found \src\core\MuninNodeServer.cpp – Dean Nov 15 '14 at 16:02
  • @Dean Check out the links I provided when replacing each function. For `inet_ntop` you need to include Ws2tcpip.h and link in the Ws2_32.lib/dll. – Jonathan Mee Nov 15 '14 at 16:13
  • Great, I managed the links, however the arguments are options, will need to research further. How and where in the VS Project do I link the DLL lib? – Dean Nov 15 '14 at 16:57
  • @Dean This question probably has the answers that you are looking for: http://stackoverflow.com/q/5220309/2642059 – Jonathan Mee Nov 15 '14 at 17:36
  • 1
    For ``GetVersion`` and ``GetVersionEx``, see [this](http://stackoverflow.com/questions/22303824/warning-c4996-getversionexw-was-declared-deprecated) stackoverflow thread. – Chuck Walbourn Dec 05 '14 at 21:05
  • @thnee Well that was an embarrassing typo. Thanks for catching that. – Jonathan Mee Jul 25 '16 at 15:37
1

Visual Studio tells you this warning cause you trying to use unsecure function which means includes the body of the function

and the body can obviously contain a signed overflow and there's a prospect to get another compiling errors or perhaps its not supported in the newer library

by the way, its about how you use this function


Simply you can disable the warning by add the following line

#pragma warning( disable : 4996)

at the top of your code

Which disable warning error code 4996 and will work fine without any problems.

Another way:

  1. from the Solution Explorer right click on the project and choose Properties
  2. navigate to Configuration Properties >> C/C++ >> Advanced
  3. at the end just put 4996 in disable specific warning and click Apply >> Ok

Note: I prefer code way at all, It's more good to learn if you're not programming in visual studio or making a header file for your library

  • I think your answer is incomplete, you just give a solution to ignore warnings (I know question is not clear). The problem could be elsewhere: for example using a newer version of the lib (he said he followed recommandations but it didn't work). But this is my opinion. Please edit your answer to remove some of your **bold** words, that'll make it easier to read/understand. – N0un Jul 13 '17 at 07:37
  • Sorry for that..I edited the answer to be more clear –  Jul 13 '17 at 09:55