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