更新时间:2022-10-17 17:58:53
罪_
办法 SOCKADDR_IN
,艾_
办法 addrinfo中的
, SA _
办法的sockaddr
。我不知道有关取值_
在 in_addr等
。套接字API在设计时考虑到pre-标准的80年代初的C编译器,它可能有对所有结构
成员单个命名空间。
Pretty simple questions. And yes, maybe not (that) important, but I'm really curious what do they mean and I couldn't find their meanings.
// ipv4
struct sockaddr_in {
short int sin_family; // Address family, AF_INET
unsigned short int sin_port; // Port number
struct in_addr sin_addr; // Internet address
unsigned char sin_zero[8]; // Same size as struct sockaddr
};
// ipv4
struct in_addr {
uint32_t s_addr; // that's a 32-bit int (4 bytes)
};
// ipv6
struct addrinfo {
int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc.
int ai_family; // AF_INET, AF_INET6, AF_UNSPEC
int ai_socktype; // SOCK_STREAM, SOCK_DGRAM
int ai_protocol; // use 0 for "any"
size_t ai_addrlen; // size of ai_addr in bytes
struct sockaddr *ai_addr; // struct sockaddr_in or _in6
char *ai_canonname; // full canonical hostname
struct addrinfo *ai_next; // linked list, next node
};
// ipv6
struct sockaddr {
unsigned short sa_family; // address family, AF_xxx
char sa_data[14]; // 14 bytes of protocol address
};
sin_
means sockaddr_in
, ai_
means addrinfo
, sa_
means sockaddr
. I'm not sure about the s_
in in_addr
. The sockets API was designed with pre-standard early 1980s C compilers in mind, which might have had a single namespace for all struct
members.