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