/* socketpair() - Greg Wooledge for SCO Unix 3.2v4.2. */ #include #include /* Create two sockets and connect them together. */ int socketpair (domain, type, protocol, fds) int domain, type, protocol, fds[2]; { int s1, s2; struct sockaddr name1, name2; int namelen1, namelen2; int err; /* Create sockets. */ s1 = socket (domain, type, protocol); if (s1 < 0) return s1; s2 = socket (domain, type, protocol); if (s2 < 0) return s2; /* Get the current names for the sockets. */ namelen1 = sizeof (name1); err = getsockname (s1, &name1, &namelen1); if (err != 0) return err; namelen2 = sizeof (name2); err = getsockname (s1, &name2, &namelen2); if (err != 0) return err; /* Connect them. */ err = connect (s1, &name2, namelen2); if (err != 0) return err; err = connect (s2, &name1, namelen1); if (err != 0) return err; /* Return the socket fd's. */ fds[0] = s1; fds[1] = s2; return 0; }