linux inet_ntoa函数

inet_ntoa
 

1基本介绍

功能:
将一个IP转换成一个互联网标准点分格式的字符串。
原型:
char FAR * inet_ntoa( struct in_addr  in);
头文件:
arpa/inet.h
Winsock2.h
参数:
一个网络上的IP地址
返回值:
如果正确,返回一个字符 指针,指向一块存储着点分格式IP地址的静态缓冲区(同一线程内共享此内存);错误,返回NULL。

2英文原意

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] 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.

3基本要求

操作系统:Windows 2000 Professional 或更高版本
头文件:Winsock2.h
链接库:Ws2_32.lib
参见:

4编程举例

SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");
char recvBuf[100];
char tempBuf[100];
sprintf(tempBuf,"%s say: %s",inet_ntoa(addrSrv.sin_addr),recvBuf);
//将sin_addr储存的IP(127.0.0.1)转换成字符串形式。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值