inet_addr()

inet_addr()

inet_addr()的功能是將一個點分十進制的IP轉換成一個長整數型數(u_long類型)

基本介紹

  • 中文名:inet_addr()函式
  • 別稱:IP位址轉化函式
  • 表達式:inet_addr(const char *cp);
  • 套用學科:計算機編程,C++
  • 適用領域範圍:網路
  • 功能:點分十進制IP轉換網路位元組序IP
基本介紹,英文原意,基本注釋,基本要求,編程舉例,

基本介紹

原型in_addr_t inet_addr(const char *cp);
參數:字元串,一個點分十進制的IP位址
返回值
如果正確執行將返回一個無符號長整數型數。如果傳入的字元串不是一個合法的IP位址,將返回INADDR_NONE。
頭檔案:
Winsock2.h (windows)
arpa/inet.h (Linux)

英文原意

The Windows Sockets inet_addr function converts a string containing an (Ipv4) Internet Protocol dotted address into a proper address for the IN_ADDR structure.
unsigned long inet_addr(const char FAR *cp );
Parameters
cp
[in] Null-terminated character string representing a number expressed in the Internet standard ".'' (dotted) notation.
Return Values
If no error occurs, inet_addr returns an unsigned long value containing a suitable binary representation of the Internet address given. If the string in the cp parameter does not contain a legitimate Internet address, for example if a portion of an "a.b.c.d" address exceeds 255, then inet_addr returns the value INADDR_NONE.
Remarks The inet_addr function interprets the character string specified by the cp parameter. This string represents a numeric Internet address expressed in the Internet standard ".'' notation. The value returned is a number suitable for use as an Internet address. All Internet addresses are returned in IP's network order (bytes ordered from left to right). If you pass in " " (a space) to the inet_addr function, inet_addr returns zero.

相關詞條

熱門詞條

聯絡我們