Understanding struct sockaddr

狂风中的少年 提交于 2019-11-28 21:22:32
Len Holgate

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 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 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:

I found this out when trying to duplicate the jnetpcap getHardwareAddress() method in C/C++. The MAC address is contained, when sa_family is 17 (0x11, AF_PACKET), in bytes 10-15.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!