* 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)
{
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";
(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) ) {
ldap_pvt_close_socket(ld, s);
- if (!use_hp)
- break;
+ if (!use_hp) break;
}
if (ha_buf) LDAP_FREE(ha_buf);
#endif
#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
struct sockaddr sabuf;
#endif
struct sockaddr *sa = (struct sockaddr *) &sabuf;
- char *host = NULL, *herr;
- char hbuf[NI_MAXHOST];
int rc;
ber_socket_t sd;
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