Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Thursday, June 13, 2019
 
 

socketpair (3C)

Name

socketpair - create a pair of connected sockets

Synopsis

#include <sys/socket.h>

int socketpair(int 
domain, int type, 
int protocol, int 
sv[2]);

Description

The socketpair() library call creates an unnamed pair of connected sockets in the specified address family domain, of the specified type, that uses the optionally specified protocol. The descriptors that are used in referencing the new sockets are returned in sv[0] and sv[1]. The two sockets are indistinguishable.

Some file descriptor flags can be specified at socket creation time to avoid race conditions. These options are passed by using a bitwise-inclusive-OR of flags with the value passed for the type parameter to the socket(). See the socket(3c) man page for the available flags.

Return Values

socketpair() returns −1 on failure and 0 on success.

Errors

The call succeeds unless:

EAFNOSUPPORT

The specified address family is not supported on this machine.

EMFILE

Too many descriptors are in use by this process.

ENOMEM

There was insufficient user memory for the operation to complete.

ENOSR

There were insufficient STREAMS resources for the operation to complete.

EOPNOTSUPP

The specified protocol does not support creation of socket pairs.

EPROTONOSUPPORT

The specified protocol is not supported on this machine.

EACCES

The process does not have appropriate privileges.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Async-Signal-Safe
Standard

See Also

pipe(2), read(2), write(2), socket.h(3HEAD), attributes(7)

Notes

This call is currently implemented only for the AF_UNIX address family.

HISTORY

Support for SOCK_* flags as part of the type parameter was added to Oracle Solaris in the 11.4 release.