|
这四个类型的定义如下:
--------
struct sockaddr
{
__SOCKADDR_COMMON (sa_); /* Common data: address family and length. */
char sa_data[14]; /* Address data. */
};
--------
struct sockaddr_in
{
__SOCKADDR_COMMON (sin_);
in_port_t sin_port; /* Port number. */
struct in_addr sin_addr; /* Internet address. */
/* Pad to size of `struct sockaddr'. */
unsigned char sin_zero[sizeof (struct sockaddr) -
__SOCKADDR_COMMON_SIZE -
sizeof (in_port_t) -
sizeof (struct in_addr)];
};
--------
struct sockaddr_in6
{
__SOCKADDR_COMMON (sin6_);
in_port_t sin6_port; /* Transport layer port # */
uint32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* IPv6 scope-id */
};
--------
struct sockaddr_un
{
__SOCKADDR_COMMON (sun_);
char sun_path[108]; /* Path name. */
};
----------------------------------------------------------------
其中sockaddr是一个通用的结构,其他三个在进行函数调用时转换到sockaddr类型。sockaddr_in比sockaddr短所以需要补0。我没看懂的地方是,sockaddr_in6和sockaddr_un都比sockaddr长。也就是说sockaddr是介于sockaddr_in和sockaddr_in6/sockaddr_un之间的。它为什么被定义成这么一个尴尬的长度? |
|