| 1 |
.\" Copyright 1983-1991, The Regents of the University of California. |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: BSD-4-Clause-UC |
| 5 |
.\" |
| 6 |
.TH socketpair 2 2025-10-29 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
socketpair \- create a pair of connected sockets |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <sys/socket.h> |
| 15 |
.P |
| 16 |
.BI "int socketpair(int " domain ", int " type ", int " protocol \ |
| 17 |
", int " sv [2]); |
| 18 |
.fi |
| 19 |
.SH DESCRIPTION |
| 20 |
The |
| 21 |
.BR socketpair () |
| 22 |
call creates an unnamed pair of connected sockets in the specified |
| 23 |
.IR domain , |
| 24 |
of the specified |
| 25 |
.IR type , |
| 26 |
and using the optionally specified |
| 27 |
.IR protocol . |
| 28 |
For further details of these arguments, see |
| 29 |
.BR socket (2). |
| 30 |
.P |
| 31 |
The file descriptors used in referencing the new sockets are returned in |
| 32 |
.I sv[0] |
| 33 |
and |
| 34 |
.IR sv[1] . |
| 35 |
The two sockets are indistinguishable. |
| 36 |
.SH RETURN VALUE |
| 37 |
On success, zero is returned. |
| 38 |
On error, \-1 is returned, |
| 39 |
.I errno |
| 40 |
is set to indicate the error, and |
| 41 |
.I sv |
| 42 |
is left unchanged |
| 43 |
.P |
| 44 |
On Linux (and other systems), |
| 45 |
.BR socketpair () |
| 46 |
does not modify |
| 47 |
.I sv |
| 48 |
on failure. |
| 49 |
A requirement standardizing this behavior was added in POSIX.1-2008 TC2. |
| 50 |
.\" http://austingroupbugs.net/view.php?id=483 |
| 51 |
.SH ERRORS |
| 52 |
.TP |
| 53 |
.B EAFNOSUPPORT |
| 54 |
The specified address family is not supported on this machine. |
| 55 |
.TP |
| 56 |
.B EFAULT |
| 57 |
The address |
| 58 |
.I sv |
| 59 |
does not specify a valid part of the process address space. |
| 60 |
.TP |
| 61 |
.B EMFILE |
| 62 |
The per-process limit on the number of open file descriptors has been reached. |
| 63 |
.TP |
| 64 |
.B ENFILE |
| 65 |
The system-wide limit on the total number of open files has been reached. |
| 66 |
.TP |
| 67 |
.B EOPNOTSUPP |
| 68 |
The specified protocol does not support creation of socket pairs. |
| 69 |
.TP |
| 70 |
.B EPROTONOSUPPORT |
| 71 |
The specified protocol is not supported on this machine. |
| 72 |
.SH VERSIONS |
| 73 |
On Linux, the only supported domains for this call are |
| 74 |
.B AF_UNIX |
| 75 |
(or synonymously, |
| 76 |
.BR AF_LOCAL ) |
| 77 |
and |
| 78 |
.B AF_TIPC |
| 79 |
.\" commit: 70b03759e9ecfae400605fa34f3d7154cccbbba3 |
| 80 |
(since Linux 4.12). |
| 81 |
.SH STANDARDS |
| 82 |
POSIX.1-2024. |
| 83 |
.SH HISTORY |
| 84 |
POSIX.1-2001, 4.2BSD. |
| 85 |
.P |
| 86 |
It is generally portable to/from |
| 87 |
non-BSD systems supporting clones of the BSD socket layer (including |
| 88 |
System\ V variants). |
| 89 |
.TP |
| 90 |
.B SOCK_CLOEXEC |
| 91 |
.TQ |
| 92 |
.B SOCK_NONBLOCK |
| 93 |
POSIX.1-2024; |
| 94 |
Linux 2.6.27. |
| 95 |
(See |
| 96 |
.BR socket (2).) |
| 97 |
.SH SEE ALSO |
| 98 |
.BR pipe (2), |
| 99 |
.BR read (2), |
| 100 |
.BR socket (2), |
| 101 |
.BR write (2), |
| 102 |
.BR socket (7), |
| 103 |
.BR unix (7) |