socketpair(3N-xs) (X/OPEN SOCKETS) socketpair(3N-xs)
NAME
socketpair - create a pair of connected sockets
SYNOPSIS
cc [flag ...] file ... -lxnet [library ...]
#include <sys/socket.h>
int socketpair(int domain, int type, int protocol,
int socketvector[2]);
DESCRIPTION
The socketpair function creates an unbound pair of connected sockets
in a specified domain, of a specified type, under the protocol option-
ally specified by the protocol argument. The two sockets are identi-
cal. The file descriptors used in referencing the created sockets are
returned in socketvector[0] and socketvector[1].
domain Specifies the communications domain in which the sock-
ets are to be created.
type Specifies the type of sockets to be created.
protocol Specifies a particular protocol to be used with the
sockets. Specifying a protocol of 0 causes socketpair
to use an unspecified default protocol appropriate for
the requested socket type.
socketvector Specifies a 2-integer array to hold the file descrip-
tors of the created socket pair.
The type argument specifies the socket type, which determines the
semantics of communications over the socket. The socket types sup-
ported by the system are implementation-dependent. Possible socket
types include:
SOCKSTREAM Provides sequenced, reliable, bidirectional, connec-
tion-oriented byte streams, and may provide a trans-
mission mechanism for out-of-band data.
SOCKDGRAM Provides datagrams, which are connectionless, unreli-
able messages of fixed maximum length.
SOCKSEQPACKET Provides sequenced, reliable, bidirectional, connec-
tion-oriented transmission path for records. A record
can be sent using one or more output operations and
received using one or more input operations, but a
single operation never transfers part of more than one
record. Record boundaries are visible to the receiver
via the MSGEOR flag.
Page 1 Reliant UNIX 5.44 Printed 11/98
socketpair(3N-xs) (X/OPEN SOCKETS) socketpair(3N-xs)
If the protocol argument is non-zero, it must specify a protocol that
is supported by the address family. The protocols supported by the
system are implementation-dependent.
RETURN VALUE
Upon successful completion, this function returns 0. Otherwise, -1 is
returned and errno is set to indicate the error.
ERRORS
The socketpair function will fail if:
EAFNOSUPPORT The implementation does not support the specified
address family.
EMFILE No more file descriptors are available for this pro-
cess.
ENFILE No more file descriptors are available for the system.
EOPNOTSUPP The specified protocol does not permit creation of
socket pairs.
EPROTONOSUPPORT The protocol is not supported by the address family,
or the protocol is not supported by the implementa-
tion.
EPROTOTYPE The socket type is not supported by the protocol.
The socketpair function may fail if:
EACCES The process does not have appropriate privileges.
ENOMEM The memory available was not sufficient to fulfill the
request.
ENOBUFS The resources available in the system were not suffi-
cient to perform the operation.
ENOSR The STREAMS resources available were not sufficient to
complete the operation.
APPLICATION USAGE
The documentation for specific address families specifies which proto-
cols each address family supports. The documentation for specific pro-
tocols specifies which socket types each protocol supports.
The socketpair function is used primarily with UNIX domain sockets and
need not be supported for other domains.
SEE ALSO
socket(3N-xs).
Page 2 Reliant UNIX 5.44 Printed 11/98