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