IP位址轉換函式

2021-06-12 00:38:13 字數 681 閱讀 3757

ip位址轉換函式:

unsigned long inet_addr (const char *cp);

inet_addr將乙個點分十進位制ip位址字串轉換成32位數字表示的ip位址(網路位元組順序)。

char* inet_ntoa (struct in_addr in);

inet_ntoa將乙個32位數字表示的ip位址轉換成點分十進位制ip位址字串。

這兩個函式互為反函式

位元組順序轉換

htons()--"host to network short"

htonl()--"host to network long"

ntohs()--"network to host short"

ntohl()--"network to host long"

*注意:在你的資料放到網路上的時候,確信它是網路位元組順序

網路位元組順序(大端位元組)和x86機器位元組順序(小端位元組)

eg:0x3132  在x86上顯示21  在網路傳輸中為12

**:here

博主所有文章已**私人部落格 

joe 的個人部落格

,謝謝關注!

IP位址轉換函式

include in addr t inet addr const char strptr 點分十進位制ipv4位址轉換為網路ipv4位址,失敗返回inaddr none int inet aton const char cp,struct in addr inp 點分十進位制ipv4位址轉換為網路...

IP位址轉換函式

常見的ip位址格式類似192.168.10.1,這是乙個ipv4格式的位址,但是這種格式只是為了方便使用者對其操作。若要計算機能夠識別,需要先將其由文字格式轉換為二進位制格式。早期linux系統中常用以下函式轉換ip位址 int inet aton const char cp,struct in a...

ip位址轉換數字函式 iton IP位址轉換函式

在ascii字串 192.168.0.99 與網路位元組序的二進位制值間轉換位址。涉及函式的標頭檔案為 include 一 只適用於ipv4協議的函式 int inet aton const char string,struct in addr addr 函式成功,返回值1,否則返回零。將strin...