|
Packit |
7cfc04 |
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
|
|
Packit |
7cfc04 |
.\" All rights reserved.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
|
|
Packit |
7cfc04 |
.\" Redistribution and use in source and binary forms, with or without
|
|
Packit |
7cfc04 |
.\" modification, are permitted provided that the following conditions
|
|
Packit |
7cfc04 |
.\" are met:
|
|
Packit |
7cfc04 |
.\" 1. Redistributions of source code must retain the above copyright
|
|
Packit |
7cfc04 |
.\" notice, this list of conditions and the following disclaimer.
|
|
Packit |
7cfc04 |
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
7cfc04 |
.\" notice, this list of conditions and the following disclaimer in the
|
|
Packit |
7cfc04 |
.\" documentation and/or other materials provided with the distribution.
|
|
Packit |
7cfc04 |
.\" 3. All advertising materials mentioning features or use of this software
|
|
Packit |
7cfc04 |
.\" must display the following acknowledgement:
|
|
Packit |
7cfc04 |
.\" This product includes software developed by the University of
|
|
Packit |
7cfc04 |
.\" California, Berkeley and its contributors.
|
|
Packit |
7cfc04 |
.\" 4. Neither the name of the University nor the names of its contributors
|
|
Packit |
7cfc04 |
.\" may be used to endorse or promote products derived from this software
|
|
Packit |
7cfc04 |
.\" without specific prior written permission.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
Packit |
7cfc04 |
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
7cfc04 |
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
7cfc04 |
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
Packit |
7cfc04 |
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit |
7cfc04 |
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
Packit |
7cfc04 |
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
Packit |
7cfc04 |
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
Packit |
7cfc04 |
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
Packit |
7cfc04 |
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
Packit |
7cfc04 |
.\" SUCH DAMAGE.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" @(#)socketpair.2 6.4 (Berkeley) 3/10/91
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
|
|
Packit |
7cfc04 |
.\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
|
|
Packit |
7cfc04 |
.\" Modified 2002-07-22 by Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\" 2008-10-11, mtk: Add description of SOCK_NONBLOCK and SOCK_CLOEXEC
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH SOCKETPAIR 2 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
socketpair \- create a pair of connected sockets
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.BR "#include <sys/types.h>" " /* See NOTES */"
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
.B #include <sys/socket.h>
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "int socketpair(int " domain ", int " type ", int " protocol \
|
|
Packit |
7cfc04 |
", int " sv [2]);
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR socketpair ()
|
|
Packit |
7cfc04 |
call creates an unnamed pair of connected sockets in the specified
|
|
Packit |
7cfc04 |
.IR domain ,
|
|
Packit |
7cfc04 |
of the specified
|
|
Packit |
7cfc04 |
.IR type ,
|
|
Packit |
7cfc04 |
and using the optionally specified
|
|
Packit |
7cfc04 |
.IR protocol .
|
|
Packit |
7cfc04 |
For further details of these arguments, see
|
|
Packit |
7cfc04 |
.BR socket (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The file descriptors used in referencing the new sockets are returned in
|
|
Packit |
7cfc04 |
.IR sv [0]
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.IR sv [1].
|
|
Packit |
7cfc04 |
The two sockets are indistinguishable.
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
On success, zero is returned.
|
|
Packit |
7cfc04 |
On error, \-1 is returned, and
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
is set appropriately.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
On Linux (and other systems),
|
|
Packit |
7cfc04 |
.BR socketpair ()
|
|
Packit |
7cfc04 |
does not modify
|
|
Packit |
7cfc04 |
.I sv
|
|
Packit |
7cfc04 |
on failure.
|
|
Packit |
7cfc04 |
A requirement standardizing this behavior was added in POSIX.1-2016.
|
|
Packit |
7cfc04 |
.\" http://austingroupbugs.net/view.php?id=483
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EAFNOSUPPORT
|
|
Packit |
7cfc04 |
The specified address family is not supported on this machine.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EFAULT
|
|
Packit |
7cfc04 |
The address
|
|
Packit |
7cfc04 |
.I sv
|
|
Packit |
7cfc04 |
does not specify a valid part of the process address space.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EMFILE
|
|
Packit |
7cfc04 |
The per-process limit on the number of open file descriptors has been reached.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENFILE
|
|
Packit |
7cfc04 |
The system-wide limit on the total number of open files has been reached.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EOPNOTSUPP
|
|
Packit |
7cfc04 |
The specified protocol does not support creation of socket pairs.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EPROTONOSUPPORT
|
|
Packit |
7cfc04 |
The specified protocol is not supported on this machine.
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
POSIX.1-2001, POSIX.1-2008, 4.4BSD.
|
|
Packit |
7cfc04 |
.BR socketpair ()
|
|
Packit |
7cfc04 |
first appeared in 4.2BSD.
|
|
Packit |
7cfc04 |
It is generally portable to/from
|
|
Packit |
7cfc04 |
non-BSD systems supporting clones of the BSD socket layer (including
|
|
Packit |
7cfc04 |
System\ V variants).
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
On Linux, the only supported domain for this call is
|
|
Packit |
7cfc04 |
.B AF_UNIX
|
|
Packit |
7cfc04 |
(or synonymously,
|
|
Packit |
7cfc04 |
.BR AF_LOCAL ).
|
|
Packit |
7cfc04 |
(Most implementations have the same restriction.)
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Since Linux 2.6.27,
|
|
Packit |
7cfc04 |
.BR socketpair ()
|
|
Packit |
7cfc04 |
supports the
|
|
Packit |
7cfc04 |
.BR SOCK_NONBLOCK
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR SOCK_CLOEXEC
|
|
Packit |
7cfc04 |
flags in the
|
|
Packit |
7cfc04 |
.I type
|
|
Packit |
7cfc04 |
argument, as described in
|
|
Packit |
7cfc04 |
.BR socket (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
POSIX.1 does not require the inclusion of
|
|
Packit |
7cfc04 |
.IR <sys/types.h> ,
|
|
Packit |
7cfc04 |
and this header file is not required on Linux.
|
|
Packit |
7cfc04 |
However, some historical (BSD) implementations required this header
|
|
Packit |
7cfc04 |
file, and portable applications are probably wise to include it.
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR pipe (2),
|
|
Packit |
7cfc04 |
.BR read (2),
|
|
Packit |
7cfc04 |
.BR socket (2),
|
|
Packit |
7cfc04 |
.BR write (2),
|
|
Packit |
7cfc04 |
.BR socket (7),
|
|
Packit |
7cfc04 |
.BR unix (7)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|