1socketpair(2) System Calls Manual socketpair(2)
2
3
4
6 socketpair - create a pair of connected sockets
7
9 Standard C library (libc, -lc)
10
12 #include <sys/socket.h>
13
14 int socketpair(int domain, int type, int protocol, int sv[2]);
15
17 The socketpair() call creates an unnamed pair of connected sockets in
18 the specified domain, of the specified type, and using the optionally
19 specified protocol. For further details of these arguments, see
20 socket(2).
21
22 The file descriptors used in referencing the new sockets are returned
23 in sv[0] and sv[1]. The two sockets are indistinguishable.
24
26 On success, zero is returned. On error, -1 is returned, errno is set
27 to indicate the error, and sv is left unchanged
28
29 On Linux (and other systems), socketpair() does not modify sv on fail‐
30 ure. A requirement standardizing this behavior was added in
31 POSIX.1-2008 TC2.
32
34 EAFNOSUPPORT
35 The specified address family is not supported on this machine.
36
37 EFAULT The address sv does not specify a valid part of the process ad‐
38 dress space.
39
40 EMFILE The per-process limit on the number of open file descriptors has
41 been reached.
42
43 ENFILE The system-wide limit on the total number of open files has been
44 reached.
45
46 EOPNOTSUPP
47 The specified protocol does not support creation of socket
48 pairs.
49
50 EPROTONOSUPPORT
51 The specified protocol is not supported on this machine.
52
54 On Linux, the only supported domains for this call are AF_UNIX (or syn‐
55 onymously, AF_LOCAL) and AF_TIPC (since Linux 4.12).
56
58 POSIX.1-2008.
59
61 POSIX.1-2001, 4.4BSD.
62
63 socketpair() first appeared in 4.2BSD. It is generally portable
64 to/from non-BSD systems supporting clones of the BSD socket layer (in‐
65 cluding System V variants).
66
67 Since Linux 2.6.27, socketpair() supports the SOCK_NONBLOCK and
68 SOCK_CLOEXEC flags in the type argument, as described in socket(2).
69
71 pipe(2), read(2), socket(2), write(2), socket(7), unix(7)
72
73
74
75Linux man-pages 6.05 2023-03-30 socketpair(2)