Understanding struct sockaddr

后端 未结 2 1707
清酒与你
清酒与你 2020-12-14 02:11
struct sockaddr {
    unsigned short sa_family;   // address family, AF_xxx
    char           sa_data[14]; // 14 bytes of protocol address
};

In t

2条回答
  •  长情又很酷
    2020-12-14 02:47

    The format and size of the address is usually protocol specific.

    sockaddr is used as the base of a set of address structures that act like a discriminated union, see the Beej guide to networking. You generally look at the sa_family and then cast to the appropriate address family's specific address structure.

    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.

    See also:

    • 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

提交回复
热议问题