Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

socketpair() - create a pair of connected sockets

&pagelevel(4)&pagelevel

#include <sys/socket.h>

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

Description

The socketpair() function creates a pair of sockets that are connected with each other but have no names.

socketpair() creates the socket pair in the address family specified with the domain parameter (AF_INET or AF_UNIX), of type type (SOCK_STREAM or SOCK_DGRAM) and using the optionally specified protocol protocol.

The protocol parameter defines a specific protocol that is to be used for the socket. Since this implementation only supports the TCP/IP protocol family, only the values 0 (standard protocol), IPPROTO_IP, IPPROTO_TCP and IPPROTO_UDP are valid here.

The descriptors of the new socket are returned in the sv[0] and sv[1] parameters. The two sockets cannot be distinguished between.

Return value

0:

If successful.

-1:

If errors occur. errno is set to indicate the error.

Errors

EAFNOSUPPORT

The specified address family is not supported on this system.

EFAULT

The address sv does not specify a valid part of the process address range.

EMFILE

The table of descriptors per process is full.

ENFILE

The system file table is full.

EOPNOTSUPP

The specified protocol does not support creating socket pairs.

EPROTONOSUPPORT

The protocol type or the specified protocol is not supported in this domain.

ENOMEM

An internal resource bottleneck has occurred.

See also

pipe() in "C Library Functions for POSIX Applications", read(), write()