network programming: Socket function: Address family Vs Protocol family
I just started with network programming. When looking at the socket function some use PF_INET and others use AF_INET. Looked in wikipedia, it says such design was used to enable the usage of different address families by different protocol families. Are there any such protocol families today which support multiple address types?
Also I came across this error when I was searching for Address family Vs Protocol family:
Address family not supported by protocol family
Does this mean there are protocols supporting multiple address families?
I came across this statement
you shouldn't necessarily开发者_运维问答 expect to be able to use NS addresses with ARPA Internet protocols
What are NS addresses?
Thanks.
The Windows documentation for socket
says that the address family is the first argument; the man page on my Linux box says that that should be the protocol family. The Linux version seems slightly more correct from a platform-agnostic perspective -- in theory, the socket has a protocol family and the addresses have address families, and the two should be compatible.
In practice, though, the PF_
and AF_
macros for the built-in protocols have the same values (in both Linux and Windows). I imagine it's a similar story for most OSes, since all the common protocol families have one address family. (You'd think IP would have two, but nope. There are separate protocol families for IPv4 and IPv6.) This (along with C's relatively weak typing) allows them to be used pretty much interchangeably.
Note that there's no guarantee about this being the case for all OSes, or for protocols supported by some third-party driver, etc. In those cases, you should consult the documentation for your particular platform.
As for what "NS addresses" are, far as i can tell, they're part of Xerox's prehistoric Network Systems protocol (a protocol family sorta like TCP/IP, but distinct and incompatible and unused by modern PCs). You won't see them in use unless you're working with archaic systems; why that was kept as an example is beyond me.
精彩评论