xref: /openbsd-src/share/man/man4/unix.4 (revision ce7e0fc6a9d74d25b78fb6ad846387717f5172b6)
1.\"	$OpenBSD: unix.4,v 1.5 2000/12/21 21:01:21 aaron Exp $
2.\"	$NetBSD: unix.4,v 1.3 1994/11/30 16:22:43 jtc Exp $
3.\"
4.\" Copyright (c) 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)unix.4	8.1 (Berkeley) 6/9/93
36.\"
37.Dd June 9, 1993
38.Dt UNIX 4
39.Os
40.Sh NAME
41.Nm unix
42.Nd UNIX-domain protocol family
43.Sh SYNOPSIS
44.Fd #include <sys/types.h>
45.Fd #include <sys/un.h>
46.Sh DESCRIPTION
47The
48.Tn UNIX Ns -domain
49protocol family is a collection of protocols
50that provides local (on-machine) interprocess
51communication through the normal
52.Xr socket 2
53mechanisms.
54The
55.Tn UNIX Ns -domain
56family supports the
57.Dv SOCK_STREAM
58and
59.Dv SOCK_DGRAM
60socket types and uses
61filesystem pathnames for addressing.
62.Sh ADDRESSING
63.Tn UNIX Ns -domain
64addresses are variable-length filesystem pathnames of
65at most 104 characters.
66The include file
67.Aq Pa sys/un.h
68defines this address:
69.Bd -literal -offset indent
70struct sockaddr_un {
71	u_char	sun_len;
72	u_char	sun_family;
73	char	sun_path[104];
74};
75.Ed
76.Pp
77Binding a name to a
78.Tn UNIX Ns -domain
79socket with
80.Xr bind 2
81causes a socket file to be created in the filesystem.
82This file is
83.Em not
84removed when the socket is closed\(em\c
85.Xr unlink 2
86must be used to remove the file.
87.Pp
88The
89.Tn UNIX Ns -domain
90protocol family does not support broadcast addressing or any form
91of
92.Dq wildcard
93matching on incoming messages.
94All addresses are absolute- or relative-pathnames
95of other
96.Tn UNIX Ns -domain
97sockets.
98Normal filesystem access-control mechanisms are also
99applied when referencing pathnames; e.g., the destination
100of a
101.Xr connect 2
102or
103.Xr sendto 2
104must be writable.
105.Sh PROTOCOLS
106The
107.Tn UNIX Ns -domain
108protocol family is comprised of simple
109transport protocols that support the
110.Dv SOCK_STREAM
111and
112.Dv SOCK_DGRAM
113abstractions.
114.Dv SOCK_STREAM
115sockets also support the communication of
116.Ux
117file descriptors through the use of the
118.Ar msg_control
119field in the
120.Ar msg
121argument to
122.Xr sendmsg 2
123and
124.Xr recvmsg 2 .
125.Pp
126Any valid descriptor may be sent in a message.
127The file descriptor(s) to be passed are described using a
128.Ar struct cmsghdr
129that is defined in the include file
130.Aq Pa sys/socket.h .
131The type of the message is
132.Dv SCM_RIGHTS ,
133and the data portion of the messages is an array of integers
134representing the file descriptors to be passed.
135The number of descriptors being passed is defined
136by the length field of the message;
137the length field is the sum of the size of the header
138plus the size of the array of file descriptors.
139.Pp
140The received descriptor is a
141.Em duplicate
142of the sender's descriptor, as if it were created with a call to
143.Xr dup 2 .
144Per-process descriptor flags, set with
145.Xr fcntl 2 ,
146are
147.Em not
148passed to a receiver.
149Descriptors that are awaiting delivery, or that are
150purposely not received, are automatically closed by the system
151when the destination socket is closed.
152.Sh SEE ALSO
153.Xr socket 2 ,
154.Xr netintro 4
155.Rs
156.%T "An Introductory 4.3 BSD Interprocess Communication Tutorial"
157.%B PS1
158.%N 7
159.Re
160.Rs
161.%T "An Advanced 4.3 BSD Interprocess Communication Tutorial"
162.%B PS1
163.%N 8
164.Re
165