Creates a pair of connected sockets. Format #include <sys/socket.h> int socketpair (int domain, int type, int protocol, int socket_vector[2]);
1 – Arguments
af The address family in which the sockets are to be created. Use one of the following: o AF_INET for the IPv4 address family o AF_INET6 for the IPv6 address family o TCPIP$C_AUXS or a network application server with the LISTEN flag enabled. Specify the TCPIP$C_AUXS address family to obtain the connected device socket created by the auxiliary server in response to incoming network traffic. type Specifies the type of sockets to be created. The socket types are: o SOCK_STREAM - Provides sequenced, reliable, two-way, connection-based byte streams with an available out-of-band data transmission mechanism. o SOCK_DGRAM - Supports datagrams (connectionless, unreliable data transmission mechanism). o SOCK_SEQPACKET - Provides sequenced, reliable, bidirectional, connection-mode transmission paths 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. Use the MSG_EOR flag to determine the record boundaries. protocol The protocol to be used with the socket. Normally, only a single protocol exists to support a particular socket type using a given address format. However, if many protocols exist, a particular protocol must be specified with this argument. Use the protocol number that is specific to the address family. If the protocol argument is 0, the function uses the default protocol for the specified socket type. If the protocol argument is non-zero, the function uses the default protocol for the address family. socket_vector A 2-integer array to hold the file descriptors of the created socket pair.
2 – Description
This function creates an unbound pair of connected sockets in a specified address family, of a specified type, under the protocol optionally specified by the protocol argument. The two sockets will be identical. The file descriptors used in referencing the created sockets are returned in socket_vector[0] and socket_ vector[1]. Appropriate privileges are required to use the socketpair() function or to create some sockets. Related Functions See also socket().
3 – Return Values
0 Successful completion -1 Error; errno is set to indicate the error.
4 – Errors
EACCES The process does not have sufficient privileges. EAFNOSUPPORT The specified address family is not supported in this version of the system. EMFILE The per-process descriptor table is full. ENETDOWN TCP/IP Services was not started. ENFILE No more file descriptors are available for the system. ENOBUFS The system has insufficient resources to complete the call. ENOMEM The system was unable to allocate kernel memory to increase the process descriptor table. EPERM The process is attempting to open a raw socket and does not have SYSTEM privilege. EPROTONOSUPPORT The socket in the specified address family is not supported. EPROTOTYPE The socket type is not supported by the protocol. ESOCKTNOSUPPORT The specified socket type is not supported in this address family.