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

NAME

6       socketpair - create a pair of connected sockets
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       int socketpair(int domain, int type, int protocol,
12              int socket_vector[2]);
13
14

DESCRIPTION

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

RETURN VALUE

71       Upon successful completion, this function shall return 0; otherwise, -1
72       shall be returned and errno set to indicate the error.
73

ERRORS

75       The socketpair() function shall fail if:
76
77       EAFNOSUPPORT
78
79              The  implementation  does not support the specified address fam‐
80              ily.
81
82       EMFILE No more file descriptors are available for this process.
83
84       ENFILE No more file descriptors are available for the system.
85
86       EOPNOTSUPP
87              The specified protocol does not permit creation of socket pairs.
88
89       EPROTONOSUPPORT
90
91              The protocol is not supported by the address family, or the pro‐
92              tocol is not supported by the implementation.
93
94       EPROTOTYPE
95              The socket type is not supported by the protocol.
96
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
109       The following sections are informative.
110

EXAMPLES

112       None.
113

APPLICATION USAGE

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

RATIONALE

123       None.
124

FUTURE DIRECTIONS

126       None.
127

SEE ALSO

129       socket()   ,  the  Base  Definitions  volume  of  IEEE Std 1003.1-2001,
130       <sys/socket.h>
131
133       Portions of this text are reprinted and reproduced in  electronic  form
134       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
135       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
136       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
137       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
138       event of any discrepancy between this version and the original IEEE and
139       The Open Group Standard, the original IEEE and The Open Group  Standard
140       is  the  referee document. The original Standard can be obtained online
141       at http://www.opengroup.org/unix/online.html .
142
143
144
145IEEE/The Open Group                  2003                        SOCKETPAIR(P)
Impressum