UNIX(4F)

NAME
unix - UNIX domain protocol family

DESCRIPTION

The Unix Domain protocol family provides support for socket-based communication between processes running on the local host. While both SOCK_STREAM and SOCK_DGRAM types are supported, the SOCK_STREAM type often provides faster performance. Pipes, for instance, are built on Unix Domain SOCK_STREAM sockets.

Unix Domain SOCK_DGRAM sockets (also called datagram sockets) exist primarily for reasons of orthogonality under the BSD socket model. However, the overhead of reading or writing data is higher for the (connectionless) datagram sockets.

Unix Domain addresses are pathnames. In other words, two independent processes can communicate by specifying the same pathname as their communications rendezvous point. The bind(2) operation creates a special entry in the file system of type socket. If that pathname already exists (as a socket from a previous bind() operation, or as some other file system type), bind() will fail.

Sockets in the Unix domain protocol family use the following addressing structure:

    struct sockaddr_un {
    	short	sun_family;
    	u_short	sun_path[108];
    };

To create or reference a Unix Domain socket, the sun_family field should be set to AF_UNIX and the sun_path array should contain the path name of a rendezvous point.

Although Unix Domain sockets are faster than Internet Domain sockets for communication between local processes, the advantage of the additional flexibility afforded by the latter may outweigh performance issues. Where inter-process communication thoughput is critical, a shared memory approach may be preferred.

Since there are no protocol families associated with Unix Domain sockets, the protocol argument to socket(2) should be zero.

When setting up a Unix Domain socket, the length argument to the bind() call is the amount of space within the sockaddr_un structure, not including the pathname delimiter. One way to specify the length is:

    sizeof(addr.sun_family) + strlen(path) where addr is a structure of type sockaddr_un, and path is a pointer to the pathname.

The limit of 108 characters is an artifact of the implementation.

Since closing a Unix Domain socket does not make the file system entry go away, an application should remove the entry using unlink(2V), when finished.

SEE ALSO
bind(2), socket(2), unlink(2V)