Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winsock deprecated no warnings

I am trying to create a UDP multicast socket program using VS2015 (C++ console application).

I got the following error,

Error   C4996   'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings mulitcast_listener

I tried to add _WINSOCK_DEPRECATED_NO_WARNINGS symbol to my project settings via "Project"->"Properties"->"Configuration properties"->"C/C++"->"Preprocessor"->"Preprocessor definitions" .. But still it says the same.

And then I tried to add symbol above #include "stdafx.h" like

#define _WINSOCK_DEPRECATED_NO_WARNINGS 1

and then No(/sdl-) on "Project"->"Properties"->"Configuration properties"->"C/C++"->General->SDL checks

now I get a error message saying

Warning C4603   '_WINSOCK_DEPRECATED_NO_WARNINGS': macro is not defined or definition is different after precompiled header

Finally I tried to implement

inet_pton(AF_INET, HELLO_GROUP, (PVOID *)(&mreq.imr_multiaddr.s_addr));

instead of

mreq.imr_multiaddr.s_addr = inet_addr(HELLO_GROUP);

I need to understand why the error didn't resolved even after adding the _WINSOCK... macro.

Thanks in advance.

like image 214
kar Avatar asked Aug 26 '15 18:08

kar


2 Answers

While the previous advice works, it is ignoring the purpose of stdafx.h. The idea is that you place #include statements for header files that don't change frequently inside stdafx.h in order to make use of precompiled headers. Therefore you should ideally place

#define _WINSOCK_DEPCRECATED 

inside stdafx.h, before other #include statements that it affects, in particular before including winsock2.h or other winsock related headers.

like image 154
Dunc Avatar answered Nov 17 '22 01:11

Dunc


As noted in the comments, the solution is to make sure that the line

#define _WINSOCK_DEPRECATED_NO_WARNINGS

is placed after

#include "stdafx.h"

but before the other #include statements.

like image 44
Aify Avatar answered Nov 17 '22 01:11

Aify