- defport = htons( defport );
-
- if ( host != NULL ) {
- for ( p = host; p != NULL && *p != '\0'; p = q ) {
- if (( q = strchr( p, ' ' )) != NULL ) {
- strncpy( hostname, p, q - p );
- hostname[ q - p ] = '\0';
- curhost = hostname;
- while ( *q == ' ' ) {
- ++q;
- }
- } else {
- curhost = p; /* avoid copy if possible */
- q = NULL;
- }
-
- if (( r = strchr( curhost, ':' )) != NULL ) {
- if ( curhost != hostname ) {
- strcpy( hostname, curhost ); /* now copy */
- r = hostname + ( r - curhost );
- curhost = hostname;
- }
- *r++ = '\0';
- port = htons( (short)atoi( r ));
- } else {
- port = defport;
- }
-
- if (( rc = ldap_connect_to_host( sb, curhost, 0L,
- port, async )) != -1 ) {
- break;
- }
- }
- } else {
- rc = ldap_connect_to_host( sb, NULL, htonl( INADDR_LOOPBACK ),
- defport, async );
+ port = srv->lud_port;
+ if (port == 0)
+ port = ld->ld_options.ldo_defport;
+ port = htons( (short) port );
+
+ addr = 0;
+ if ( srv->lud_host == NULL || *srv->lud_host == 0 )
+ addr = htonl( INADDR_LOOPBACK );
+
+ switch ( srv->lud_protocol ) {
+ case LDAP_PROTO_TCP:
+ rc = ldap_connect_to_host( ld, sb, srv->lud_host,
+ addr, port, async );
+ if ( rc == -1 )
+ return rc;
+ ber_sockbuf_add_io( sb, &ber_sockbuf_io_tcp,
+ LBER_SBIOD_LEVEL_PROVIDER, NULL );
+ break;
+ case LDAP_PROTO_UDP:
+ rc = ldap_connect_to_host( ld, sb, srv->lud_host,
+ addr, port, async );
+ if ( rc == -1 )
+ return rc;
+ ber_sockbuf_add_io( sb, &ber_sockbuf_io_udp,
+ LBER_SBIOD_LEVEL_PROVIDER, NULL );
+ break;
+#ifdef LDAP_PF_LOCAL
+ case LDAP_PROTO_LOCAL:
+ rc = ldap_connect_to_path( ld, sb, srv->lud_host,
+ async );
+ if ( rc == -1 )
+ return rc;
+ ber_sockbuf_add_io( sb, &ber_sockbuf_io_fd,
+ LBER_SBIOD_LEVEL_PROVIDER, NULL );
+ break;
+#endif /* LDAP_PF_LOCAL */
+ default:
+ return -1;
+ break;