日常筆記in addr

2021-08-13 16:02:50 字數 971 閱讀 7999

#include

函式樣式

structin_addr

;

結構體in_addr 用來表示乙個32位的ipv4位址。

in_addr_t

一般為 32位的unsigned int,其位元組順序為網路順序(network byte ordered),即該無符號整數採用大端位元組序 。

其中每8位代表乙個ip位址位中的乙個數值。

例如192.168.3.144記為0xc0a80390,其中 c0 為192 ,a8 為 168, 03 為 3 , 90 為 144

列印的時候可以呼叫inet_ntoa()函式將其轉換為char *型別。

[cpp]view plain

copy

print

?#include

#include

#include

#include

#include

int main(int argc, char *argv)   

#include #include #include #include #include int main(int argc, char *argv)

實際執行結果如下:

192.168.0.74 : 192.168.0.74 //從這裡可以看出,printf裡的inet_ntoa(addr2)先於inet_ntoa(addr1)執行。

192.168.0.74

211.100.21.179

inet_ntoa返回乙個char *,而這個char *的空間是在inet_ntoa裡面靜態分配的,所以inet_ntoa後面的呼叫會覆蓋上一次的呼叫。第一句printf的結果只能說明在printf裡面的可變引數的求值是從右到左的,僅此而已。

hostent和in addr結構體

一.hostent資料結構是這樣的 struct hostent typedef uint32 t in addr t struct in addr 這裡是這個資料結構的詳細資料 struct hostent h name 位址的正式名稱。h aliases 空位元組 位址的預備名稱的指標。h ad...

日常筆記 vim

終於要學習 vim 了 為什麼要學習 vim?想想看,當你有乙個 100m 的 txt 文件需要編輯的時候 你相用文字編輯器做?孩子 那速度得等到天荒地老 這裡記錄一下我的 vim 學習過程 筆記。如下,我有下面的接近 900000 行的 txt 檔案,我需要將其中的 850001 行之後的文字貼上...

oracle 日常筆記

1.替換文字 update table name set field name replace field name from str to str where 說明 table name 表的名字 field name 欄位名 from str 需要替換的字串 to str 替換成的字串 2.排序...