typedef uint16_t in_port_t; // Internet address. --- IPV4 typedef uint32_t in_addr_t; struct in_addr{ in_addr_t s_addr; }; // IPv6 address struct in6_addr { union { uint8_t __u6_addr8[16]; } __in6_u; }; // Structure describing an Internet socket address --- IPV4 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)]; }; /* Ditto, for IPv6. */ 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 in_addr 仅一个成员, s_addr (uint32_t) struct in6_addr 仅一个成员 __u6_addr ( uint8_t [16]) IPV4: socket_in 共4个成员: unsignedshort sin_family --> 协议族类型 uint16_t sin_port --> 端口号 struct in_addr sin_addr --> ip地址 unsigned char sin_zero --> IPV6: socket_in6 共4个成员: uint16_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{ unsignedshort sa_family; /* address family */ char sa_data[14]; /* up to 14 bytes of direct address */ };