我希望了解 UDP 標頭,我發現它實際上是 24 位
struct sockaddr_in {
short sin_family; // e.g. AF_INET //4 bytes
unsigned short sin_port; // e.g. htons(3490) //4 bytes
struct in_addr sin_addr; // see struct in_addr, below //8 bytes
char sin_zero[8]; // zero this if you want to //8 bytes
};
struct in_addr {
unsigned long s_addr; // load with inet_aton()
};
根據這個解釋,它是 16 個位元組。由于 sin_zero[8] 沒有在任何地方使用它是 16 位元組?UDP HEADER結構體大小仍然是 24 位元組。我錯過了什么嗎?
謝謝!
uj5u.com熱心網友回復:
您的問題是用于表示套接字地址的 C 結構。
它與實際通過網路發送的 UDP 標頭不同。
基本上,IPv4 標頭是 20 個位元組,而其上的 UDP 標頭是 8 個位元組,正如 Geeks for Geeks 參考在您的問題中所解釋的那樣。
我建議查看https://en.wikipedia.org/wiki/User_Datagram_Protocol,或安裝 Wireshark 并捕獲 UDP 資料包以查看它的外觀。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/447838.html
