了解struct sockaddr [英] Understanding struct sockaddr
问题描述
struct sockaddr {
unsigned short sa_family; // address family, AF_xxx
char sa_data[14]; // 14 bytes of protocol address
};
在此结构中,sa_family
描述的地址族的含义是什么?
In this structure what exactly is the meaning address family depicted by sa_family
?
这是否意味着TCP/UDP之类的协议具有地址"?好吧,我认为协议可以是标识号而不是地址.
Does it mean that protocols like TCP/UDP have "addresses"? Well, the protocols can be identification numbers not addresses, I think.
无论如何,如果是的话,那么他们的家庭是根据什么来分居的?
Anyway, if yes, then on what basis have their families been divided?
推荐答案
地址的格式和大小通常是特定于协议的.
The format and size of the address is usually protocol specific.
sockaddr
用作一组类似于已区分联合的地址结构的基础,请参见 https://beej.us/guide/bgnet/html/multi/sockaddr_inman.html .通常,您先查看sa_family
,然后将其转换为适当的地址族的特定地址结构.
sockaddr
is used as the base of a set of address structures that act like a discriminated union, see https://beej.us/guide/bgnet/html/multi/sockaddr_inman.html. You generally look at the sa_family
and then cast to the appropriate address family's specific address structure.
TCP和UDP本身没有特定的地址,而是IP级别的IPv4和IPv6地址大小不同.
TCP and UDP do not have addresses specific to them as such, rather the IP level has different sizes of address for IPv4 and IPv6.
另请参阅:
- http://en.wikipedia.org/wiki/AF_INET
- http://msdn.microsoft. com/en-us/library/ms740496(v = vs.85).aspx
- http://www.iana.org /assignments/address-family-numbers/address-family-numbers.xml
- http://en.wikipedia.org/wiki/AF_INET
- http://msdn.microsoft.com/en-us/library/ms740496(v=vs.85).aspx
- http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml
这篇关于了解struct sockaddr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!