1SOCKETPAIR(3P) POSIX Programmer's Manual SOCKETPAIR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 socketpair — create a pair of connected sockets
13
15 #include <sys/socket.h>
16
17 int socketpair(int domain, int type, int protocol,
18 int socket_vector[2]);
19
21 The socketpair() function shall create an unbound pair of connected
22 sockets in a specified domain, of a specified type, under the protocol
23 optionally specified by the protocol argument. The two sockets shall be
24 identical. The file descriptors used in referencing the created sockets
25 shall be returned in socket_vector[0] and socket_vector[1]. The file
26 descriptors shall be allocated as described in Section 2.14, File
27 Descriptor Allocation.
28
29 The socketpair() function takes the following arguments:
30
31 domain Specifies the communications domain in which the sockets
32 are to be created.
33
34 type Specifies the type of sockets to be created.
35
36 protocol Specifies a particular protocol to be used with the sock‐
37 ets. Specifying a protocol of 0 causes socketpair() to use
38 an unspecified default protocol appropriate for the
39 requested socket type.
40
41 socket_vector
42 Specifies a 2-integer array to hold the file descriptors of
43 the created socket pair.
44
45 The type argument specifies the socket type, which determines the
46 semantics of communications over the socket. The following socket types
47 are defined; implementations may specify additional socket types:
48
49 SOCK_STREAM Provides sequenced, reliable, bidirectional, connection-
50 mode byte streams, and may provide a transmission mecha‐
51 nism for out-of-band data.
52
53 SOCK_DGRAM Provides datagrams, which are connectionless-mode, unre‐
54 liable messages of fixed maximum length.
55
56 SOCK_SEQPACKET
57 Provides sequenced, reliable, bidirectional, connection-
58 mode transmission paths for records. A record can be sent
59 using one or more output operations and received using
60 one or more input operations, but a single operation
61 never transfers part of more than one record. Record
62 boundaries are visible to the receiver via the MSG_EOR
63 flag.
64
65 If the protocol argument is non-zero, it shall specify a protocol that
66 is supported by the address family. If the protocol argument is zero,
67 the default protocol for this address family and type shall be used.
68 The protocols supported by the system are implementation-defined.
69
70 The process may need to have appropriate privileges to use the socket‐
71 pair() function or to create some sockets.
72
74 Upon successful completion, this function shall return 0; otherwise, -1
75 shall be returned and errno set to indicate the error, no file descrip‐
76 tors shall be allocated, and the contents of socket_vector shall be
77 left unmodified.
78
80 The socketpair() function shall fail if:
81
82 EAFNOSUPPORT
83 The implementation does not support the specified address fam‐
84 ily.
85
86 EMFILE All, or all but one, of the file descriptors available to the
87 process are currently open.
88
89 ENFILE No more file descriptors are available for the system.
90
91 EOPNOTSUPP
92 The specified protocol does not permit creation of socket pairs.
93
94 EPROTONOSUPPORT
95 The protocol is not supported by the address family, or the pro‐
96 tocol is not supported by the implementation.
97
98 EPROTOTYPE
99 The socket type is not supported by the protocol.
100
101 The socketpair() function may fail if:
102
103 EACCES The process does not have appropriate privileges.
104
105 ENOBUFS
106 Insufficient resources were available in the system to perform
107 the operation.
108
109 ENOMEM Insufficient memory was available to fulfill the request.
110
111 The following sections are informative.
112
114 None.
115
117 The documentation for specific address families specifies which proto‐
118 cols each address family supports. The documentation for specific pro‐
119 tocols specifies which socket types each protocol supports.
120
121 The socketpair() function is used primarily with UNIX domain sockets
122 and need not be supported for other domains.
123
125 None.
126
128 None.
129
131 Section 2.14, File Descriptor Allocation, socket()
132
133 The Base Definitions volume of POSIX.1‐2017, <sys_socket.h>
134
136 Portions of this text are reprinted and reproduced in electronic form
137 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
138 table Operating System Interface (POSIX), The Open Group Base Specifi‐
139 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
140 Electrical and Electronics Engineers, Inc and The Open Group. In the
141 event of any discrepancy between this version and the original IEEE and
142 The Open Group Standard, the original IEEE and The Open Group Standard
143 is the referee document. The original Standard can be obtained online
144 at http://www.opengroup.org/unix/online.html .
145
146 Any typographical or formatting errors that appear in this page are
147 most likely to have been introduced during the conversion of the source
148 files to man page format. To report such errors, see https://www.ker‐
149 nel.org/doc/man-pages/reporting_bugs.html .
150
151
152
153IEEE/The Open Group 2017 SOCKETPAIR(3P)