1
1
/* os-ip.c -- platform-specific TCP & UDP related code */
2
/* $OpenLDAP: pkg/ldap/libraries/libldap/os-ip.c,v 1.118.2.8 2008/05/20 00:05:30 quanah Exp $ */
2
/* $OpenLDAP: pkg/ldap/libraries/libldap/os-ip.c,v 1.118.2.14 2009/02/10 23:42:16 quanah Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5
* Copyright 1998-2008 The OpenLDAP Foundation.
5
* Copyright 1998-2009 The OpenLDAP Foundation.
6
6
* Portions Copyright 1999 Lars Uffmann.
7
7
* All rights reserved.
428
ldap_int_connect_cbs(LDAP *ld, Sockbuf *sb, ber_socket_t *s, LDAPURLDesc *srv, struct sockaddr *addr)
430
struct ldapoptions *lo;
435
ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, s );
437
/* Invoke all handle-specific callbacks first */
438
lo = &ld->ld_options;
439
for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
441
rc = cb->lc_add( ld, sb, srv, addr, cb );
442
/* on any failure, call the teardown functions for anything
443
* that previously succeeded
447
for (l2 = lo->ldo_conn_cbs; l2 != ll; l2 = l2->ll_next) {
449
cb->lc_del( ld, sb, cb );
451
/* a failure might have implicitly closed the fd */
452
ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, s );
456
lo = LDAP_INT_GLOBAL_OPT();
457
for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
459
rc = cb->lc_add( ld, sb, srv, addr, cb );
462
for (l2 = lo->ldo_conn_cbs; l2 != ll; l2 = l2->ll_next) {
464
cb->lc_del( ld, sb, cb );
466
lo = &ld->ld_options;
467
for (l2 = lo->ldo_conn_cbs; l2; l2 = l2->ll_next) {
469
cb->lc_del( ld, sb, cb );
471
ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, s );
429
479
ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
431
const char *host, int port,
480
int proto, LDAPURLDesc *srv,
436
485
ber_socket_t s = AC_SOCKET_INVALID;
438
488
#if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
448
498
char *ha_buf=NULL;
451
if( host == NULL ) host = "localhost";
501
if ( srv->lud_host == NULL || *srv->lud_host == 0 ) {
504
host = srv->lud_host;
507
port = srv->lud_port;
510
if( strcmp(srv->lud_scheme, "ldaps") == 0 ) {
454
518
case LDAP_PROTO_TCP: socktype = SOCK_STREAM;
470
534
#if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
471
535
memset( &hints, '\0', sizeof(hints) );
472
#ifdef USE_AI_ATTRCONFIG /* FIXME: configure test needed */
473
/* Use AI_ATTRCONFIG only on systems where its known to be needed. */
474
hints.ai_flags = AI_ATTRCONFIG;
536
#ifdef USE_AI_ADDRCONFIG /* FIXME: configure test needed */
537
/* Use AI_ADDRCONFIG only on systems where its known to be needed. */
538
hints.ai_flags = AI_ADDRCONFIG;
476
540
hints.ai_family = ldap_int_inet4or6;
477
541
hints.ai_socktype = socktype;
537
601
rc = ldap_pvt_connect( ld, s,
538
602
sai->ai_addr, sai->ai_addrlen, async );
539
603
if ( rc == 0 || rc == -2 ) {
540
ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &s );
604
err = ldap_int_connect_cbs( ld, sb, &s, srv, sai->ai_addr );
543
610
ldap_pvt_close_socket(ld, s);
611
678
if ( (rc == 0) || (rc == -2) ) {
612
ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &s );
679
i = ldap_int_connect_cbs( ld, sb, &s, srv, (struct sockaddr *)&sin );
616
686
ldap_pvt_close_socket(ld, s);
888
958
sip = (struct selectinfo *)ld->ld_selectinfo;
960
if (ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ))
890
963
ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );