X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fos-ip.c;h=57195918db1ef1a4f12fa1161cd68ada0155658a;hb=afa2cd1893875266c58677cc640514c1d9eef41f;hp=b5601ba25874c0f250cf6f2e1b123b3d04886518;hpb=978c94a223e71df10137965daa47812ee78b3e3f;p=openldap diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index b5601ba258..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) { @@ -325,19 +333,22 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, const char *host, int port, int async ) { + int rc; + int socktype; ber_socket_t s = AC_SOCKET_INVALID; - int rc, i, use_hp = 0; - struct hostent *hp = NULL; + #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP ) char serv[7]; int err; struct addrinfo hints, *res, *sai; #else + int i; + int use_hp = 0; + struct hostent *hp = NULL; struct hostent he_buf; struct in_addr in; + char *ha_buf=NULL; #endif - char *ha_buf=NULL, *p, *q; - int socktype; if( host == NULL ) host = "localhost"; @@ -469,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) ) { @@ -487,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 @@ -499,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 @@ -508,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; @@ -572,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