From 5c296dc0bafe1e4ac9c4a36df9d7fe9bfbd17573 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 23 Oct 1998 17:42:19 +0000 Subject: [PATCH] Minor changes to support NT. --- include/ac/socket.h | 4 +++- libraries/libldap/open.c | 38 ++++++++++++++++++++++++++++++++++++++ libraries/libldap/os-ip.c | 9 ++++++++- libraries/libldap/unbind.c | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/ac/socket.h b/include/ac/socket.h index c8c7e28140..a27da0db87 100644 --- a/include/ac/socket.h +++ b/include/ac/socket.h @@ -27,6 +27,8 @@ #include #elif HAVE_WINSOCK #include +#else +#define WSACleanup() #endif #ifdef HAVE_PCNFS @@ -48,7 +50,7 @@ #define tcp_close( s ) netclose( s ); netshut() #endif /* NCSA */ #ifdef WINSOCK -#define tcp_close( s ) closesocket( s ); WSACleanup(); +#define tcp_close( s ) closesocket( s ); #endif /* WINSOCK */ #else /* DOS */ #define tcp_close( s ) close( s ) diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index 3ea3eea14a..f92147f415 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -111,14 +111,51 @@ ldap_init( char *defhost, int defport ) Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 ); +#ifdef HAVE_WINSOCK2 +{ WORD wVersionRequested; + WSADATA wsaData; + int err; + + wVersionRequested = MAKEWORD( 2, 0 ); + + err = WSAStartup( wVersionRequested, &wsaData ); + if ( err != 0 ) { + /* Tell the user that we couldn't find a usable */ + /* WinSock DLL. */ + return NULL; + } + + /* Confirm that the WinSock DLL supports 2.0.*/ + /* Note that if the DLL supports versions greater */ + /* than 2.0 in addition to 2.0, it will still return */ + /* 2.0 in wVersion since that is the version we */ + /* requested. */ + + if ( LOBYTE( wsaData.wVersion ) != 2 || + HIBYTE( wsaData.wVersion ) != 0 ) + { + /* Tell the user that we couldn't find a usable */ + /* WinSock DLL. */ + WSACleanup( ); + return NULL; + } +} /* The WinSock DLL is acceptable. Proceed. */ + +#elif HAVE_WINSOCK + if ( WSAStartup( 0x0101, &wsadata ) != 0 ) { + return( NULL ); + } +#endif if ( (ld = (LDAP *) calloc( 1, sizeof(LDAP) )) == NULL ) { + WSACleanup( ); return( NULL ); } #ifdef LDAP_REFERRALS if (( ld->ld_selectinfo = ldap_new_select_info()) == NULL ) { free( (char*)ld ); + WSACleanup( ); return( NULL ); } ld->ld_options = LDAP_OPT_REFERRALS; @@ -130,6 +167,7 @@ ldap_init( char *defhost, int defport ) ldap_free_select_info( ld->ld_selectinfo ); #endif /* LDAP_REFERRALS */ free( (char*)ld ); + WSACleanup( ); return( NULL ); } diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 7105dc1c77..e87cb0cb46 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -58,7 +58,11 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, if ( host != NULL && ( address = inet_addr( host )) == -1 ) { if ( (hp = gethostbyname( host )) == NULL ) { +#ifdef HAVE_WINSOCK + errno = WSAGetLastError(); +#else errno = EHOSTUNREACH; /* not exactly right, but... */ +#endif return( -1 ); } use_hp = 1; @@ -91,6 +95,9 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, rc = 0; break; } else { +#ifdef HAVE_WINSOCK + errno = WSAGetLastError(); +#endif #ifdef notyet #ifdef LDAP_REFERRALS #ifdef EAGAIN @@ -111,7 +118,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address, perror( (char *)inet_ntoa( sin.sin_addr )); } #endif - close( s ); + tcp_close( s ); if ( !use_hp ) { break; } diff --git a/libraries/libldap/unbind.c b/libraries/libldap/unbind.c index 449026ce7e..2fc2727c3d 100644 --- a/libraries/libldap/unbind.c +++ b/libraries/libldap/unbind.c @@ -105,6 +105,8 @@ ldap_ld_free( LDAP *ld, int close ) free( (char *) ld ); + WSACleanup(); + return( err ); } -- 2.39.5