From b49973db8489f02e10e3475b6a8a199d919a6efa Mon Sep 17 00:00:00 2001 From: David Date: Wed, 14 Jan 2009 21:06:20 +0000 Subject: david - WSA functions --- src/win32_compatibility.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ src/win32_compatibility.h | 9 ++++++++ 2 files changed, 62 insertions(+) (limited to 'src') diff --git a/src/win32_compatibility.cpp b/src/win32_compatibility.cpp index 0ef3abc..083925b 100644 --- a/src/win32_compatibility.cpp +++ b/src/win32_compatibility.cpp @@ -2,6 +2,59 @@ #ifdef WIN32 +typedef int (__cdecl *FNDEF_DYN_WSAStartup)(WORD,LPWSADATA); +int DynamicWinsock2::WSAStartup( + WORD wVersionRequested,LPWSADATA lpWSAData) +{ + int out=0; + HINSTANCE Ws2_32 = LoadLibrary(TEXT("WS2_32.DLL")); + printf("ws2_32 dll: %08x\n", (int) Ws2_32); + if( Ws2_32 != NULL ) + { + FNDEF_DYN_WSAStartup fn = (FNDEF_DYN_WSAStartup) + GetProcAddress( Ws2_32, "WSAStartup" ); + printf("WSAStartup function pointer: %08x\n", (int)fn); + if( fn != NULL ) + out = (fn)(wVersionRequested,lpWSAData); + } + return out; +} + +typedef int (__cdecl *FNDEF_DYN_WSACleanup)(); +int DynamicWinsock2::WSACleanup() +{ + int out=0; + HINSTANCE Ws2_32 = LoadLibrary(TEXT("WS2_32.DLL")); + printf("ws2_32 dll: %08x\n", (int) Ws2_32); + if( Ws2_32 != NULL ) + { + FNDEF_DYN_WSACleanup fn = (FNDEF_DYN_WSACleanup) + GetProcAddress( Ws2_32, "WSACleanup" ); + printf("WSACleanup function pointer: %08x\n", (int)fn); + if( fn != NULL ) + out = (fn)(); + } + return out; +} + +//typedef char * (__cdecl *FNDEF_DYN_gai_strerrorA)( int ecode ); +typedef int (__cdecl *FNDEF_DYN_WSAGetLastError)(void); +int DynamicWinsock2::WSAGetLastError() +{ + int out=0; + HINSTANCE Ws2_32 = LoadLibrary(TEXT("WS2_32.DLL")); + printf("ws2_32 dll: %08x\n", (int) Ws2_32); + if( Ws2_32 != NULL ) + { + FNDEF_DYN_WSAGetLastError fn = (FNDEF_DYN_WSAGetLastError) + GetProcAddress( Ws2_32, "WSAGetLastError" ); + printf("WSAGetLastError function pointer: %08x\n", (int)fn); + if( fn != NULL ) + out = (fn)(); + } + return out; +} + typedef char * (__cdecl *FNDEF_DYN_inet_ntoa)( struct in_addr ); void DynamicWinsock2::inet_ntoa( Bu::FString &out, struct in_addr addr_in ) { diff --git a/src/win32_compatibility.h b/src/win32_compatibility.h index 8bf3a00..72cb4f7 100644 --- a/src/win32_compatibility.h +++ b/src/win32_compatibility.h @@ -16,8 +16,14 @@ #ifdef WIN32 +#ifdef __cplusplus +extern "C" +{ #include #include +} +#endif + #include "fstring.h" #ifndef TEMP_FAILURE_RETRY @@ -33,6 +39,9 @@ __extension__ typedef int socklen_t; namespace DynamicWinsock2 { + int WSAStartup(WORD wVersionRequested,LPWSADATA lpWSAData); + int WSACleanup(void); + int WSAGetLastError(); void inet_ntoa( Bu::FString &out, struct in_addr addr_in ); unsigned long inet_addr( const char *s_in ); int select(int nfds, fd_set *readfds, fd_set *writefds, -- cgit v1.2.3