gct
gct

Reputation: 14583

Default protocol for AF_UNIX sockets

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".

Upvotes: 7

Views: 4403

Answers (3)

user195488
user195488

Reputation:

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

Upvotes: 4

KurzedMetal
KurzedMetal

Reputation: 12946

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

Look at socket(2) and unix(7)

Upvotes: 2

ldx
ldx

Reputation: 4084

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.

Upvotes: 5

Related Questions