1 .\" $OpenBSD: socket.2,v 1.41 2016/03/19 22:10:49 guenther Exp $
2 .\" $NetBSD: socket.2,v 1.5 1995/02/27 12:37:53 cgd Exp $
4 .\" Copyright (c) 1983, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)socket.2 8.1 (Berkeley) 6/4/93
38 .Nd create an endpoint for communication
42 .Fn socket "int domain" "int type" "int protocol"
45 creates an endpoint for communication and returns a descriptor.
49 parameter specifies a communications domain within which
50 communication will take place; this selects the protocol family
52 These families are defined in the include file
54 The currently understood formats are:
56 .Bl -tag -width "AF_INET6XXX" -offset indent -compact
58 UNIX internal protocols
60 ARPA Internet protocols
62 IPv6 (Internet Protocol version 6) protocols
65 The socket has the indicated
67 which specifies the semantics of communication.
68 Currently defined types are:
70 .Bl -tag -width "SOCK_SEQPACKETXXX" -offset indent -compact
79 type provides sequenced, reliable,
80 two-way connection based byte streams.
81 An out-of-band data transmission mechanism may be supported.
85 datagrams (connectionless, unreliable messages of
86 a fixed (typically small) maximum length).
89 socket may provide a sequenced, reliable,
90 two-way connection-based data transmission path for datagrams
91 of fixed maximum length; a consumer may be required to read
92 an entire packet with each read system call.
93 This facility is protocol specific, and currently implemented for
103 sockets provide access to internal network protocols and interfaces,
104 and are available only with the
108 Any combination of the following flags may additionally be used in the
112 .Bl -tag -width "SOCK_NONBLOCKX" -offset indent -compact
114 Set close-on-exec flag on the new descriptor.
116 Set non-blocking I/O mode on the new socket.
121 specifies a particular protocol to be used with the socket.
122 Normally only a single protocol exists to support a particular
123 socket type within a given protocol family.
124 However, it is possible that many protocols may exist,
125 in which case a particular protocol must be specified in this manner.
126 The protocol number to use is particular to the
127 .Dq communication domain
128 in which communication is to take place; see
132 will let the system select an appropriate protocol for the requested
137 are full-duplex byte streams.
138 A stream socket must be in a
140 state before any data may be sent or received on it.
141 A connection to another socket is created with a
144 Once connected, data may be transferred using
148 calls or some variant of the
153 When a session has been completed a
156 Out-of-band data may also be transmitted as described in
158 and received as described in
161 The communications protocols used to implement a
163 ensure that data is not lost or duplicated.
164 If a piece of data for which the peer protocol has buffer space cannot
165 be successfully transmitted within a reasonable length of time, then the
166 connection is considered broken and calls will indicate an error with \-1
169 as the specific code in the global variable
171 The protocols optionally keep sockets
173 by forcing transmissions roughly every minute in the absence of other activity.
174 An error is then indicated if no response can be elicited on an otherwise
175 idle connection for an extended period (e.g., 5 minutes).
178 signal is raised if a process sends on a broken stream; this causes
179 naive processes, which do not handle the signal, to exit.
182 sockets employ the same system calls
186 The only difference is that
188 calls will return only the amount of data requested,
189 and any remaining in the arriving packet will be discarded.
194 sockets allow sending of datagrams to correspondents named in
197 Datagrams are generally received with
199 which returns the next datagram with its return address.
203 call can be used to specify a process group to receive
206 signal when the out-of-band data arrives.
207 It may also enable non-blocking I/O and asynchronous notification
211 The operation of sockets is controlled by socket level
213 These options are defined in the file
218 are used to set and get options, respectively.
220 A \-1 is returned if an error occurs, otherwise the return
221 value is a descriptor referencing the socket.
227 .It Bq Er EAFNOSUPPORT
228 The specified address family is not supported on this machine.
229 .It Bq Er EPROTONOSUPPORT
230 The protocol type or the specified protocol is not supported
233 The combination of the specified protocol and type is not supported.
235 The per-process descriptor table is full.
237 The system file table is full.
239 Insufficient resources were available in the system
240 to perform the operation.
242 Insufficient user memory was available to perform the operation.
244 Permission to create a socket of the specified type and/or protocol
268 .%T "An Introductory 4.3 BSD Interprocess Communication Tutorial"
269 .%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1"
272 .%T "BSD Interprocess Communication Tutorial"
273 .%O "reprinted in UNIX Programmer's Supplementary Documents Volume 1"
284 flags are expected to conform to a future revision of that standard.
288 system call first appeared in