inet_ntoa

inet_ntoa的原型是char*inet_ntoa,作業系統是Win2000 Professional或更高版本,參數是一個網路上的IP位址。

基本介紹

功能:

將一個十進制網路位元組序轉換為點分十進制IP格式的字元串。

原型:

頭檔案:

arpa/inet.h

Winsock2.h

參數:

一個網路上的IP位址

返回值:

如果正確,返回一個字元指針,指向一塊存儲著點分格式IP位址的靜態緩衝區(同一執行緒內共享此記憶體);錯誤,返回NULL。

英文原意

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.

基本要求

作業系統:Windows 2000 Professional 或更高版本

頭檔案:Winsock2.h

程式庫:Ws2_32.lib

參見:

編程舉例

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)。

相關詞條

熱門詞條

聯絡我們