我用谷歌搜索了它,有些人说“与 struct sockaddr 保持相同的大小”。但是内核不会直接使用 sockaddr (对吧?)。使用时。内核会将其转换回原来的样子。那么为什么需要零填充呢?
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()
};