我google了一下,有人說「保持與struct sockaddr相同的大小」。但是Kernel不會直接使用sockaddr(對吧?)。使用它時。內核將把它重新轉換成它的內容。那麼爲什麼零填充需要?爲什麼在sockaddr_in中需要零填充?
struct sockaddr {
unsigned short sa_family; // address family, AF_xxx
char sa_data[14]; // 14 bytes of protocol address
};
struct sockaddr_in {
short sin_family; // e.g. AF_INET, AF_INET6
unsigned short sin_port; // e.g. htons(3490)
struct in_addr sin_addr; // see struct in_addr, below
char sin_zero[8]; // zero this if you want to
};
struct in_addr {
unsigned long s_addr; // load with inet_pton()
};
隨着免責聲明,我完全沒有已知的水域: 它可能是endiannes? – 2013-03-25 06:21:01
@ G.Stoynev我不知道... 16字節對齊? – louxiu 2013-03-25 06:25:26
它在這裏被擴展...... http://silviocesare.wordpress.com/2007/10/22/setting-sin_zero-to-0-in-struct-sockaddr_in/ – 2013-03-25 06:49:13