1.\" $NetBSD: socketpair.2,v 1.25 2022/11/29 20:50:37 uwe Exp $ 2.\" 3.\" Copyright (c) 1983, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)socketpair.2 8.1 (Berkeley) 6/4/93 31.\" 32.Dd November 29, 2022 33.Dt SOCKETPAIR 2 34.Os 35.Sh NAME 36.Nm socketpair 37.Nd create a pair of connected sockets 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.In sys/socket.h 42.Ft int 43.Fn socketpair "int d" "int type" "int protocol" "int *sv" 44.Sh DESCRIPTION 45The 46.Fn socketpair 47call creates an unnamed pair of connected sockets in 48the specified domain 49.Fa d , 50of the specified 51.Fa type , 52and using the optionally specified 53.Fa protocol . 54The descriptors used in referencing the new sockets 55are returned in 56.Fa sv Ns Li [0] 57and 58.Fa sv Ns Li [1] . 59The two sockets are indistinguishable. 60.Pp 61Possible values for the 62.Fa type 63argument are 64.Dv SOCK_STREAM , 65.Dv SOCK_DGRAM , 66and 67.Dv SOCK_SEQPACKET ; 68the only supported value for the 69.Fa protocol 70is 0, 71which will let the system select an appropriate 72protocol for the requested socket 73.Fa type . 74.Pp 75Any combination of the following flags may 76additionally be used in the 77.Fa type 78argument: 79.Pp 80.Bl -tag -width Dv -offset indent -compact 81.It Dv SOCK_CLOEXEC 82Set close-on-exec flag on both the new descriptors. 83.It Dv SOCK_NONBLOCK 84Set non-blocking I/O mode on both the new sockets. 85.El 86.Sh RETURN VALUES 87.Rv -std 88.Sh ERRORS 89The call succeeds unless: 90.Bl -tag -width Er 91.It Bq Er EAFNOSUPPORT 92The specified address family is not supported on this machine. 93.It Bq Er EFAULT 94The address 95.Fa sv 96does not specify a valid part of the 97process address space. 98.It Bq Er EMFILE 99Too many descriptors are in use by this process. 100.It Bq Er ENFILE 101The system file table is full. 102.It Bq Er EOPNOTSUPP 103The specified protocol does not support creation of socket pairs. 104.It Bq Er EPROTONOSUPPORT 105The specified protocol is not supported on this machine. 106.El 107.Sh SEE ALSO 108.Xr pipe 2 , 109.Xr read 2 , 110.Xr socket 2 , 111.Xr write 2 112.Sh HISTORY 113The 114.Fn socketpair 115function call appeared in 116.Bx 4.2 . 117.Pp 118Support for the 119.Dv SOCK_CLOEXEC 120and 121.Dv SOCK_NONBLOCK 122flags appeared in 123.Nx 6.0 . 124.Sh BUGS 125This call is currently implemented only for the 126.Dv PF_LOCAL 127domain. 128