3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 /* Return a pair of socket descriptors that are connected to each other.
14 * The returned descriptors are suitable for use with select(). The two
15 * descriptors may or may not be identical; the function may return
16 * the same descriptor number in both slots. It is guaranteed that
17 * data written on sds[1] will be readable on sds[0]. The returned
18 * descriptors may be datagram oriented, so data should be written
19 * in reasonably small pieces and read all at once. On Unix systems
20 * this function is best implemented using a single pipe() call.
23 int lutil_pair( LBER_SOCKET_T sds[2] )
28 struct sockaddr_in si;
29 int rc, len = sizeof(si);
32 sd = socket( AF_INET, SOCK_DGRAM, 0 );
33 if ( sd == AC_SOCKET_INVALID )
36 (void) memset( (void*) &si, 0, len );
37 si.sin_family = AF_INET;
39 si.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
41 rc = bind( sd, (struct sockaddr *)&si, len );
42 if ( rc == AC_SOCKET_ERROR ) {
47 rc = getsockname( sd, (struct sockaddr *)&si, &len );
48 if ( rc == AC_SOCKET_ERROR ) {
53 rc = connect( sd, (struct sockaddr *)&si, len );
54 if ( rc == AC_SOCKET_ERROR ) {