#include <winsock2.h>
#elif HAVE_WINSOCK
#include <winsock.h>
+#else
+#define WSACleanup()
#endif
#ifdef HAVE_PCNFS
#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 )
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;
ldap_free_select_info( ld->ld_selectinfo );
#endif /* LDAP_REFERRALS */
free( (char*)ld );
+ WSACleanup( );
return( NULL );
}
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;
rc = 0;
break;
} else {
+#ifdef HAVE_WINSOCK
+ errno = WSAGetLastError();
+#endif
#ifdef notyet
#ifdef LDAP_REFERRALS
#ifdef EAGAIN
perror( (char *)inet_ntoa( sin.sin_addr ));
}
#endif
- close( s );
+ tcp_close( s );
if ( !use_hp ) {
break;
}