socketpair
Prototype:
#include <sys/socket.h>
#include <resolv.h>
int socketpair(int domain, int type, int protocol,
    int sockfds[2]);
General Description: Creates a pair of sockets that are linked together like a pipe, but uses the socket subsystem. It is nearly identical to a pipe() system call, but gives you the added functionality of the socket API. Socketpair() supports PF_UNIX or PF_LOCAL sockets only. You do not need to bind() this socket to a file system file name.
Return Value: Zero (0) if everything goes well. If an error occurs, you can find the cause in errno.
Parameters
domain Must be PF_LOCAL or PF_UNIX.
type May be either SOCK_STREAM: This creates a socket like a pipe(). On some Unix systems the pipe is bidirectional. Posix 1, however, does not require bidirectionality.
protocol Must be zero (0).
sockfds[2] An array of integers into which the call stores the new socket descriptors if successful.
Possible Errors
EMFILE Too many descriptors are in use by this process.
EAFNOSUPPORT The specified address family is not supported on this machine.
EPROTONOSUPPORT The specified protocol is not supported on this machine.
EOPNOSUPPORT The specified protocol does not support creation of socket pairs.
EFAULT The address sockfds does not specify a valid part of the process address space.
Examples
int sockfd[2];
struct sockaddr_ux addr;
if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sockfd) != 0 )
    perror("socketpair");