为什么我用不了inet_ntop这个函数

tankfg 2009-06-03 09:57:00
最近搞IPV6的开发,可是我用不了inet_ntop 和 inet_pton这两个函数,而且msdn上也没有这两个函数的介绍。
我目前引入的头文件有这些。
#include <iostream>
#include <WinSock2.h>
#include <WS2tcpip.h>
在网上查到的好多要用
tpipv6.h这个头文件,但是再看安装过程的时候,都是说2k要安装那个补丁包,xp不需要啊。我现在操作系统是xp sp3.
往达人们指点一二。
...全文
3121 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
weikemin 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 proad 的回复:]
这是Linux下专用函数。Windows下用inet_addr
[/Quote]

不错。
jim_brook 2009-08-15
  • 打赏
  • 举报
回复
二楼的同志,你好像说错了哟。
inet_addr 是把IPv4点分十进制地址串转换成网络字节序地址;
而inet_ntop 和 inet_pton这两个函数是用于IPv6的。
另外,楼主:msdn上有关于这两个函数的介绍,你没有找到,是因为你的msdn版本太低。建议到微软msdn网页上查询,能找到。

嘻嘻,不知所云。
tankfg 2009-06-03
  • 打赏
  • 举报
回复
哦,原来是这个样子啊,看来网上教程有的也靠不住啊。呵呵。
blackcat242 2009-06-03
  • 打赏
  • 举报
回复
哦,看错函数了
proad 2009-06-03
  • 打赏
  • 举报
回复
这是Linux下专用函数。Windows下用inet_addr
blackcat242 2009-06-03
  • 打赏
  • 举报
回复
Platform SDK: Windows Sockets 2
inet_ntoa
The inet_ntoa function converts an (Ipv4) Internet network address into a string in Internet standard dotted format.

char* FAR inet_ntoa(
struct in_addr in
);

Parameters
in
[in] Pointer to an in_addr structure that represents an Internet host address.
Return Values
If no error occurs, inet_ntoa returns a character pointer to a static buffer containing the text address in standard ".'' notation. Otherwise, it returns NULL.
Remarks
The inet_ntoa function takes an Internet address structure specified by the in parameter and returns an ASCII string representing the address in ".'' (dot) notation as in "a.b.c.d.'' The string returned by inet_ntoa resides in memory that is allocated by Windows Sockets. The application should not make any assumptions about the way in which the memory is allocated. The data is guaranteed to be valid until the next Windows Sockets function call within the same thread—but no longer. Therefore, the data should be copied before another Windows Sockets call is made.

Requirements
Client Requires Windows "Longhorn", Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header Declared in Winsock2.h.

Library Link to Ws2_32.lib.

DLL Requires Ws2_32.dll.

See Also
Winsock Reference, Winsock Functions, SOCKADDR, inet_addr

我的msdn中有描述
资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 在计算机网络编程中,IP地址的转换是一项常见任务,尤其是随着IPv4和IPv6的广泛应用。将点分十进制IP地址转换为网络字节序的二进制数值,以及进行反向转换,变得至关重要。inet_pton()和inet_ntop()函数是现代网络编程中用于处理IPv4和IPv6地址转换的常用函数inet_pton()函数能够将点分十进制格式的IP地址转换为适用于网络传输的二进制数值。该函数支持IPv4和IPv6地址,是随着IPv6发展而引入的。其函数原型为: 其中,family参数用于指定地址族,AF_INET表示IPv4地址,AF_INET6表示IPv6地址。strptr是指向包含点分十进制IP地址字符串的指针,addrptr是指向足够大内存块的指针,用于存储转换后的二进制数值。函数返回值为1表示成功,0表示输入字符串无效,-1表示出现错误。例如,将IPv4地址“..*.**”转换为二进制数值的代码如下: inet_ntop()函数则用于将网络字节序的二进制数值转换为点分十进制格式的IP地址字符串。其函数原型为: family参数同样指定地址族类型,addrptr是指向二进制数值的指针,strptr是用于存储转换后字符串的缓冲区,len参数指定缓冲区大小。函数成功时返回指向转换后字符串的指针,出错时返回NULL。对于IPv4地址,传统的inet_ntoa()函数也可以实现网络字节序IPv4地址到点分十进制字符串的转换,但其返回值指向静态分配的内存,多次调用会导致值被覆盖。而inet_pton()和inet_ntop()函数在转换过程中无需额外处理字节顺序问题,它们自身已解决了网络字节序和主机字节序的转换。例如,使用inet_ntop()将二进制数值转换为点分十进制格式的代码如下: 总之,ine

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧