linux inet_ntoa函数

inet_ntoa
 

目录

1基本介绍

2英文原意

3基本要求

4编程举例

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)转换成字符串形式。

你可能感兴趣的:(linux,函数,inet_ntoa)