ws2_32: Avoid using inet_ntoa() which isn't thread-safe.

This commit is contained in:
Huw Davies 2015-08-10 15:08:44 +01:00 committed by Alexandre Julliard
parent f5f025f1dd
commit 2569123d00
1 changed files with 20 additions and 11 deletions

View File

@ -283,9 +283,18 @@ static inline const char *debugstr_sockaddr( const struct WS_sockaddr *a )
switch (a->sa_family) switch (a->sa_family)
{ {
case WS_AF_INET: case WS_AF_INET:
{
char buf[16];
const char *p;
struct WS_sockaddr_in *sin = (struct WS_sockaddr_in *)a;
p = WS_inet_ntop( WS_AF_INET, &sin->sin_addr, buf, sizeof(buf) );
if (!p)
p = "(unknown IPv4 address)";
return wine_dbg_sprintf("{ family AF_INET, address %s, port %d }", return wine_dbg_sprintf("{ family AF_INET, address %s, port %d }",
inet_ntoa(((const struct sockaddr_in *)a)->sin_addr), p, ntohs(sin->sin_port));
ntohs(((const struct sockaddr_in *)a)->sin_port)); }
case WS_AF_INET6: case WS_AF_INET6:
{ {
char buf[46]; char buf[46];
@ -4004,15 +4013,15 @@ WS_u_short WINAPI WS_ntohs(WS_u_short netshort)
*/ */
char* WINAPI WS_inet_ntoa(struct WS_in_addr in) char* WINAPI WS_inet_ntoa(struct WS_in_addr in)
{ {
char* s = inet_ntoa(*((struct in_addr*)&in)); struct per_thread_data *data = get_per_thread_data();
if( s )
{ sprintf( data->ntoa_buffer, "%u.%u.%u.%u",
struct per_thread_data *data = get_per_thread_data(); (unsigned int)(ntohl( in.WS_s_addr ) >> 24 & 0xff),
strcpy(data->ntoa_buffer, s); (unsigned int)(ntohl( in.WS_s_addr ) >> 16 & 0xff),
return data->ntoa_buffer; (unsigned int)(ntohl( in.WS_s_addr ) >> 8 & 0xff),
} (unsigned int)(ntohl( in.WS_s_addr ) & 0xff) );
SetLastError(wsaErrno());
return NULL; return data->ntoa_buffer;
} }
static const char *debugstr_wsaioctl(DWORD ioctl) static const char *debugstr_wsaioctl(DWORD ioctl)