Hans Leidekker : wininet: Use getaddrinfo for thread-safe resolving if available.
Alexandre Julliard
julliard at winehq.org
Mon Aug 4 08:53:33 CDT 2008
Module: wine
Branch: master
Commit: daa2fdfccb29f5a17b7c900d5f01cc2c05c92817
URL: http://source.winehq.org/git/wine.git/?a=commit;h=daa2fdfccb29f5a17b7c900d5f01cc2c05c92817
Author: Hans Leidekker <hans at meelstraat.net>
Date: Sat Aug 2 23:21:23 2008 +0200
wininet: Use getaddrinfo for thread-safe resolving if available.
---
dlls/wininet/utility.c | 33 ++++++++++++++++++++++++++++++---
1 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/dlls/wininet/utility.c b/dlls/wininet/utility.c
index b0d9c9c..ff914f4 100644
--- a/dlls/wininet/utility.c
+++ b/dlls/wininet/utility.c
@@ -40,6 +40,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
+#ifndef HAVE_GETADDRINFO
+
/* critical section to protect non-reentrant gethostbyname() */
static CRITICAL_SECTION cs_gethostbyname;
static CRITICAL_SECTION_DEBUG critsect_debug =
@@ -50,6 +52,8 @@ static CRITICAL_SECTION_DEBUG critsect_debug =
};
static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 };
+#endif
+
#define TIME_STRING_LEN 30
time_t ConvertTimeString(LPCWSTR asctime)
@@ -142,7 +146,12 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
WCHAR *found;
char *name;
int len, sz;
+#ifdef HAVE_GETADDRINFO
+ struct addrinfo *res, hints;
+ int ret;
+#else
struct hostent *phe;
+#endif
TRACE("%s\n", debugstr_w(lpszServerName));
@@ -158,27 +167,45 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
len = strlenW(lpszServerName);
sz = WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, NULL, 0, NULL, NULL );
- name = HeapAlloc(GetProcessHeap(), 0, sz+1);
+ if (!(name = HeapAlloc( GetProcessHeap(), 0, sz + 1 ))) return FALSE;
WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL );
name[sz] = 0;
+#ifdef HAVE_GETADDRINFO
+ memset( &hints, 0, sizeof(struct addrinfo) );
+ hints.ai_family = AF_INET;
+
+ ret = getaddrinfo( name, NULL, &hints, &res );
+ HeapFree( GetProcessHeap(), 0, name );
+ if (ret != 0)
+ {
+ TRACE("failed to get address of %s (%s)\n", debugstr_w(lpszServerName), gai_strerror(ret));
+ return FALSE;
+ }
+ memset( psa, 0, sizeof(struct sockaddr_in) );
+ memcpy( &psa->sin_addr, &((struct sockaddr_in *)res->ai_addr)->sin_addr, sizeof(struct in_addr) );
+ psa->sin_family = res->ai_family;
+ psa->sin_port = htons(nServerPort);
+
+ freeaddrinfo( res );
+#else
EnterCriticalSection( &cs_gethostbyname );
phe = gethostbyname(name);
HeapFree( GetProcessHeap(), 0, name );
if (NULL == phe)
{
- TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
+ TRACE("failed to get address of %s (%d)\n", debugstr_w(lpszServerName), h_errno);
LeaveCriticalSection( &cs_gethostbyname );
return FALSE;
}
-
memset(psa,0,sizeof(struct sockaddr_in));
memcpy((char *)&psa->sin_addr, phe->h_addr, phe->h_length);
psa->sin_family = phe->h_addrtype;
psa->sin_port = htons(nServerPort);
LeaveCriticalSection( &cs_gethostbyname );
+#endif
return TRUE;
}
More information about the wine-cvs
mailing list