3 * Copyright 1998-2000 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( ber_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 ) {
37 (void) memset( (void*) &si, '\0', len );
38 si.sin_family = AF_INET;
40 si.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
42 rc = bind( sd, (struct sockaddr *)&si, len );
43 if ( rc == AC_SOCKET_ERROR ) {
48 rc = getsockname( sd, (struct sockaddr *)&si, &len );
49 if ( rc == AC_SOCKET_ERROR ) {
54 rc = connect( sd, (struct sockaddr *)&si, len );
55 if ( rc == AC_SOCKET_ERROR ) {
62 sds[1] = dup( sds[0] );