[转]关于VS2013下inet_ntoa函数不能使用的问题

https://blog.csdn.net/Zxiuqi/article/details/49888727

发现在VS2013,64位的Windows系统中不能再使用老旧函数inet_addr(),inet_ntoa()等了。。

例如使用inet_ntoa()时,会报如下错误提示:

错误 1 error C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings d:\opencv program\tcpserver\tcpserver\server.cpp 31 1 TCPServer

对于该问题的较稳妥的解决方案如下:(该解决方案只针对windows,64位,vs2013)

在程序开始添加头文件:

 #include<WS2tcpip.h>

对于: inet_ntoa(addr2.sin_addr);

将其等价替换为

扫描二维码关注公众号,回复: 2523807 查看本文章

char sendBuf[20] = {'\0'};
inet_ntop(AF_INET,(void*)&addr2.sin_addr,sendBuf,16);

对于: addr.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");

等价替换为: inet_pton(AF_INET, "127.0.0.1", (void*)&addr.sin_addr.S_un.S_addr);

猜你喜欢

转载自blog.csdn.net/xian_wwq/article/details/81390767
今日推荐