man-pages/man2/socketpair.2.html
2021-03-31 01:06:50 +01:00

205 lines
4.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SOCKETPAIR</TITLE>
</HEAD><BODY>
<H1>SOCKETPAIR</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
socketpair - create a pair of connected sockets
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</B> /* See NOTES */
<BR>
<B>#include &lt;<A HREF="file:///usr/include/sys/socket.h">sys/socket.h</A>&gt;</B>
<P>
<B>int socketpair(int </B><I>domain</I><B>, int </B><I>type</I><B>, int </B><I>protocol</I><B>, int </B><I>sv</I><B>[2]);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>socketpair</B>()
call creates an unnamed pair of connected sockets in the specified
<I>domain</I>,
of the specified
<I>type</I>,
and using the optionally specified
<I>protocol</I>.
For further details of these arguments, see
<B><A HREF="/cgi-bin/man/man2html?2+socket">socket</A></B>(2).
<P>
The file descriptors used in referencing the new sockets are returned in
<I>sv</I>[0]
and
<I>sv</I>[1].
The two sockets are indistinguishable.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned,
<I>errno</I>
is set appropriately, and
<I>sv</I>
is left unchanged
<P>
On Linux (and other systems),
<B>socketpair</B>()
does not modify
<I>sv</I>
on failure.
A requirement standardizing this behavior was added in POSIX.1-2016.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EAFNOSUPPORT</B>
<DD>
The specified address family is not supported on this machine.
<DT id="2"><B>EFAULT</B>
<DD>
The address
<I>sv</I>
does not specify a valid part of the process address space.
<DT id="3"><B>EMFILE</B>
<DD>
The per-process limit on the number of open file descriptors has been reached.
<DT id="4"><B>ENFILE</B>
<DD>
The system-wide limit on the total number of open files has been reached.
<DT id="5"><B>EOPNOTSUPP</B>
<DD>
The specified protocol does not support creation of socket pairs.
<DT id="6"><B>EPROTONOSUPPORT</B>
<DD>
The specified protocol is not supported on this machine.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, 4.4BSD.
<B>socketpair</B>()
first appeared in 4.2BSD.
It is generally portable to/from
non-BSD systems supporting clones of the BSD socket layer (including
System&nbsp;V variants).
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
On Linux, the only supported domains for this call are
<B>AF_UNIX</B>
(or synonymously,
<B>AF_LOCAL</B>)
and
<B>AF_TIPC</B>
(since Linux 4.12).
<P>
Since Linux 2.6.27,
<B>socketpair</B>()
supports the
<B>SOCK_NONBLOCK</B>
and
<B>SOCK_CLOEXEC</B>
flags in the
<I>type</I>
argument, as described in
<B><A HREF="/cgi-bin/man/man2html?2+socket">socket</A></B>(2).
<P>
POSIX.1 does not require the inclusion of
<I>&lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;</I>,
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.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+pipe">pipe</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+socket">socket</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+write">write</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+socket">socket</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+unix">unix</A></B>(7)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="7"><A HREF="#lbAB">NAME</A><DD>
<DT id="8"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="9"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="10"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="11"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="12"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="13"><A HREF="#lbAH">NOTES</A><DD>
<DT id="14"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="15"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:34 GMT, March 31, 2021
</BODY>
</HTML>