1SOCKETPAIR(3P)             POSIX Programmer's Manual            SOCKETPAIR(3P)
2
3
4

PROLOG

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
11

NAME

13       socketpair — create a pair of connected sockets
14

SYNOPSIS

16       #include <sys/socket.h>
17
18       int socketpair(int domain, int type, int protocol,
19           int socket_vector[2]);
20

DESCRIPTION

22       The socketpair() function shall create an  unbound  pair  of  connected
23       sockets  in a specified domain, of a specified type, under the protocol
24       optionally specified by the protocol argument. The two sockets shall be
25       identical. The file descriptors used in referencing the created sockets
26       shall be returned in socket_vector[0] and socket_vector[1].
27
28       The socketpair() function takes the following arguments:
29
30       domain      Specifies the communications domain in  which  the  sockets
31                   are to be created.
32
33       type        Specifies the type of sockets to be created.
34
35       protocol    Specifies  a  particular protocol to be used with the sock‐
36                   ets.  Specifying a protocol of 0 causes socketpair() to use
37                   an   unspecified   default  protocol  appropriate  for  the
38                   requested socket type.
39
40       socket_vector
41                   Specifies a 2-integer array to hold the file descriptors of
42                   the created socket pair.
43
44       The  type  argument  specifies  the  socket  type, which determines the
45       semantics of communications over the socket. The following socket types
46       are defined; implementations may specify additional socket types:
47
48       SOCK_STREAM   Provides  sequenced, reliable, bidirectional, connection-
49                     mode byte streams, and may provide a transmission  mecha‐
50                     nism for out-of-band data.
51
52       SOCK_DGRAM    Provides  datagrams, which are connectionless-mode, unre‐
53                     liable messages of fixed maximum length.
54
55       SOCK_SEQPACKET
56                     Provides sequenced, reliable, bidirectional,  connection-
57                     mode transmission paths for records. A record can be sent
58                     using one or more output operations  and  received  using
59                     one  or  more  input  operations,  but a single operation
60                     never transfers part of  more  than  one  record.  Record
61                     boundaries  are  visible  to the receiver via the MSG_EOR
62                     flag.
63
64       If the protocol argument is non-zero, it shall specify a protocol  that
65       is  supported  by the address family. If the protocol argument is zero,
66       the default protocol for this address family and type  shall  be  used.
67       The protocols supported by the system are implementation-defined.
68
69       The  process may need to have appropriate privileges to use the socket‐
70       pair() function or to create some sockets.
71

RETURN VALUE

73       Upon successful completion, this function shall return 0; otherwise, −1
74       shall be returned and errno set to indicate the error.
75

ERRORS

77       The socketpair() function shall fail if:
78
79       EAFNOSUPPORT
80              The  implementation  does not support the specified address fam‐
81              ily.
82
83       EMFILE All, or all but one, of the file descriptors  available  to  the
84              process are currently open.
85
86       ENFILE No more file descriptors are available for the system.
87
88       EOPNOTSUPP
89              The specified protocol does not permit creation of socket pairs.
90
91       EPROTONOSUPPORT
92              The protocol is not supported by the address family, or the pro‐
93              tocol is not supported by the implementation.
94
95       EPROTOTYPE
96              The socket type is not supported by the protocol.
97
98       The socketpair() function may fail if:
99
100       EACCES The process does not have appropriate privileges.
101
102       ENOBUFS
103              Insufficient resources were available in the system  to  perform
104              the operation.
105
106       ENOMEM Insufficient memory was available to fulfill the request.
107
108       The following sections are informative.
109

EXAMPLES

111       None.
112

APPLICATION USAGE

114       The  documentation for specific address families specifies which proto‐
115       cols each address family supports. The documentation for specific  pro‐
116       tocols specifies which socket types each protocol supports.
117
118       The  socketpair()  function  is used primarily with UNIX domain sockets
119       and need not be supported for other domains.
120

RATIONALE

122       None.
123

FUTURE DIRECTIONS

125       None.
126

SEE ALSO

128       socket()
129
130       The Base Definitions volume of POSIX.1‐2008, <sys_socket.h>
131
133       Portions of this text are reprinted and reproduced in  electronic  form
134       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
135       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
136       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
137       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
138       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
139       event of any discrepancy between this version and the original IEEE and
140       The  Open Group Standard, the original IEEE and The Open Group Standard
141       is the referee document. The original Standard can be  obtained  online
142       at http://www.unix.org/online.html .
143
144       Any  typographical  or  formatting  errors that appear in this page are
145       most likely to have been introduced during the conversion of the source
146       files  to  man page format. To report such errors, see https://www.ker
147       nel.org/doc/man-pages/reporting_bugs.html .
148
149
150
151IEEE/The Open Group                  2013                       SOCKETPAIR(3P)
Impressum