1 .\" Copyright (c) 1983, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" From: @(#)socket.2 8.1 (Berkeley) 6/4/93
40 .Nd create an endpoint for communication
47 .Fn socket "int domain" "int type" "int protocol"
52 creates an endpoint for communication and returns a descriptor.
56 argument specifies a communications domain within which
57 communication will take place; this selects the protocol family
59 These families are defined in the include file
61 The currently understood formats are:
63 .Bd -literal -offset indent -compact
64 PF_LOCAL Host-internal protocols, formerly called PF_UNIX,
65 PF_UNIX Host-internal protocols, deprecated, use PF_LOCAL,
66 PF_INET Internet version 4 protocols,
67 PF_PUP PUP protocols, like BSP,
68 PF_APPLETALK AppleTalk protocols,
69 PF_ROUTE Internal Routing protocol,
70 PF_LINK Link layer interface,
71 PF_IPX Novell Internet Packet eXchange protocol,
72 PF_RTIP Help Identify RTIP packets,
73 PF_PIP Help Identify PIP packets,
74 PF_ISDN Integrated Services Digital Network,
75 PF_KEY Internal key-management function,
76 PF_INET6 Internet version 6 protocols,
77 PF_NATM Native ATM access,
79 PF_NETGRAPH Netgraph sockets
82 The socket has the indicated
84 which specifies the semantics of communication.
88 .Bd -literal -offset indent -compact
89 SOCK_STREAM Stream socket,
90 SOCK_DGRAM Datagram socket,
91 SOCK_RAW Raw-protocol interface,
92 SOCK_RDM Reliably-delivered packet,
93 SOCK_SEQPACKET Sequenced packet stream
98 type provides sequenced, reliable,
99 two-way connection based byte streams.
100 An out-of-band data transmission mechanism may be supported.
104 datagrams (connectionless, unreliable messages of
105 a fixed (typically small) maximum length).
108 socket may provide a sequenced, reliable,
109 two-way connection-based data transmission path for datagrams
110 of fixed maximum length; a consumer may be required to read
111 an entire packet with each read system call.
112 This facility is protocol specific, and presently unimplemented.
114 sockets provide access to internal network protocols and interfaces.
117 which is available only to the super-user, and
120 but not yet implemented, are not described here.
125 specifies a particular protocol to be used with the socket.
126 Normally only a single protocol exists to support a particular
127 socket type within a given protocol family.
128 However, it is possible
129 that many protocols may exist, in which case a particular protocol
130 must be specified in this manner.
131 The protocol number to use is
133 .Dq "communication domain"
134 in which communication
135 is to take place; see
140 are full-duplex byte streams, similar
142 A stream socket must be in a
144 state before any data may be sent or received
146 A connection to another socket is created with a
149 Once connected, data may be transferred using
153 calls or some variant of the
158 (Some protocol families, such as the Internet family,
159 support the notion of an
160 .Dq implied connect ,
161 which permits data to be sent piggybacked onto a connect operation by
165 When a session has been completed a
168 Out-of-band data may also be transmitted as described in
170 and received as described in
173 The communications protocols used to implement a
176 is not lost or duplicated.
177 If a piece of data for which the
178 peer protocol has buffer space cannot be successfully transmitted
179 within a reasonable length of time, then
180 the connection is considered broken and calls
181 will indicate an error with
185 in the global variable
187 The protocols optionally keep sockets
189 by forcing transmissions
190 roughly every minute in the absence of other activity.
191 An error is then indicated if no response can be
192 elicited on an otherwise
193 idle connection for an extended period (e.g.\& 5 minutes).
196 signal is raised if a process sends
197 on a broken stream; this causes naive processes,
198 which do not handle the signal, to exit.
201 sockets employ the same system calls
208 calls will return only the amount of data requested,
209 and any remaining in the arriving packet will be discarded.
214 sockets allow sending of datagrams to correspondents
218 Datagrams are generally received with
220 which returns the next datagram with its return address.
224 system call can be used to specify a process group to receive
227 signal when the out-of-band data arrives.
228 It may also enable non-blocking I/O
229 and asynchronous notification of I/O events
233 The operation of sockets is controlled by socket level
235 These options are defined in the file
241 system calls are used to set and get options, respectively.
243 A -1 is returned if an error occurs, otherwise the return
244 value is a descriptor referencing the socket.
248 system call fails if:
250 .It Bq Er EPROTONOSUPPORT
251 The protocol type or the specified protocol is not supported
254 The per-process descriptor table is full.
256 The system file table is full.
258 Permission to create a socket of the specified type and/or protocol
261 Insufficient buffer space is available.
262 The socket cannot be created until sufficient resources are freed.
284 .%T "An Introductory 4.3 BSD Interprocess Communication Tutorial"
289 .%T "BSD Interprocess Communication Tutorial"
296 system call appeared in