How are Unix domain sockets related to networking?

3

I understand that networking uses sockets as well but I am wondering if Unix domain (IPC) sockets somehow relate to network layer. If so, does this use network HW somehow? Does it work like a loopback? If not, then why are listed by netstat in Linux ?

ps-aux

Posted 2014-11-29T13:35:24.520

Reputation: 3 397

Answers

2

Unix domain sockets share the same semantics as regular sockets but that's about it, the underlying code has nothing to do with the network layer. They provide an efficient means of communication for processes on the same host (IPC) where network-like semantics are desirable (listen, connect ...)

See What is the cost of establishing connection using Unix Domain sockets vs TCP sockets for example:

Messages sent through TCP sockets have to go all the way through the networking stack to the loopback interface (which is a virtual network interface device typically called "lo" on Unix-style systems), and then back up to the receiving socket. The networking stack code tacks on TCP and IP headers, makes routing decisions, forwards a packet to itself through "lo", then does more routing and strips the headers back off. Furthermore, because TCP is a networking protocol, the connection establishment part of it has all kinds of added complexity to deal with dropped packets. Most significantly for you, TCP has to send three messages just to establish the connection (SYN, SYN-ACK, and ACK).

In the case of unix sockets the kernel can bypass all this and just pass the data between the two processes so there is less overhead.

Googling around you might come across some benchmarks.

lemonsqueeze

Posted 2014-11-29T13:35:24.520

Reputation: 1 151

Fair enough. So only the semantics are there, but otherwise not related to network at all, right? So why they are part of netstat output? – ps-aux – 2014-11-29T16:28:40.933

1From a networking point of view it may seem strange indeed, but you could also see netstat's job as listing active sockets, and zealously it tells about unix sockets as well. You can get it back on track with netstat --tcp --udp though... – lemonsqueeze – 2014-11-29T16:41:42.887