1SOCKETPAIR(2)              Linux Programmer's Manual             SOCKETPAIR(2)
2
3
4

NAME

6       socketpair - create a pair of connected sockets
7

SYNOPSIS

9       #include <sys/types.h>          /* See NOTES */
10       #include <sys/socket.h>
11
12       int socketpair(int domain, int type, int protocol, int sv[2]);
13

DESCRIPTION

15       The  socketpair()  call creates an unnamed pair of connected sockets in
16       the specified domain, of the specified type, and using  the  optionally
17       specified  protocol.   For  further  details  of  these  arguments, see
18       socket(2).
19
20       The file descriptors used in referencing the new sockets  are  returned
21       in sv[0] and sv[1].  The two sockets are indistinguishable.
22

RETURN VALUE

24       On  success,  zero is returned.  On error, -1 is returned, and errno is
25       set appropriately.
26
27       On Linux (and other systems), socketpair() does not modify sv on  fail‐
28       ure.    A   requirement   standardizing  this  behavior  was  added  in
29       POSIX.1-2016.
30

ERRORS

32       EAFNOSUPPORT
33              The specified address family is not supported on this machine.
34
35       EFAULT The address sv does not specify a  valid  part  of  the  process
36              address space.
37
38       EMFILE The per-process limit on the number of open file descriptors has
39              been reached.
40
41       ENFILE The system-wide limit on the total number of open files has been
42              reached.
43
44       EOPNOTSUPP
45              The  specified  protocol  does  not  support  creation of socket
46              pairs.
47
48       EPROTONOSUPPORT
49              The specified protocol is not supported on this machine.
50

CONFORMING TO

52       POSIX.1-2001, POSIX.1-2008, 4.4BSD.   socketpair()  first  appeared  in
53       4.2BSD.   It  is  generally portable to/from non-BSD systems supporting
54       clones of the BSD socket layer (including System V variants).
55

NOTES

57       On Linux, the only supported domain for this call is AF_UNIX  (or  syn‐
58       onymously,  AF_LOCAL).   (Most  implementations  have the same restric‐
59       tion.)
60
61       Since  Linux  2.6.27,  socketpair()  supports  the  SOCK_NONBLOCK   and
62       SOCK_CLOEXEC flags in the type argument, as described in socket(2).
63
64       POSIX.1  does  not  require  the  inclusion  of <sys/types.h>, and this
65       header file is not required on Linux.  However, some  historical  (BSD)
66       implementations  required  this  header file, and portable applications
67       are probably wise to include it.
68

SEE ALSO

70       pipe(2), read(2), socket(2), write(2), socket(7), unix(7)
71

COLOPHON

73       This page is part of release 4.16 of the Linux  man-pages  project.   A
74       description  of  the project, information about reporting bugs, and the
75       latest    version    of    this    page,    can     be     found     at
76       https://www.kernel.org/doc/man-pages/.
77
78
79
80Linux                             2017-09-15                     SOCKETPAIR(2)
Impressum