]> git.sur5r.net Git - openldap/blob - libraries/libldap/os-ip.c
ccd24b6db7348f03b764d9b045c8cfce3cb3d3bf
[openldap] / libraries / libldap / os-ip.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*  Portions
7  *  Copyright (c) 1995 Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  os-ip.c -- platform-specific TCP & UDP related code
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/stdlib.h>
18
19 #include <ac/errno.h>
20 #include <ac/socket.h>
21 #include <ac/string.h>
22 #include <ac/time.h>
23 #include <ac/unistd.h>
24
25 #ifdef HAVE_IO_H
26 #include <io.h>
27 #endif /* HAVE_IO_H */
28
29 #include "ldap-int.h"
30
31 int ldap_int_tblsize = 0;
32
33 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
34 #  ifdef LDAP_PF_INET6
35 int ldap_int_inet4or6 = AF_UNSPEC;
36 #  else
37 int ldap_int_inet4or6 = AF_INET;
38 #  endif
39 #endif
40
41 /*
42  * nonblock connect code
43  * written by Lars Uffmann, <lars.uffmann@mediaway.net>.
44  *
45  * Copyright 1999, Lars Uffmann, All rights reserved.
46  * This software is not subject to any license of my employer
47  * mediaWays GmbH.
48  *
49  * OpenLDAP COPYING RESTRICTIONS APPLY, see COPYRIGHT file
50  *
51  * Read about the rationale in ldap_connect_timeout: 
52  * ftp://koobera.math.uic.edu/www/docs/connect.html.
53  */
54
55 #define osip_debug(ld,fmt,arg1,arg2,arg3) \
56 do { \
57         ldap_log_printf(NULL, LDAP_DEBUG_TRACE, fmt, arg1, arg2, arg3); \
58 } while(0)
59
60 static void
61 ldap_pvt_set_errno(int err)
62 {
63         errno = err;
64 }
65
66 int
67 ldap_int_timeval_dup( struct timeval **dest, const struct timeval *src )
68 {
69         struct timeval *new;
70
71         assert( dest != NULL );
72
73         if (src == NULL) {
74                 *dest = NULL;
75                 return 0;
76         }
77
78         new = (struct timeval *) LDAP_MALLOC(sizeof(struct timeval));
79
80         if( new == NULL ) {
81                 *dest = NULL;
82                 return 1;
83         }
84
85         AC_MEMCPY( (char *) new, (const char *) src, sizeof(struct timeval));
86
87         *dest = new;
88         return 0;
89 }
90
91 static int
92 ldap_pvt_ndelay_on(LDAP *ld, int fd)
93 {
94         osip_debug(ld, "ldap_ndelay_on: %d\n",fd,0,0);
95         return ber_pvt_socket_set_nonblock( fd, 1 );
96 }
97    
98 static int
99 ldap_pvt_ndelay_off(LDAP *ld, int fd)
100 {
101         osip_debug(ld, "ldap_ndelay_off: %d\n",fd,0,0);
102         return ber_pvt_socket_set_nonblock( fd, 0 );
103 }
104
105 static ber_socket_t
106 ldap_int_socket(LDAP *ld, int family, int type )
107 {
108         ber_socket_t s = socket(family, type, 0);
109         osip_debug(ld, "ldap_new_socket: %d\n",s,0,0);
110         return ( s );
111 }
112
113 static int
114 ldap_pvt_close_socket(LDAP *ld, int s)
115 {
116         osip_debug(ld, "ldap_close_socket: %d\n",s,0,0);
117         return tcp_close(s);
118 }
119
120 static int
121 ldap_int_prepare_socket(LDAP *ld, int s, int proto )
122 {
123         osip_debug(ld, "ldap_prepare_socket: %d\n", s,0,0);
124
125 #ifdef TCP_NODELAY
126         if( proto == LDAP_PROTO_TCP ) {
127                 int dummy = 1;
128                 if ( setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
129                         (char*) &dummy, sizeof(dummy) ) == AC_SOCKET_ERROR )
130                 {
131                         osip_debug(ld, "ldap_prepare_socket: "
132                                 "setsockopt(%d, TCP_NODELAY) failed (ignored).\n",
133                                 s, 0, 0);
134                 }
135         }
136 #endif
137
138         return 0;
139 }
140
141 #ifndef HAVE_WINSOCK
142
143 #undef TRACE
144 #define TRACE do { \
145         osip_debug(ld, \
146                 "ldap_is_socket_ready: error on socket %d: errno: %d (%s)\n", \
147                 s, \
148                 errno, \
149                 sock_errstr(errno) ); \
150 } while( 0 )
151
152 /*
153  * check the socket for errors after select returned.
154  */
155 static int
156 ldap_pvt_is_socket_ready(LDAP *ld, int s)
157 {
158         osip_debug(ld, "ldap_is_sock_ready: %d\n",s,0,0);
159
160 #if defined( notyet ) /* && defined( SO_ERROR ) */
161 {
162         int so_errno;
163         socklen_t dummy = sizeof(so_errno);
164         if ( getsockopt( s, SOL_SOCKET, SO_ERROR, &so_errno, &dummy )
165                 == AC_SOCKET_ERROR )
166         {
167                 return -1;
168         }
169         if ( so_errno ) {
170                 ldap_pvt_set_errno(so_errno);
171                 TRACE;
172                 return -1;
173         }
174         return 0;
175 }
176 #else
177 {
178         /* error slippery */
179 #ifdef LDAP_PF_INET6
180         struct sockaddr_storage sin;
181 #else
182         struct sockaddr_in sin;
183 #endif
184         char ch;
185         socklen_t dummy = sizeof(sin);
186         if ( getpeername( s, (struct sockaddr *) &sin, &dummy )
187                 == AC_SOCKET_ERROR )
188         {
189                 /* XXX: needs to be replace with ber_stream_read() */
190                 read(s, &ch, 1);
191                 TRACE;
192                 return -1;
193         }
194         return 0;
195 }
196 #endif
197         return -1;
198 }
199 #undef TRACE
200
201 #endif /* HAVE_WINSOCK */
202
203 static int
204 ldap_pvt_connect(LDAP *ld, ber_socket_t s,
205         struct sockaddr *sin, socklen_t addrlen,
206         int async)
207 {
208         int rc;
209         struct timeval  tv, *opt_tv=NULL;
210         fd_set          wfds, *z=NULL;
211 #ifdef HAVE_WINSOCK
212         fd_set          efds;
213 #endif
214
215 #ifdef LDAP_CONNECTIONLESS
216         /* We could do a connect() but that would interfere with
217          * attempts to poll a broadcast address
218          */
219         if (LDAP_IS_UDP(ld)) {
220                 if (ld->ld_options.ldo_peer)
221                         ldap_memfree(ld->ld_options.ldo_peer);
222                 ld->ld_options.ldo_peer=ldap_memalloc(sizeof(struct sockaddr));
223                 AC_MEMCPY(ld->ld_options.ldo_peer,sin,sizeof(struct sockaddr));
224                 return ( 0 );
225         }
226 #endif
227         if ( (opt_tv = ld->ld_options.ldo_tm_net) != NULL ) {
228                 tv.tv_usec = opt_tv->tv_usec;
229                 tv.tv_sec = opt_tv->tv_sec;
230         }
231
232         osip_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n",
233                         s, opt_tv ? tv.tv_sec : -1L, async);
234
235         if ( ldap_pvt_ndelay_on(ld, s) == -1 )
236                 return ( -1 );
237
238         if ( connect(s, sin, addrlen) != AC_SOCKET_ERROR ) {
239                 if ( ldap_pvt_ndelay_off(ld, s) == -1 )
240                         return ( -1 );
241                 return ( 0 );
242         }
243
244 #ifdef HAVE_WINSOCK
245         ldap_pvt_set_errno( WSAGetLastError() );
246 #endif
247
248         if ( errno != EINPROGRESS && errno != EWOULDBLOCK ) {
249                 return ( -1 );
250         }
251         
252 #ifdef notyet
253         if ( async ) return ( -2 );
254 #endif
255
256         FD_ZERO(&wfds);
257         FD_SET(s, &wfds );
258
259 #ifdef HAVE_WINSOCK
260         FD_ZERO(&efds);
261         FD_SET(s, &efds );
262 #endif
263
264         do {
265                 rc = select(ldap_int_tblsize, z, &wfds,
266 #ifdef HAVE_WINSOCK
267                         &efds,
268 #else
269                         z,
270 #endif
271                         opt_tv ? &tv : NULL);
272         } while( rc == AC_SOCKET_ERROR && errno == EINTR &&
273                 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART ));
274
275         if( rc == AC_SOCKET_ERROR ) return rc;
276
277 #ifdef HAVE_WINSOCK
278         /* This means the connection failed */
279         if ( FD_ISSET(s, &efds) ) {
280             int so_errno;
281             int dummy = sizeof(so_errno);
282             if ( getsockopt( s, SOL_SOCKET, SO_ERROR,
283                         (char *) &so_errno, &dummy ) == AC_SOCKET_ERROR || !so_errno )
284             {
285                 /* impossible */
286                 so_errno = WSAGetLastError();
287             }
288             ldap_pvt_set_errno(so_errno);
289             osip_debug(ld, "ldap_pvt_connect: error on socket %d: "
290                        "errno: %d (%s)\n", s, errno, sock_errstr(errno));
291             return -1;
292         }
293 #endif
294         if ( FD_ISSET(s, &wfds) ) {
295 #ifndef HAVE_WINSOCK
296                 if ( ldap_pvt_is_socket_ready(ld, s) == -1 )
297                         return ( -1 );
298 #endif
299                 if ( ldap_pvt_ndelay_off(ld, s) == -1 )
300                         return ( -1 );
301                 return ( 0 );
302         }
303         osip_debug(ld, "ldap_connect_timeout: timed out\n",0,0,0);
304         ldap_pvt_set_errno( ETIMEDOUT );
305         return ( -1 );
306 }
307
308 #ifndef HAVE_INET_ATON
309 int
310 ldap_pvt_inet_aton( const char *host, struct in_addr *in)
311 {
312         unsigned long u = inet_addr( host );
313         if ( u != 0xffffffff || u != (unsigned long) -1 ) {
314                 in->s_addr = u;
315                 return 1;
316         }
317         return 0;
318 }
319 #endif
320
321
322 int
323 ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
324         int proto,
325         const char *host, int port,
326         int async )
327 {
328         int     rc;
329         int     socktype;
330         ber_socket_t            s = AC_SOCKET_INVALID;
331
332 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
333         char serv[7];
334         int err;
335         struct addrinfo hints, *res, *sai;
336 #else
337         int i;
338         int use_hp = 0;
339         struct hostent *hp = NULL;
340         struct hostent he_buf;
341         struct in_addr in;
342         char *ha_buf=NULL;
343 #endif
344
345         if( host == NULL ) host = "localhost";
346         
347         switch(proto) {
348         case LDAP_PROTO_TCP: socktype = SOCK_STREAM;
349                 osip_debug( ld,
350                         "ldap_connect_to_host: TCP %s:%d\n",
351                         host, port, 0);
352                 break;
353         case LDAP_PROTO_UDP: socktype = SOCK_DGRAM;
354                 osip_debug( ld,
355                         "ldap_connect_to_host: UDP %s:%d\n",
356                         host, port, 0);
357                 break;
358         default:
359                 osip_debug( ld, "ldap_connect_to_host: unknown proto: %d\n",
360                         proto, 0, 0 );
361                 return -1;
362         }
363
364 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
365         memset( &hints, '\0', sizeof(hints) );
366         hints.ai_family = ldap_int_inet4or6;
367         hints.ai_socktype = socktype;
368         snprintf(serv, sizeof serv, "%d", port );
369
370 #ifdef LDAP_R_COMPILE
371         /* most getaddrinfo(3) use non-threadsafe resolver libraries */
372         ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
373 #endif
374
375         err = getaddrinfo( host, serv, &hints, &res );
376
377 #ifdef LDAP_R_COMPILE
378         ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex);
379 #endif
380
381         if ( err != 0 ) {
382                 osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n",
383                         AC_GAI_STRERROR(err), 0, 0);
384                 return -1;
385         }
386         rc = -1;
387
388         for( sai=res; sai != NULL; sai=sai->ai_next) {
389                 if( sai->ai_addr == NULL ) {
390                         osip_debug(ld, "ldap_connect_to_host: getaddrinfo "
391                                 "ai_addr is NULL?\n", 0, 0, 0);
392                         continue;
393                 }
394
395                 /* we assume AF_x and PF_x are equal for all x */
396                 s = ldap_int_socket( ld, sai->ai_family, socktype );
397                 if ( s == AC_SOCKET_INVALID ) {
398                         continue;
399                 }
400
401                 if ( ldap_int_prepare_socket(ld, s, proto ) == -1 ) {
402                         ldap_pvt_close_socket(ld, s);
403                         break;
404                 }
405
406                 switch (sai->ai_family) {
407 #ifdef LDAP_PF_INET6
408                         case AF_INET6: {
409                                 char addr[INET6_ADDRSTRLEN];
410                                 inet_ntop( AF_INET6,
411                                         &((struct sockaddr_in6 *)sai->ai_addr)->sin6_addr,
412                                         addr, sizeof addr);
413                                 osip_debug(ld, "ldap_connect_to_host: Trying %s %s\n", 
414                                         addr, serv, 0);
415                         } break;
416 #endif
417                         case AF_INET: {
418                                 char addr[INET_ADDRSTRLEN];
419                                 inet_ntop( AF_INET,
420                                         &((struct sockaddr_in *)sai->ai_addr)->sin_addr,
421                                         addr, sizeof addr);
422                                 osip_debug(ld, "ldap_connect_to_host: Trying %s:%s\n", 
423                                         addr, serv, 0);
424                         } break;
425                 }
426
427                 rc = ldap_pvt_connect( ld, s,
428                         sai->ai_addr, sai->ai_addrlen, async );
429                 if ( (rc == 0) || (rc == -2) ) {
430                         ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &s );
431                         break;
432                 }
433                 ldap_pvt_close_socket(ld, s);
434         }
435         freeaddrinfo(res);
436
437 #else
438         if (! inet_aton( host, &in ) ) {
439                 int local_h_errno;
440                 rc = ldap_pvt_gethostbyname_a( host, &he_buf, &ha_buf,
441                         &hp, &local_h_errno );
442
443                 if ( (rc < 0) || (hp == NULL) ) {
444 #ifdef HAVE_WINSOCK
445                         ldap_pvt_set_errno( WSAGetLastError() );
446 #else
447                         /* not exactly right, but... */
448                         ldap_pvt_set_errno( EHOSTUNREACH );
449 #endif
450                         if (ha_buf) LDAP_FREE(ha_buf);
451                         return -1;
452                 }
453
454                 use_hp = 1;
455         }
456
457         rc = s = -1;
458         for ( i = 0; !use_hp || (hp->h_addr_list[i] != 0); ++i, rc = -1 ) {
459                 struct sockaddr_in      sin;
460
461                 s = ldap_int_socket( ld, PF_INET, socktype );
462                 if ( s == AC_SOCKET_INVALID ) {
463                         /* use_hp ? continue : break; */
464                         break;
465                 }
466            
467                 if ( ldap_int_prepare_socket( ld, s, proto ) == -1 ) {
468                         ldap_pvt_close_socket(ld, s);
469                         break;
470                 }
471
472                 (void)memset((char *)&sin, '\0', sizeof sin);
473                 sin.sin_family = AF_INET;
474                 sin.sin_port = htons((short) port);
475
476                 if( use_hp ) {
477                         AC_MEMCPY( &sin.sin_addr, hp->h_addr_list[i],
478                                 sizeof(sin.sin_addr) );
479                 } else {
480                         AC_MEMCPY( &sin.sin_addr, &in.s_addr,
481                                 sizeof(sin.sin_addr) );
482                 }
483
484                 osip_debug(ld, "ldap_connect_to_host: Trying %s:%d\n", 
485                         inet_ntoa(sin.sin_addr), port, 0);
486
487                 rc = ldap_pvt_connect(ld, s,
488                         (struct sockaddr *)&sin, sizeof(sin),
489                         async);
490    
491                 if ( (rc == 0) || (rc == -2) ) {
492                         ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &s );
493                         break;
494                 }
495
496                 ldap_pvt_close_socket(ld, s);
497
498                 if (!use_hp) break;
499         }
500         if (ha_buf) LDAP_FREE(ha_buf);
501 #endif
502
503         return rc;
504 }
505
506 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND ) || \
507         defined( HAVE_CYRUS_SASL )
508 char *
509 ldap_host_connected_to( Sockbuf *sb )
510 {
511         socklen_t               len;
512 #ifdef LDAP_PF_INET6
513         struct sockaddr_storage sabuf;
514 #else
515         struct sockaddr sabuf;
516 #endif
517         struct sockaddr *sa = (struct sockaddr *) &sabuf;
518         char                    *host = NULL, *herr;
519         char hbuf[NI_MAXHOST];
520         int rc;
521         ber_socket_t    sd;
522
523         (void)memset( (char *)sa, '\0', sizeof sabuf );
524         len = sizeof sabuf;
525
526         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
527         if ( getpeername( sd, sa, &len ) == -1 ) {
528                 return( NULL );
529         }
530
531         /*
532          * do a reverse lookup on the addr to get the official hostname.
533          * this is necessary for kerberos to work right, since the official
534          * hostname is used as the kerberos instance.
535          */
536
537         switch (sa->sa_family) {
538 #ifdef LDAP_PF_LOCAL
539         case AF_LOCAL:
540                 return LDAP_STRDUP( ldap_int_hostname );
541 #endif
542 #ifdef LDAP_PF_INET6
543         case AF_INET6:
544                 {
545                         struct in6_addr localhost = IN6ADDR_LOOPBACK_INIT;
546                         if( memcmp ( &((struct sockaddr_in6 *)sa)->sin6_addr,
547                                 &localhost, sizeof(localhost)) == 0 )
548                         {
549                                 return LDAP_STRDUP( ldap_int_hostname );
550                         }
551                 }
552                 break;
553 #endif
554         case AF_INET:
555                 {
556                         struct in_addr localhost;
557                         localhost.s_addr = htonl( INADDR_ANY );
558
559                         if( memcmp ( &((struct sockaddr_in *)sa)->sin_addr,
560                                 &localhost, sizeof(localhost) ) == 0 )
561                         {
562                                 return LDAP_STRDUP( ldap_int_hostname );
563                         }
564
565 #ifdef INADDR_LOOPBACK
566                         localhost.s_addr = htonl( INADDR_LOOPBACK );
567
568                         if( memcmp ( &((struct sockaddr_in *)sa)->sin_addr,
569                                 &localhost, sizeof(localhost) ) == 0 )
570                         {
571                                 return LDAP_STRDUP( ldap_int_hostname );
572                         }
573 #endif
574                 }
575                 break;
576
577         default:
578                 return( NULL );
579                 break;
580         }
581
582         hbuf[0] = 0;
583         if (ldap_pvt_get_hname( sa, len, hbuf, sizeof(hbuf), &herr ) == 0 &&
584                 hbuf[0] ) 
585         {
586                 host = LDAP_STRDUP( hbuf );   
587         }
588
589         return host;
590 }
591 #endif
592
593
594 /* for UNIX */
595 struct selectinfo {
596         fd_set  si_readfds;
597         fd_set  si_writefds;
598         fd_set  si_use_readfds;
599         fd_set  si_use_writefds;
600 };
601
602
603 void
604 ldap_mark_select_write( LDAP *ld, Sockbuf *sb )
605 {
606         struct selectinfo       *sip;
607         ber_socket_t            sd;
608
609         sip = (struct selectinfo *)ld->ld_selectinfo;
610         
611         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
612         if ( !FD_ISSET( sd, &sip->si_writefds )) {
613                 FD_SET( sd, &sip->si_writefds );
614         }
615 }
616
617
618 void
619 ldap_mark_select_read( LDAP *ld, Sockbuf *sb )
620 {
621         struct selectinfo       *sip;
622         ber_socket_t            sd;
623
624         sip = (struct selectinfo *)ld->ld_selectinfo;
625
626         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
627         if ( !FD_ISSET( sd, &sip->si_readfds )) {
628                 FD_SET( sd, &sip->si_readfds );
629         }
630 }
631
632
633 void
634 ldap_mark_select_clear( LDAP *ld, Sockbuf *sb )
635 {
636         struct selectinfo       *sip;
637         ber_socket_t            sd;
638
639         sip = (struct selectinfo *)ld->ld_selectinfo;
640
641         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
642         FD_CLR( sd, &sip->si_writefds );
643         FD_CLR( sd, &sip->si_readfds );
644 }
645
646
647 int
648 ldap_is_write_ready( LDAP *ld, Sockbuf *sb )
649 {
650         struct selectinfo       *sip;
651         ber_socket_t            sd;
652
653         sip = (struct selectinfo *)ld->ld_selectinfo;
654
655         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
656         return( FD_ISSET( sd, &sip->si_use_writefds ));
657 }
658
659
660 int
661 ldap_is_read_ready( LDAP *ld, Sockbuf *sb )
662 {
663         struct selectinfo       *sip;
664         ber_socket_t            sd;
665
666         sip = (struct selectinfo *)ld->ld_selectinfo;
667
668         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
669         return( FD_ISSET( sd, &sip->si_use_readfds ));
670 }
671
672
673 void *
674 ldap_new_select_info( void )
675 {
676         struct selectinfo       *sip;
677
678         if (( sip = (struct selectinfo *)LDAP_CALLOC( 1,
679             sizeof( struct selectinfo ))) != NULL ) {
680                 FD_ZERO( &sip->si_readfds );
681                 FD_ZERO( &sip->si_writefds );
682         }
683
684         return( (void *)sip );
685 }
686
687
688 void
689 ldap_free_select_info( void *sip )
690 {
691         LDAP_FREE( sip );
692 }
693
694
695 void
696 ldap_int_ip_init( void )
697 {
698         int tblsize;
699 #if defined( HAVE_SYSCONF )
700         tblsize = sysconf( _SC_OPEN_MAX );
701 #elif defined( HAVE_GETDTABLESIZE )
702         tblsize = getdtablesize();
703 #else
704         tblsize = FD_SETSIZE;
705 #endif /* !USE_SYSCONF */
706
707 #ifdef FD_SETSIZE
708         if( tblsize > FD_SETSIZE )
709                 tblsize = FD_SETSIZE;
710 #endif  /* FD_SETSIZE*/
711         ldap_int_tblsize = tblsize;
712 }
713
714
715 int
716 ldap_int_select( LDAP *ld, struct timeval *timeout )
717 {
718         struct selectinfo       *sip;
719
720 #ifdef NEW_LOGGING
721         LDAP_LOG ( CONNECTION, ENTRY, "ldap_int_select\n", 0, 0, 0 );
722 #else
723         Debug( LDAP_DEBUG_TRACE, "ldap_int_select\n", 0, 0, 0 );
724 #endif
725
726         if ( ldap_int_tblsize == 0 )
727                 ldap_int_ip_init();
728
729         sip = (struct selectinfo *)ld->ld_selectinfo;
730         sip->si_use_readfds = sip->si_readfds;
731         sip->si_use_writefds = sip->si_writefds;
732         
733         return( select( ldap_int_tblsize,
734                         &sip->si_use_readfds, &sip->si_use_writefds,
735                         NULL, timeout ));
736 }