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

gct
  • 14,100
  • 15
  • 68
  • 107

3 Answers3

5

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.

ldx
  • 3,984
  • 23
  • 28
  • This relates to another post I made [here](http://stackoverflow.com/questions/10899814/af-unix-socket-overhead) in which I am seeing a significant amount of overhead sending data through AF_UNIX pipes (betwee 200 and 300 bytes it would seem). So if there's no protocol headers I'm very confused. – gct Jun 05 '12 at 18:22
  • There is some overhead inside the kernel when data is copied between the source and destination sockets, though it's not a protocol overhead per se. Inside the kernel this copying is optimized somewhat to make skb memory allocation not hog too much memory, see e.g. net/unix/af_unix.c unix_stream_sendmsg(). – ldx Jun 05 '12 at 20:08
  • I have a pretty passing familiarity with kernel land, so the unix_stream_sendmsg() is a little beyond me, but I can't imagine there's 200+ bytes of overhead is there? That's what I'm seeing. – gct Jun 05 '12 at 21:07
  • 1
    If I use a pipe I can push exactly the amount of data I think I should be able to, so the unix domain sockets are definitely adding some sort of overhead... – gct Jun 06 '12 at 13:48
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

  • I know they support protocol 0, but as far as I know that just tells it to use the default, I'm curious what that default is. – gct Jun 05 '12 at 18:23
  • 1
    @gct: The protocol is AF_UNIX, which means it is using interprocess communication via a file to communicate. The protocol name is PF_UNIX. –  Jun 05 '12 at 18:31
2

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

Look at socket(2) and unix(7)

KurzedMetal
  • 12,540
  • 6
  • 39
  • 65