]> git.sur5r.net Git - openldap/commitdiff
Minor changes to support NT.
authorKurt Zeilenga <kurt@openldap.org>
Fri, 23 Oct 1998 17:42:19 +0000 (17:42 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 23 Oct 1998 17:42:19 +0000 (17:42 +0000)
include/ac/socket.h
libraries/libldap/open.c
libraries/libldap/os-ip.c
libraries/libldap/unbind.c

index c8c7e28140a26991c86485f29dd88c23d772ebb7..a27da0db8764f092d8e81f4a403042f0eb424542 100644 (file)
@@ -27,6 +27,8 @@
 #include <winsock2.h>
 #elif HAVE_WINSOCK
 #include <winsock.h>
+#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 )
index 3ea3eea14afb3844fe07e8b19783a3c2c774bada..f92147f4150fdcbb0c919b07674a56b45c4282ed 100644 (file)
@@ -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 );
        }
 
index 7105dc1c776d56ebc0764243cdd714c08abe348b..e87cb0cb46c997dc717f925127df80eae07572d3 100644 (file)
@@ -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;
                        }
index 449026ce7e7b4be2b8217ef66e80e5c20638c86b..2fc2727c3df98d5d329d5f286b58fa681c1e5ce1 100644 (file)
@@ -105,6 +105,8 @@ ldap_ld_free( LDAP *ld, int close )
 
        free( (char *) ld );
 
+       WSACleanup();
+
        return( err );
 }