Commit 183fc7bd authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- Fix thread safety problem in [18812]

- Fix illegal error return value for getnaminfo from [18812]
- Do not crash if the APIs are not available (*NULL) from [18812]

Should fix most Win32 resolution crashes
(if not already done in previous commits)
parent 45d6d772
...@@ -476,75 +476,57 @@ static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos ); ...@@ -476,75 +476,57 @@ static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos );
static GETNAMEINFO ws2_getnameinfo = _ws2_getnameinfo_bind; static GETNAMEINFO ws2_getnameinfo = _ws2_getnameinfo_bind;
static GETADDRINFO ws2_getaddrinfo = _ws2_getaddrinfo_bind; static GETADDRINFO ws2_getaddrinfo = _ws2_getaddrinfo_bind;
static FREEADDRINFO ws2_freeaddrinfo = _ws2_freeaddrinfo_bind; static FREEADDRINFO ws2_freeaddrinfo;
static int _ws2_find_ipv6_api(void) static FARPROC ws2_find_api (const char *name)
{ {
/* For Windows XP and above, IPv6 stack is in WS2_32.DLL */ FARPROC f = NULL;
HINSTANCE module = LoadLibrary( "ws2_32.dll" );
if( module != NULL )
{
ws2_getnameinfo = (GETNAMEINFO)GetProcAddress( module, "getnameinfo" );
ws2_getaddrinfo = (GETADDRINFO)GetProcAddress( module, "getaddrinfo" );
ws2_freeaddrinfo = (FREEADDRINFO)GetProcAddress( module, "freeaddrinfo" );
if( ws2_getnameinfo && ws2_getaddrinfo && ws2_freeaddrinfo )
{
/* got them */
return 1;
}
FreeLibrary( module );
/* For Windows 2000 and below, try IPv6 stack in in WSHIP6.DLL */ HMODULE m = GetModuleHandle ("WS2_32");
module = LoadLibrary( "wship6.dll" ); if (m != NULL)
if( module != NULL ) f = GetProcAddress (m, name);
{
ws2_getnameinfo = (GETNAMEINFO)GetProcAddress( module, "getnameinfo" ); if (f == NULL)
ws2_getaddrinfo = (GETADDRINFO)GetProcAddress( module, "getaddrinfo" ); {
ws2_freeaddrinfo = (FREEADDRINFO)GetProcAddress( module, "freeaddrinfo" ); /* Windows 2K IPv6 preview */
if( ws2_getnameinfo && ws2_getaddrinfo && ws2_freeaddrinfo ) m = LoadLibrary ("WSHIP6");
{ if (m != NULL)
/* got them */ f = GetProcAddress (m, name);
return 1;
}
FreeLibrary( module );
}
} }
/* no API */
return 0; return f;
} }
static WINAPI int _ws2_getnameinfo_bind( const struct sockaddr *sa, socklen_t salen, static WINAPI int _ws2_getnameinfo_bind( const struct sockaddr *sa, socklen_t salen,
char *host, DWORD hostlen, char *serv, DWORD servlen, int flags ) char *host, DWORD hostlen, char *serv, DWORD servlen, int flags )
{ {
if( _ws2_find_ipv6_api() ) GETNAMEINFO entry = (GETNAMEINFO)ws2_find_api ("getnameinfo");
if (entry != NULL)
{ {
return ws2_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags); ws2_getnameinfo = entry;
return entry (sa, salen, host, hostlen, serv, servlen, flags);
} }
/* return a possible error if API is not found */ /* return a possible error if API is not found */
WSASetLastError(WSAHOST_NOT_FOUND); WSASetLastError (WSAEAFNOSUPPORT);
return WSAHOST_NOT_FOUND; return EAI_FAMILY;
} }
static WINAPI int _ws2_getaddrinfo_bind(const char *node, const char *service, static WINAPI int _ws2_getaddrinfo_bind(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res) const struct addrinfo *hints, struct addrinfo **res)
{ {
if( _ws2_find_ipv6_api() ) GETADDRINFO entry = (GETADDRINFO)ws2_find_api ("getaddrinfo");
{ FREEADDRINFO freentry = (FREEADDRINFO)ws2_find_api ("freeaddrinfo");
return ws2_getaddrinfo(node, service, hints, res);
}
/* return a possible error if API is not found */
WSASetLastError(WSAHOST_NOT_FOUND);
return WSAHOST_NOT_FOUND;
}
static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos ) if ((entry != NULL) && (freentry != NULL))
{
if( _ws2_find_ipv6_api() )
{ {
ws2_freeaddrinfo(infos); ws2_freeaddrinfo = freentry;
ws2_getaddrinfo = entry;
return entry (node, service, hints, res);
} }
/* return a possible error if API is not found */
WSASetLastError (WSAHOST_NOT_FOUND);
return EAI_NONAME;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment