From 1da400ea6b5ac311bb65f807cc9920a7c1be7718 Mon Sep 17 00:00:00 2001 From: MuQun Yang Date: Wed, 24 Apr 2002 09:58:26 -0500 Subject: [svn-r5245] Purpose: windows support of socket function Description: gethostname is treated as socket function in windows and it is defined at winsock.h. for every windows socket function to be called, it must start with WSAStartup and end with WSACleanup Solution: Add WSAstartup and WSACleanup with WIN32 macro. Platforms tested: windows 2000, confirmed at linux 2.2.18 --- test/h5test.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/h5test.c b/test/h5test.c index e0c46a6..05d5147 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -17,6 +17,7 @@ #ifdef WIN32 #include #include +#include #endif /* WIN32 */ /* @@ -523,6 +524,10 @@ void h5_show_hostname(void) { char hostname[80]; +#ifdef WIN32 + WSADATA wsaData; + int err; +#endif /* try show the process or thread id in multiple processes cases*/ #ifdef H5_HAVE_PARALLEL @@ -541,9 +546,35 @@ h5_show_hostname(void) #else printf("thread 0."); #endif +#ifdef WIN32 + + err = WSAStartup( MAKEWORD(2,2), &wsaData ); + if ( err != 0 ) { + /* could not find a usable WinSock DLL */ + return; + } + +/* Confirm that the WinSock DLL supports 2.2.*/ +/* Note that if the DLL supports versions greater */ +/* than 2.2 in addition to 2.2, it will still return */ +/* 2.2 in wVersion since that is the version we */ +/* requested. */ + + if ( LOBYTE( wsaData.wVersion ) != 2 || + HIBYTE( wsaData.wVersion ) != 2 ) { + /* could not find a usable WinSock DLL */ + WSACleanup( ); + return; + } + +#endif + if (gethostname(hostname, 80) < 0){ printf(" gethostname failed\n"); } else printf(" hostname=%s\n", hostname); +#ifdef WIN32 + WSACleanup(); +#endif } -- cgit v0.12