aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <david@xagasoft.com>2009-01-14 20:05:02 +0000
committerDavid <david@xagasoft.com>2009-01-14 20:05:02 +0000
commit3ee5204eb254e914d695a37fede11c8599415fa9 (patch)
tree26b92fba438d16a0d2e896f92f106125e04abf94
parente771f7c48d38d1c1481b9904d17ed7989d6cd579 (diff)
downloadlibbu++-3ee5204eb254e914d695a37fede11c8599415fa9.tar.gz
libbu++-3ee5204eb254e914d695a37fede11c8599415fa9.tar.bz2
libbu++-3ee5204eb254e914d695a37fede11c8599415fa9.tar.xz
libbu++-3ee5204eb254e914d695a37fede11c8599415fa9.zip
david - added getaddrinfo and freeaddrinfo
Diffstat (limited to '')
-rw-r--r--src/win32_compatibility.cpp35
-rw-r--r--src/win32_compatibility.h5
2 files changed, 40 insertions, 0 deletions
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,
53typedef SOCKET (__cdecl *FNDEF_DYN_socket)(int,int,int); 53typedef SOCKET (__cdecl *FNDEF_DYN_socket)(int,int,int);
54SOCKET DynamicWinsock2::socket(int domain, int type, int protocol) 54SOCKET DynamicWinsock2::socket(int domain, int type, int protocol)
55{ 55{
56 printf("in win32::socket\n");
56 SOCKET out = 0; 57 SOCKET out = 0;
57 HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32")); 58 HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32"));
59 printf("ws2_32 dll: %08x\n", (int) Ws2_32);
58 if( Ws2_32 != NULL ) 60 if( Ws2_32 != NULL )
59 { 61 {
60 FNDEF_DYN_socket fn = (FNDEF_DYN_socket) 62 FNDEF_DYN_socket fn = (FNDEF_DYN_socket)
61 GetProcAddress( Ws2_32, "socket" ); 63 GetProcAddress( Ws2_32, "socket" );
64 printf("socket function pointer: %08x\n", (int)fn);
62 if( fn != NULL ) 65 if( fn != NULL )
63 out = (fn)( domain, type, protocol ); 66 out = (fn)( domain, type, protocol );
64 } 67 }
68 printf("win32::socket complete.\n");
65 return out; 69 return out;
66} 70}
67 71
@@ -125,6 +129,37 @@ struct hostent *DynamicWinsock2::gethostbyname(const char *name)
125 return out; 129 return out;
126} 130}
127 131
132typedef void (__cdecl *FNDEF_DYN_freeaddrinfo)(struct addrinfo *);
133void DynamicWinsock2::freeaddrinfo(struct addrinfo *ai)
134{
135 HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32"));
136 if( Ws2_32 != NULL )
137 {
138 FNDEF_DYN_freeaddrinfo fn = (FNDEF_DYN_freeaddrinfo)
139 GetProcAddress( Ws2_32, "freeaddrinfo" );
140 if( fn != NULL )
141 (fn)( ai );
142 }
143}
144
145typedef int (__cdecl *FNDEF_DYN_getaddrinfo)(
146 const char*,const char*,const struct addrinfo*,struct addrinfo**);
147int DynamicWinsock2::getaddrinfo(
148 const char *nodename, const char *servname,
149 const struct addrinfo *hints, struct addrinfo **res )
150{
151 int out = 0;
152 HINSTANCE Ws2_32 = LoadLibrary(TEXT("Ws2_32"));
153 if( Ws2_32 != NULL )
154 {
155 FNDEF_DYN_getaddrinfo fn = (FNDEF_DYN_getaddrinfo)
156 GetProcAddress( Ws2_32, "getaddrinfo" );
157 if( fn != NULL )
158 out = (fn)( nodename, servname, hints, res );
159 }
160 return out;
161}
162
128typedef int (__cdecl *FNDEF_DYN_connect)(SOCKET,const struct sockaddr*,int); 163typedef int (__cdecl *FNDEF_DYN_connect)(SOCKET,const struct sockaddr*,int);
129int DynamicWinsock2::connect( 164int DynamicWinsock2::connect(
130 SOCKET s, const struct sockaddr *serv_addr, int addrlen) 165 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 @@
17#ifdef WIN32 17#ifdef WIN32
18 18
19#include <Winsock2.h> 19#include <Winsock2.h>
20#include <ws2tcpip.h>
20#include "fstring.h" 21#include "fstring.h"
21 22
22#ifndef TEMP_FAILURE_RETRY 23#ifndef TEMP_FAILURE_RETRY
@@ -41,6 +42,10 @@ namespace DynamicWinsock2
41 u_short htons(u_short in); 42 u_short htons(u_short in);
42 u_long htonl(u_long in); 43 u_long htonl(u_long in);
43 struct hostent *gethostbyname(const char *name); 44 struct hostent *gethostbyname(const char *name);
45 void freeaddrinfo(struct addrinfo *ai);
46 int getaddrinfo(
47 const char *nodename, const char *servname,
48 const struct addrinfo *hints, struct addrinfo **res );
44 int connect(SOCKET s, const struct sockaddr *serv_addr, int addrlen); 49 int connect(SOCKET s, const struct sockaddr *serv_addr, int addrlen);
45 int getpeername(SOCKET s, struct sockaddr *name, int *namelen); 50 int getpeername(SOCKET s, struct sockaddr *name, int *namelen);
46 int setsockopt(SOCKET s, int level, int optname, 51 int setsockopt(SOCKET s, int level, int optname,