]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/socketpair.2
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd...
[thirdparty/man-pages.git] / man2 / socketpair.2
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" %%%LICENSE_END
33 .\"
34 .\" @(#)socketpair.2 6.4 (Berkeley) 3/10/91
35 .\"
36 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
37 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
38 .\" Modified 2002-07-22 by Michael Kerrisk <mtk.manpages@gmail.com>
39 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\" 2008-10-11, mtk: Add description of SOCK_NONBLOCK and SOCK_CLOEXEC
41 .\"
42 .TH SOCKETPAIR 2 2019-03-06 "Linux" "Linux Programmer's Manual"
43 .SH NAME
44 socketpair \- create a pair of connected sockets
45 .SH SYNOPSIS
46 .BR "#include <sys/types.h>" " /* See NOTES */"
47 .br
48 .B #include <sys/socket.h>
49 .PP
50 .BI "int socketpair(int " domain ", int " type ", int " protocol \
51 ", int " sv [2]);
52 .SH DESCRIPTION
53 The
54 .BR socketpair ()
55 call creates an unnamed pair of connected sockets in the specified
56 .IR domain ,
57 of the specified
58 .IR type ,
59 and using the optionally specified
60 .IR protocol .
61 For further details of these arguments, see
62 .BR socket (2).
63 .PP
64 The file descriptors used in referencing the new sockets are returned in
65 .IR sv [0]
66 and
67 .IR sv [1].
68 The two sockets are indistinguishable.
69 .SH RETURN VALUE
70 On success, zero is returned.
71 On error, \-1 is returned, and
72 .I errno
73 is set appropriately.
74 .PP
75 On Linux (and other systems),
76 .BR socketpair ()
77 does not modify
78 .I sv
79 on failure.
80 A requirement standardizing this behavior was added in POSIX.1-2016.
81 .\" http://austingroupbugs.net/view.php?id=483
82 .SH ERRORS
83 .TP
84 .B EAFNOSUPPORT
85 The specified address family is not supported on this machine.
86 .TP
87 .B EFAULT
88 The address
89 .I sv
90 does not specify a valid part of the process address space.
91 .TP
92 .B EMFILE
93 The per-process limit on the number of open file descriptors has been reached.
94 .TP
95 .B ENFILE
96 The system-wide limit on the total number of open files has been reached.
97 .TP
98 .B EOPNOTSUPP
99 The specified protocol does not support creation of socket pairs.
100 .TP
101 .B EPROTONOSUPPORT
102 The specified protocol is not supported on this machine.
103 .SH CONFORMING TO
104 POSIX.1-2001, POSIX.1-2008, 4.4BSD.
105 .BR socketpair ()
106 first appeared in 4.2BSD.
107 It is generally portable to/from
108 non-BSD systems supporting clones of the BSD socket layer (including
109 System\ V variants).
110 .SH NOTES
111 On Linux, the only supported domains for this call are
112 .B AF_UNIX
113 (or synonymously,
114 .BR AF_LOCAL )
115 and
116 .B AF_TIPC
117 .\" commit: 70b03759e9ecfae400605fa34f3d7154cccbbba3
118 (since Linux 4.12).
119 .PP
120 Since Linux 2.6.27,
121 .BR socketpair ()
122 supports the
123 .BR SOCK_NONBLOCK
124 and
125 .BR SOCK_CLOEXEC
126 flags in the
127 .I type
128 argument, as described in
129 .BR socket (2).
130 .PP
131 POSIX.1 does not require the inclusion of
132 .IR <sys/types.h> ,
133 and this header file is not required on Linux.
134 However, some historical (BSD) implementations required this header
135 file, and portable applications are probably wise to include it.
136 .SH SEE ALSO
137 .BR pipe (2),
138 .BR read (2),
139 .BR socket (2),
140 .BR write (2),
141 .BR socket (7),
142 .BR unix (7)