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

NAME

12       socketpair - create a pair of connected sockets
13

SYNOPSIS

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

RETURN VALUE

77       Upon successful completion, this function shall return 0; otherwise, -1
78       shall be returned and errno set to indicate the error.
79

ERRORS

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

EXAMPLES

118       None.
119

APPLICATION USAGE

121       The  documentation for specific address families specifies which proto‐
122       cols each address family supports. The documentation for specific  pro‐
123       tocols specifies which socket types each protocol supports.
124
125       The  socketpair()  function  is used primarily with UNIX domain sockets
126       and need not be supported for other domains.
127

RATIONALE

129       None.
130

FUTURE DIRECTIONS

132       None.
133

SEE ALSO

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