1.\" Copyright (c) 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)unix.4 8.1 (Berkeley) 06/09/93 7.\" 8.Dd 9.Dt UNIX 4 10.Os 11.Sh NAME 12.Nm unix 13.Nd UNIX-domain protocol family 14.Sh SYNOPSIS 15.Fd #include <sys/types.h> 16.Fd #include <sys/un.h> 17.Sh DESCRIPTION 18The 19.Tn UNIX Ns -domain 20protocol family is a collection of protocols 21that provides local (on-machine) interprocess 22communication through the normal 23.Xr socket 2 24mechanisms. 25The 26.Tn UNIX Ns -domain 27family supports the 28.Dv SOCK_STREAM 29and 30.Dv SOCK_DGRAM 31socket types and uses 32filesystem pathnames for addressing. 33.Sh ADDRESSING 34.Tn UNIX Ns -domain 35addresses are variable-length filesystem pathnames of 36at most 104 characters. 37The include file 38.Aq Pa sys/un.h 39defines this address: 40.Bd -literal -offset indent 41struct sockaddr_un { 42u_char sun_len; 43u_char sun_family; 44char sun_path[104]; 45}; 46.Ed 47.Pp 48Binding a name to a 49.Tn UNIX Ns -domain 50socket with 51.Xr bind 2 52causes a socket file to be created in the filesystem. 53This file is 54.Em not 55removed when the socket is closed\(em\c 56.Xr unlink 2 57must be used to remove the file. 58.Pp 59The 60.Tn UNIX Ns -domain 61protocol family does not support broadcast addressing or any form 62of 63.Dq wildcard 64matching on incoming messages. 65All addresses are absolute- or relative-pathnames 66of other 67.Tn UNIX Ns -domain 68sockets. 69Normal filesystem access-control mechanisms are also 70applied when referencing pathnames; e.g., the destination 71of a 72.Xr connect 2 73or 74.Xr sendto 2 75must be writable. 76.Sh PROTOCOLS 77The 78.Tn UNIX Ns -domain 79protocol family is comprised of simple 80transport protocols that support the 81.Dv SOCK_STREAM 82and 83.Dv SOCK_DGRAM 84abstractions. 85.Dv SOCK_STREAM 86sockets also support the communication of 87.Ux 88file descriptors through the use of the 89.Ar msg_control 90field in the 91.Ar msg 92argument to 93.Xr sendmsg 2 94and 95.Xr recvmsg 2 . 96.Pp 97Any valid descriptor may be sent in a message. 98The file descriptor(s) to be passed are described using a 99.Ar struct cmsghdr 100that is defined in the include file 101.Aq Pa sys/socket.h . 102The type of the message is 103.Dv SCM_RIGHTS , 104and the data portion of the messages is an array of integers 105representing the file descriptors to be passed. 106The number of descriptors being passed is defined 107by the length field of the message; 108the length field is the sum of the size of the header 109plus the size of the array of file descriptors. 110.Pp 111The received descriptor is a 112.Em duplicate 113of the sender's descriptor, as if it were created with a call to 114.Xr dup 2 . 115Per-process descriptor flags, set with 116.Xr fcntl 2 , 117are 118.Em not 119passed to a receiver. 120Descriptors that are awaiting delivery, or that are 121purposely not received, are automatically closed by the system 122when the destination socket is closed. 123.Sh SEE ALSO 124.Xr socket 2 , 125.Xr intro 4 126.Rs 127.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial" 128.%B PS1 129.%N 7 130.Re 131.Rs 132.%T "An Advanced 4.3 BSD Interprocess Communication Tutorial" 133.%B PS1 134.%N 8 135.Re 136