1SOCKETPAIR(2) Linux Programmer's Manual SOCKETPAIR(2)
2
3
4
6 socketpair - create a pair of connected sockets
7
9 #include <sys/types.h> /* See NOTES */
10 #include <sys/socket.h>
11
12 int socketpair(int domain, int type, int protocol, int sv[2]);
13
15 The socketpair() call creates an unnamed pair of connected sockets in
16 the specified domain, of the specified type, and using the optionally
17 specified protocol. For further details of these arguments, see
18 socket(2).
19
20 The file descriptors used in referencing the new sockets are returned
21 in sv[0] and sv[1]. The two sockets are indistinguishable.
22
24 On success, zero is returned. On error, -1 is returned, errno is set
25 appropriately, and sv is left unchanged
26
27 On Linux (and other systems), socketpair() does not modify sv on fail‐
28 ure. A requirement standardizing this behavior was added in
29 POSIX.1-2016.
30
32 EAFNOSUPPORT
33 The specified address family is not supported on this machine.
34
35 EFAULT The address sv does not specify a valid part of the process
36 address space.
37
38 EMFILE The per-process limit on the number of open file descriptors has
39 been reached.
40
41 ENFILE The system-wide limit on the total number of open files has been
42 reached.
43
44 EOPNOTSUPP
45 The specified protocol does not support creation of socket
46 pairs.
47
48 EPROTONOSUPPORT
49 The specified protocol is not supported on this machine.
50
52 POSIX.1-2001, POSIX.1-2008, 4.4BSD. socketpair() first appeared in
53 4.2BSD. It is generally portable to/from non-BSD systems supporting
54 clones of the BSD socket layer (including System V variants).
55
57 On Linux, the only supported domains for this call are AF_UNIX (or syn‐
58 onymously, AF_LOCAL) and AF_TIPC (since Linux 4.12).
59
60 Since Linux 2.6.27, socketpair() supports the SOCK_NONBLOCK and
61 SOCK_CLOEXEC flags in the type argument, as described in socket(2).
62
63 POSIX.1 does not require the inclusion of <sys/types.h>, and this
64 header file is not required on Linux. However, some historical (BSD)
65 implementations required this header file, and portable applications
66 are probably wise to include it.
67
69 pipe(2), read(2), socket(2), write(2), socket(7), unix(7)
70
72 This page is part of release 5.02 of the Linux man-pages project. A
73 description of the project, information about reporting bugs, and the
74 latest version of this page, can be found at
75 https://www.kernel.org/doc/man-pages/.
76
77
78
79Linux 2019-03-06 SOCKETPAIR(2)