Section: Linux Programmer's Manual (2)
socketpair - create a pair of connected sockets
/* See NOTES */
int socketpair(int domain, int type, int protocol, int sv);
call creates an unnamed pair of connected sockets in the specified
of the specified
and using the optionally specified
For further details of these arguments, see
The file descriptors used in referencing the new sockets are returned in
The two sockets are indistinguishable.
On success, zero is returned.
On error, -1 is returned,
is set appropriately, and
is left unchanged
On Linux (and other systems),
does not modify
A requirement standardizing this behavior was added in POSIX.1-2016.
The specified address family is not supported on this machine.
does not specify a valid part of the process address space.
The per-process limit on the number of open file descriptors has been reached.
The system-wide limit on the total number of open files has been reached.
The specified protocol does not support creation of socket pairs.
The specified protocol is not supported on this machine.
POSIX.1-2001, POSIX.1-2008, 4.4BSD.
first appeared in 4.2BSD.
It is generally portable to/from
non-BSD systems supporting clones of the BSD socket layer (including
System V variants).
On Linux, the only supported domains for this call are
(since Linux 4.12).
Since Linux 2.6.27,
flags in the
argument, as described in
POSIX.1 does not require the inclusion of
and this header file is not required on Linux.
However, some historical (BSD) implementations required this header
file, and portable applications are probably wise to include it.
This page is part of release 5.02 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at