From: Hallvard Furuseth Date: Thu, 12 Nov 1998 02:24:43 +0000 (+0000) Subject: Check if inet_addr() returns 0xffffffff as well as -1. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~1131 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ce5dcbc5229e16f1c020d5989733e01657b5d0d2;p=openldap Check if inet_addr() returns 0xffffffff as well as -1. It returns (int)0xffffffff on OSF1 which has 64-bit long, so `unsigned long address; ... if((address = inet_addr(str)) == -1)' fails. --- diff --git a/libraries/libldap/cldap.c b/libraries/libldap/cldap.c index c12859b858..9403c090c0 100644 --- a/libraries/libldap/cldap.c +++ b/libraries/libldap/cldap.c @@ -105,7 +105,10 @@ cldap_open( char *host, int port ) } } - if ( (address = inet_addr( host )) == (unsigned long) -1L ) { + address = inet_addr( host ); + /* This was just a test for -1 until OSF1 let inet_addr return + unsigned int, which is narrower than 'unsigned long address' */ + if ( address == 0xffffffff || address == (unsigned long) -1 ) { if ( (hp = gethostbyname( host )) == NULL ) { errno = EHOSTUNREACH; continue; diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 4642144b20..56aa3deecf 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -54,7 +54,11 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, connected = use_hp = 0; - if ( host != NULL && ( address = inet_addr( host )) == (unsigned long) -1L ) { + if ( host != NULL ) { + address = inet_addr( host ); + /* This was just a test for -1 until OSF1 let inet_addr return + unsigned int, which is narrower than 'unsigned long address' */ + if ( address == 0xffffffff || address == (unsigned long) -1 ) { if ( (hp = gethostbyname( host )) == NULL ) { #ifdef HAVE_WINSOCK errno = WSAGetLastError(); @@ -64,6 +68,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, return( -1 ); } use_hp = 1; + } } rc = -1;