I'm learning about socket programming. An example of int socketpair(int domain, int type, int protocol, int sv[2])
I've been studying changed the domain
argument from AF_LOCAL
to PF_LOCAL
without explanation. Googling for "AF_LOCAL vs. PF_LOCAL" led me to forums where users debated without conclusion whether they were the same or not. What is actually the relationship between these AF_*
and PF_*
values, and if they are the same, why do both exist?

- 5,314
- 4
- 44
- 86
-
1_The manifest constants used under 4.x BSD for protocol families are PF_UNIX, PF_INET, and so on, while AF_UNIX, AF_INET, and so on are used for address families. However, already the BSD man page promises: "The protocol family generally is the same as the address family", and subsequent standards use AF_* everywhere._ excerpt from https://linux.die.net/man/2/socket – alvits May 17 '17 at 01:47
-
Similar question asked previously here: http://stackoverflow.com/questions/6729366/what-is-the-difference-between-af-inet-and-pf-inet-in-socket-programming – user3905264 May 17 '17 at 01:48
1 Answers
At least in linux (socket.h) they are defined to be the same value. (Even though technically, the definition of what they stand for is slightly different)
Quoting from the accepted answer to a similar question regarding AF_INET vs PF_INET. What is the difference between AF_INET and PF_INET in socket programming?
In some documentation, you'll see mention of a mystical "PF_INET". This is a weird etherial beast that is rarely seen in nature, but I might as well clarify it a bit here. Once a long time ago, it was thought that maybe a address family (what the "AF" in "AF_INET" stands for) might support several protocols that were referenced by their protocol family (what the "PF" in "PF_INET" stands for). That didn't happen. Oh well. So the correct thing to do is to use AF_INET in your struct sockaddr_in and PF_INET in your call to socket(). But practically speaking, you can use AF_INET everywhere. And, since that's what W. Richard Stevens does in his book, that's what I'll do here.

- 1
- 1

- 3,175
- 1
- 14
- 27