7

I'm curious what the default protocol is for an AF_UNIX SOCK_STREAM socket. I'm trying to track down exactly what the packet overhead should be, but I can't figure out what protocol is used by default. I suspect it's not IPPROTO_TCP because this:

socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) 

works while, this:

socketpair(AF_UNIX, SOCK_STREAM, IPPROTO_TCP, sfd) 

Gives a "Protocol not supported error".

4

3 回答 3

4

Since an AF_UNIX unix socket is a local thing, there's no such thing as added protocol overhead in this case. You can use it in SOCK_STREAM or SOCK_DGRAM mode to make it connection-oriented or connectionless, respectively, but that's all: no protocol headers are added and it traverses none of the network or transport protocol implementations in the network stack.

于 2012-06-05T17:37:09.943 回答
4

AF stands for A ddress F amily whereas PF stands for P rotocol F amily.

The AF_UNIX family does not have a protocol IPPROTO_TCP that is supported by that address family. AF_UNIX is for interprocess communications between processes on the same system in the UNIX® domain. The AF_UNIX and AF_UNIX_CCSID address family supports a protocol of 0 for both SOCK_STREAM and SOCK_DGRAM.

Read more here: Sockets

于 2012-06-05T17:56:42.497 回答
2

The only valid "protocol" when using AF_UNIX is zero.

Look at socket(2) and unix(7)

于 2012-06-05T17:42:07.767 回答