From 3ee5204eb254e914d695a37fede11c8599415fa9 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 14 Jan 2009 20:05:02 +0000 Subject: david - added getaddrinfo and freeaddrinfo --- src/win32_compatibility.cpp | 35 +++++++++++++++++++++++++++++++++++ src/win32_compatibility.h | 5 +++++ 2 files changed, 40 insertions(+) (limited to 'src') diff --git a/src/win32_compatibility.cpp b/src/win32_compatibility.cpp index 372dd6c..0ef3abc 100644 --- a/src/win32_compatibility.cpp +++ b/src/win32_compatibility.cpp @@ -53,15 +53,19 @@ int DynamicWinsock2::select(int nfds, fd_set *readfds, fd_set *writefds, typedef SOCKET (__cdecl *FNDEF_DYN_socket)(int,int,int); SOCKET DynamicWinsock2::socket(int domain, int type, int protocol) { + printf("in win32::socket\n"); SOCKET out = 0; HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); + printf("ws2_32 dll: %08x\n", (int) Ws2_32); if( Ws2_32 != NULL ) { FNDEF_DYN_socket fn = (FNDEF_DYN_socket) GetProcAddress( Ws2_32, "socket" ); + printf("socket function pointer: %08x\n", (int)fn); if( fn != NULL ) out = (fn)( domain, type, protocol ); } + printf("win32::socket complete.\n"); return out; } @@ -125,6 +129,37 @@ struct hostent *DynamicWinsock2::gethostbyname(const char *name) return out; } +typedef void (__cdecl *FNDEF_DYN_freeaddrinfo)(struct addrinfo *); +void DynamicWinsock2::freeaddrinfo(struct addrinfo *ai) +{ + HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); + if( Ws2_32 != NULL ) + { + FNDEF_DYN_freeaddrinfo fn = (FNDEF_DYN_freeaddrinfo) + GetProcAddress( Ws2_32, "freeaddrinfo" ); + if( fn != NULL ) + (fn)( ai ); + } +} + +typedef int (__cdecl *FNDEF_DYN_getaddrinfo)( + const char*,const char*,const struct addrinfo*,struct addrinfo**); +int DynamicWinsock2::getaddrinfo( + const char *nodename, const char *servname, + const struct addrinfo *hints, struct addrinfo **res ) +{ + int out = 0; + HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); + if( Ws2_32 != NULL ) + { + FNDEF_DYN_getaddrinfo fn = (FNDEF_DYN_getaddrinfo) + GetProcAddress( Ws2_32, "getaddrinfo" ); + if( fn != NULL ) + out = (fn)( nodename, servname, hints, res ); + } + return out; +} + typedef int (__cdecl *FNDEF_DYN_connect)(SOCKET,const struct sockaddr*,int); int DynamicWinsock2::connect( SOCKET s, const struct sockaddr *serv_addr, int addrlen) diff --git a/src/win32_compatibility.h b/src/win32_compatibility.h index 7d1f79b..8bf3a00 100644 --- a/src/win32_compatibility.h +++ b/src/win32_compatibility.h @@ -17,6 +17,7 @@ #ifdef WIN32 #include +#include #include "fstring.h" #ifndef TEMP_FAILURE_RETRY @@ -41,6 +42,10 @@ namespace DynamicWinsock2 u_short htons(u_short in); u_long htonl(u_long in); struct hostent *gethostbyname(const char *name); + void freeaddrinfo(struct addrinfo *ai); + int getaddrinfo( + const char *nodename, const char *servname, + const struct addrinfo *hints, struct addrinfo **res ); int connect(SOCKET s, const struct sockaddr *serv_addr, int addrlen); int getpeername(SOCKET s, struct sockaddr *name, int *namelen); int setsockopt(SOCKET s, int level, int optname, -- cgit v1.2.3