Back to index

openldap  2.4.31
Functions
sockpair.c File Reference
#include "portable.h"
#include <ac/socket.h>
#include <ac/unistd.h>
#include <lutil.h>

Go to the source code of this file.

Functions

int lutil_pair (ber_socket_t sds[2])

Function Documentation

int lutil_pair ( ber_socket_t  sds[2])

Definition at line 32 of file sockpair.c.

{
#ifdef USE_PIPE
       return pipe( sds );
#else
       struct sockaddr_in si;
       int rc;
       ber_socklen_t len = sizeof(si);
       ber_socket_t sd;

       sd = socket( AF_INET, SOCK_DGRAM, 0 );
       if ( sd == AC_SOCKET_INVALID ) {
              return sd;
       }
       
       (void) memset( (void*) &si, '\0', len );
       si.sin_family = AF_INET;
       si.sin_port = 0;
       si.sin_addr.s_addr = htonl( INADDR_LOOPBACK );

       rc = bind( sd, (struct sockaddr *)&si, len );
       if ( rc == AC_SOCKET_ERROR ) {
              tcp_close(sd);
              return rc;
       }

       rc = getsockname( sd, (struct sockaddr *)&si, &len );
       if ( rc == AC_SOCKET_ERROR ) {
              tcp_close(sd);
              return rc;
       }

       rc = connect( sd, (struct sockaddr *)&si, len );
       if ( rc == AC_SOCKET_ERROR ) {
              tcp_close(sd);
              return rc;
       }

       sds[0] = sd;
#if !HAVE_WINSOCK
       sds[1] = dup( sds[0] );
#else
       sds[1] = sds[0];
#endif
       return 0;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function: