错误 C4996 ‘inet_ntoa‘: Use inet_ntop() or InetNtop() instead or define _WINS

简介: 错误 C4996 ‘inet_ntoa‘: Use inet_ntop() or InetNtop() instead or define _WINS

严重性    代码    说明    项目    文件    行    禁止显示状态

错误    C4996    'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings    Server    c:\users\wh\desktop\server\server\server.cpp    55    

解决方法:


将inetntoa改为inet_ntop()或者 InetNtop() 添加


#include <Ws2tcpip.h>  头文件



客户端:


      sockaddr_in serAddr;

       serAddr.sin_family = AF_INET;

       serAddr.sin_port = htons(8888);

       inet_pton(AF_INET, "127.0.0.1", &serAddr.sin_addr.S_un.S_addr);

       if (connect(sclient, (sockaddr *)&serAddr, sizeof(serAddr)) == SOCKET_ERROR)

       {  //连接失败

           printf("connect error !");

           closesocket(sclient);

           return 0;

       }


服务端:


char ip[100];

       if (inet_ntop(AF_INET, &remoteAddr.sin_addr.S_un.S_addr, ip, 100) == NULL)

       {

           cout << "error" << endl;

           return -1;

       }

       cout << ip << endl;    //宽字符记得用宽字符的方式进行输出


目录
相关文章
|
1月前
|
网络协议 Unix Linux
`AF_INET`
`AF_INET`
16 3
|
1月前
|
网络协议 Linux C++
Linux C/C++ 网络编程中地址格式转换(inet_pton和inet_ntop函数)
Linux C/C++ 网络编程中地址格式转换(inet_pton和inet_ntop函数)
26 0
|
1月前
|
网络协议 Unix
`AF_UNIX` 和 `AF_LOCAL`
`AF_UNIX` 和 `AF_LOCAL`
24 1
|
1月前
|
网络协议 Unix API
`AF_INET6`
`AF_INET6`
21 2
|
网络协议 Linux
tcp/ip源码(18)——struct inet_sock中的cork用途
作者:gfree.wind@gmail.com 博客:linuxfocus.blog.chinaunix.net 在前面的学习过程中,遇到了位于struct inet_sock中的cork,当时没有把这个变量搞得很明白,没有完全搞清这个变量的用途。
1269 0
|
网络协议 C++ 索引
TCP/IP源码(21)——struct inet_socks
本文的copyleft归gfree.wind@gmail.com所有,使用GPL发布,可以自由拷贝,转载。但转载请保持文档的完整性,注明原作者及原链接,严禁用于任何商业用途。 作者:gfree.wind@gmail.com 博客:linuxfocus.blog.chinaunix.net     在前面的博文中,我画出了TCP/IP数据包发送的流程图。
1524 0
内核中的UDP socket流程(5)——inet_create
内核中的UDP socket流程(5)——inet_create 作者:gfree.wind@gmail.com 原文:http://blog.chinaunix.net/space.
1025 0
|
数据安全/隐私保护 网络协议 Ubuntu
|
数据安全/隐私保护 网络协议 Ubuntu