2 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
3 .\" All rights reserved.
5 .\" SPDX-License-Identifier: BSD-4-Clause-UC
7 .\" $Id: socket.2,v 1.4 1999/05/13 11:33:42 freitag Exp $
9 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
10 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
11 .\" Modified 1998, 1999 by Andi Kleen <ak@muc.de>
12 .\" Modified 2002-07-17 by Michael Kerrisk <mtk.manpages@gmail.com>
13 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
15 .TH socket 2 (date) "Linux man-pages (unreleased)"
17 socket \- create an endpoint for communication
20 .RI ( libc ", " \-lc )
23 .B #include <sys/socket.h>
25 .BI "int socket(int " domain ", int " type ", int " protocol );
29 creates an endpoint for communication and returns a file descriptor
30 that refers to that endpoint.
31 The file descriptor returned by a successful call will be
32 the lowest-numbered file descriptor not currently open for the process.
36 argument specifies a communication domain; this selects the protocol
37 family which will be used for communication.
38 These families are defined in
40 The formats currently understood by the Linux kernel include:
61 T}:IPv4 Internet protocols:T{
67 Amateur radio AX.25 protocol
69 .\" Part of ax25-tools
74 T}:IPX \- Novell protocols:
82 T}:ITU-T X.25 / ISO/IEC\~8208 protocol:T{
87 T}:IPv6 Internet protocols:T{
93 DECet protocol sockets
98 Key management protocol, originally developed for usage with IPsec
103 Kernel user interface device
110 Low-level packet interface
117 .\" commit: 639b321b4d8f4e412bfbb2a4a19bfebc1e68ace4
118 Reliable Datagram Sockets (RDS) protocol
120 .\" rds-tools: https://github.com/oracle/rds-tools/blob/master/rds.7
121 .\" rds-tools: https://github.com/oracle/rds-tools/blob/master/rds-rdma.7
129 Generic PPP transport layer, for setting up L2 tunnels
135 .\" linux-history commit: 34beb106cde7da233d4df35dd3d6cf4fee937caa
136 Logical link control (IEEE 802.2 LLC) protocol
141 .\" commits: 8d36eb01da5d371f..ce117ffac2e93334
142 InfiniBand native addressing
147 .\" commits: 0189197f441602acdca3f97750d392a895b778fd
148 Multiprotocol Label Switching
153 .\" commits: 8dbde28d9711475a..5423dd67bd0108a1
154 Controller Area Network automotive bus protocol
159 .\" commits: b97bf3fd8f6a16966d4f18983b2c40993ff937d4
160 TIPC, "cluster domain sockets" protocol
165 .\" commits: 8d36eb01da5d371f..ce117ffac2e93334
166 Bluetooth low-level socket protocol
171 .\" commit: 03c8efc1ffeb6b82a22c1af8dd908af349563314
172 Interface to kernel crypto API
177 .\" commit: d021c344051af91f42c5ba9fdedc176740cbd238
178 VSOCK (originally "VMWare VSockets") protocol
179 for hypervisor-guest communication
186 .\" commit: 03c8efc1ffeb6b82a22c1af8dd908af349563314
187 KCM (kernel connection multiplexer) interface
192 .\" commit: c0c77d8fb787cfe0c3fca689c2a30d1dad4eaba7
193 XDP (express data path) interface
197 Further details of the above address families,
198 as well as information on several other address families, can be found in
199 .BR address_families (7).
201 The socket has the indicated
203 which specifies the communication semantics.
204 Currently defined types
208 Provides sequenced, reliable, two-way, connection-based byte streams.
209 An out-of-band data transmission mechanism may be supported.
212 Supports datagrams (connectionless, unreliable messages of a fixed
216 Provides a sequenced, reliable, two-way connection-based data
217 transmission path for datagrams of fixed maximum length; a consumer is
218 required to read an entire packet with each input system call.
221 Provides raw network protocol access.
224 Provides a reliable datagram layer that does not guarantee ordering.
227 Obsolete and should not be used in new programs;
231 Some socket types may not be implemented by all protocol families.
233 Since Linux 2.6.27, the
235 argument serves a second purpose:
236 in addition to specifying a socket type,
237 it may include the bitwise OR of any of the following values,
238 to modify the behavior of
244 file status flag on the open file description (see
246 referred to by the new file descriptor.
247 Using this flag saves extra calls to
249 to achieve the same result.
252 Set the close-on-exec
254 flag on the new file descriptor.
255 See the description of the
259 for reasons why this may be useful.
263 specifies a particular protocol to be used with the socket.
264 Normally only a single protocol exists to support a particular
265 socket type within a given protocol family, in which case
267 can be specified as 0.
268 However, it is possible that many protocols may exist, in
269 which case a particular protocol must be specified in this manner.
270 The protocol number to use is specific to the \*(lqcommunication domain\*(rq
271 in which communication is to take place; see
275 on how to map protocol name strings to protocol numbers.
279 are full-duplex byte streams.
282 A stream socket must be in
285 state before any data may be sent or received on it.
287 another socket is created with a
290 Once connected, data may be transferred using
294 calls or some variant of the
299 When a session has been completed a
302 Out-of-band data may also be transmitted as described in
304 and received as described in
307 The communications protocols which implement a
309 ensure that data is not lost or duplicated.
310 If a piece of data for which
311 the peer protocol has buffer space cannot be successfully transmitted
312 within a reasonable length of time, then the connection is considered
316 is enabled on the socket the protocol checks in a protocol-specific
317 manner if the other end is still alive.
320 signal is raised if a process sends or receives
321 on a broken stream; this causes naive processes,
322 which do not handle the signal, to exit.
324 sockets employ the same system calls as
327 The only difference is that
329 calls will return only the amount of data requested,
330 and any data remaining in the arriving packet will be discarded.
331 Also all message boundaries in incoming datagrams are preserved.
336 sockets allow sending of datagrams to correspondents named in
339 Datagrams are generally received with
341 which returns the next datagram along with the address of its sender.
344 is an obsolete socket type to receive raw packets directly from the
353 operation can be used to specify a process or process group to receive a
355 signal when the out-of-band data arrives or
359 connection breaks unexpectedly.
360 This operation may also be used to set the process or process group
361 that receives the I/O and asynchronous notification of I/O events via
373 When the network signals an error condition to the protocol module (e.g.,
374 using an ICMP message for IP) the pending error flag is set for the socket.
375 The next operation on this socket will return the error code of the pending
377 For some protocols it is possible to enable a per-socket error queue
378 to retrieve detailed information about the error; see
383 The operation of sockets is controlled by socket level
385 These options are defined in
391 are used to set and get options.
393 On success, a file descriptor for the new socket is returned.
394 On error, \-1 is returned, and
396 is set to indicate the error.
400 Permission to create a socket of the specified type and/or protocol
404 The implementation does not support the specified address family.
407 Unknown protocol, or protocol family not available.
410 .\" Since Linux 2.6.27
415 The per-process limit on the number of open file descriptors has been reached.
418 The system-wide limit on the total number of open files has been reached.
420 .BR ENOBUFS " or " ENOMEM
421 Insufficient memory is available.
423 created until sufficient resources are freed.
426 The protocol type or the specified protocol is not
427 supported within this domain.
429 Other errors may be generated by the underlying protocol modules.
438 POSIX.1-2001, 4.4BSD.
442 It is generally portable to/from
443 non-BSD systems supporting clones of the BSD socket layer (including
446 The manifest constants used under 4.x BSD for protocol families
453 and so on are used for address
455 However, already the BSD man page promises: "The protocol
456 family generally is the same as the address family", and subsequent
457 standards use AF_* everywhere.
459 An example of the use of
482 .BR address_families (7),
489 \[lq]An Introductory 4.3BSD Interprocess Communication Tutorial\[rq]
491 \[lq]BSD Interprocess Communication Tutorial\[rq],
493 .I UNIX Programmer's Supplementary Documents Volume 1.