X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fos-ip.c;h=57195918db1ef1a4f12fa1161cd68ada0155658a;hb=afa2cd1893875266c58677cc640514c1d9eef41f;hp=3f7ae1f615551b288bbd75b48ab8849f00642adc;hpb=ca52123a60416d947b973c5194af11051d015d23;p=openldap diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 3f7ae1f615..57195918db 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -52,11 +52,19 @@ int ldap_int_inet4or6 = AF_INET; * ftp://koobera.math.uic.edu/www/docs/connect.html. */ +#ifdef LDAP_DEBUG + #define osip_debug(ld,fmt,arg1,arg2,arg3) \ do { \ ldap_log_printf(NULL, LDAP_DEBUG_TRACE, fmt, arg1, arg2, arg3); \ } while(0) +#else + +#define osip_debug(ld,fmt,arg1,arg2,arg3) ((void)0) + +#endif /* LDAP_DEBUG */ + static void ldap_pvt_set_errno(int err) { @@ -336,10 +344,10 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, #else int i; int use_hp = 0; - struct hostent *hp = NULL; + struct hostent *hp = NULL; struct hostent he_buf; struct in_addr in; - char *ha_buf=NULL, *p, *q; + char *ha_buf=NULL; #endif if( host == NULL ) host = "localhost"; @@ -472,15 +480,20 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, (void)memset((char *)&sin, '\0', sizeof sin); sin.sin_family = AF_INET; sin.sin_port = htons((short) port); - p = (char *)&sin.sin_addr; - q = use_hp ? (char *)hp->h_addr_list[i] : (char *)&in.s_addr; - AC_MEMCPY(p, q, sizeof(sin.sin_addr) ); + + if( use_hp ) { + AC_MEMCPY( &sin.sin_addr, hp->h_addr_list[i], + sizeof(sin.sin_addr) ); + } else { + AC_MEMCPY( &sin.sin_addr, &in.s_addr, + sizeof(sin.sin_addr) ); + } osip_debug(ld, "ldap_connect_to_host: Trying %s:%d\n", - inet_ntoa(sin.sin_addr),port,0); + inet_ntoa(sin.sin_addr), port, 0); rc = ldap_pvt_connect(ld, s, - (struct sockaddr *)&sin, sizeof(struct sockaddr_in), + (struct sockaddr *)&sin, sizeof(sin), async); if ( (rc == 0) || (rc == -2) ) { @@ -490,8 +503,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, ldap_pvt_close_socket(ld, s); - if (!use_hp) - break; + if (!use_hp) break; } if (ha_buf) LDAP_FREE(ha_buf); #endif @@ -502,7 +514,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND ) || \ defined( HAVE_CYRUS_SASL ) char * -ldap_host_connected_to( Sockbuf *sb ) +ldap_host_connected_to( Sockbuf *sb, const char *host ) { socklen_t len; #ifdef LDAP_PF_INET6 @@ -511,8 +523,6 @@ ldap_host_connected_to( Sockbuf *sb ) struct sockaddr sabuf; #endif struct sockaddr *sa = (struct sockaddr *) &sabuf; - char *host = NULL, *herr; - char hbuf[NI_MAXHOST]; int rc; ber_socket_t sd; @@ -575,14 +585,21 @@ ldap_host_connected_to( Sockbuf *sb ) break; } - hbuf[0] = 0; - if (ldap_pvt_get_hname( sa, len, hbuf, sizeof(hbuf), &herr ) == 0 && - hbuf[0] ) +#if 0 { - host = LDAP_STRDUP( hbuf ); + char *herr; + char hbuf[NI_MAXHOST]; + hbuf[0] = 0; + + if (ldap_pvt_get_hname( sa, len, hbuf, sizeof(hbuf), &herr ) == 0 + && hbuf[0] ) + { + return LDAP_STRDUP( hbuf ); + } } +#endif - return host; + return host ? LDAP_STRDUP( host ) : NULL; } #endif