Commit 2fa64f52 authored by Jeff Latimer's avatar Jeff Latimer Committed by Alexandre Julliard

ws2_32: IPv6 functionality for WSAAddressToStringA.

parent 7d78bf4b
...@@ -4922,7 +4922,7 @@ INT WINAPI WSAAddressToStringA( LPSOCKADDR sockaddr, DWORD len, ...@@ -4922,7 +4922,7 @@ INT WINAPI WSAAddressToStringA( LPSOCKADDR sockaddr, DWORD len,
LPDWORD lenstr ) LPDWORD lenstr )
{ {
DWORD size; DWORD size;
CHAR buffer[22]; /* 12 digits + 3 dots + ':' + 5 digits + '\0' */ CHAR buffer[54]; /* 32 digits + 7':' + '[' + '%" + 5 digits + ']:' + 5 digits + '\0' */
CHAR *p; CHAR *p;
TRACE( "(%p, %d, %p, %p, %p)\n", sockaddr, len, info, string, lenstr ); TRACE( "(%p, %d, %p, %p, %p)\n", sockaddr, len, info, string, lenstr );
...@@ -4931,17 +4931,36 @@ INT WINAPI WSAAddressToStringA( LPSOCKADDR sockaddr, DWORD len, ...@@ -4931,17 +4931,36 @@ INT WINAPI WSAAddressToStringA( LPSOCKADDR sockaddr, DWORD len,
if (!string || !lenstr) return SOCKET_ERROR; if (!string || !lenstr) return SOCKET_ERROR;
/* sin_family is guaranteed to be the first u_short */ /* sin_family is guaranteed to be the first u_short */
if (((SOCKADDR_IN *)sockaddr)->sin_family != AF_INET) return SOCKET_ERROR; switch(((SOCKADDR_IN *)sockaddr)->sin_family)
{
case WS_AF_INET:
sprintf( buffer, "%u.%u.%u.%u:%u",
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) >> 24 & 0xff),
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) >> 16 & 0xff),
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) >> 8 & 0xff),
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) & 0xff),
ntohs( ((SOCKADDR_IN *)sockaddr)->sin_port ) );
p = strchr( buffer, ':' );
if (!((SOCKADDR_IN *)sockaddr)->sin_port) *p = 0;
break;
sprintf( buffer, "%u.%u.%u.%u:%u", case WS_AF_INET6:
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) >> 24 & 0xff), {
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) >> 16 & 0xff), struct WS_sockaddr_in6 *sockaddr6 = (LPSOCKADDR_IN6) sockaddr;
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) >> 8 & 0xff),
(unsigned int)(ntohl( ((SOCKADDR_IN *)sockaddr)->sin_addr.WS_s_addr ) & 0xff),
ntohs( ((SOCKADDR_IN *)sockaddr)->sin_port ) );
p = strchr( buffer, ':' ); if (!WS_inet_ntop(WS_AF_INET6, &sockaddr6->sin6_addr, buffer, sizeof(buffer)))
if (!((SOCKADDR_IN *)sockaddr)->sin_port) *p = 0; {
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
break;
}
default:
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
size = strlen( buffer ) + 1; size = strlen( buffer ) + 1;
......
...@@ -1371,12 +1371,9 @@ static void test_WSAAddressToStringA(void) ...@@ -1371,12 +1371,9 @@ static void test_WSAAddressToStringA(void)
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_1, sizeof(addr6_1)); memcpy (sockaddr6.sin6_addr.s6_addr, addr6_1, sizeof(addr6_1));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len ); ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() ); ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_1 ), "Expected: %s, got: %s\n", expect6_1, address6 ); ok( !strcmp( address6, expect6_1 ), "Expected: %s, got: %s\n", expect6_1, address6 );
ok( len == sizeof(expect6_1), "Got size %d\n", len); ok( len == sizeof(expect6_1), "Got size %d\n", len);
}
/* Test a longer IPv6 address */ /* Test a longer IPv6 address */
len = sizeof(address6); len = sizeof(address6);
...@@ -1387,12 +1384,9 @@ static void test_WSAAddressToStringA(void) ...@@ -1387,12 +1384,9 @@ static void test_WSAAddressToStringA(void)
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_2, sizeof(addr6_2)); memcpy (sockaddr6.sin6_addr.s6_addr, addr6_2, sizeof(addr6_2));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len ); ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
todo_wine
{
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() ); ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_2 ), "Expected: %s, got: %s\n", expect6_2, address6 ); ok( !strcmp( address6, expect6_2 ), "Expected: %s, got: %s\n", expect6_2, address6 );
ok( len == sizeof(expect6_2), "Got size %d\n", len); ok( len == sizeof(expect6_2), "Got size %d\n", len);
}
/* Test IPv6 address and port number */ /* Test IPv6 address and port number */
len = sizeof(address6); len = sizeof(address6);
...@@ -1403,9 +1397,9 @@ static void test_WSAAddressToStringA(void) ...@@ -1403,9 +1397,9 @@ static void test_WSAAddressToStringA(void)
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3)); memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len ); ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
todo_wine todo_wine
{ {
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_3 ), "Expected: %s, got: %s\n", expect6_3, address6 ); ok( !strcmp( address6, expect6_3 ), "Expected: %s, got: %s\n", expect6_3, address6 );
ok( len == sizeof(expect6_3), "Got size %d\n", len); ok( len == sizeof(expect6_3), "Got size %d\n", len);
} }
...@@ -1419,9 +1413,9 @@ static void test_WSAAddressToStringA(void) ...@@ -1419,9 +1413,9 @@ static void test_WSAAddressToStringA(void)
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3)); memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len ); ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
todo_wine todo_wine
{ {
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_3_2 ), "Expected: %s, got: %s\n", expect6_3_2, address6 ); ok( !strcmp( address6, expect6_3_2 ), "Expected: %s, got: %s\n", expect6_3_2, address6 );
ok( len == sizeof(expect6_3_2), "Got size %d\n", len); ok( len == sizeof(expect6_3_2), "Got size %d\n", len);
} }
...@@ -1435,9 +1429,9 @@ static void test_WSAAddressToStringA(void) ...@@ -1435,9 +1429,9 @@ static void test_WSAAddressToStringA(void)
memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3)); memcpy (sockaddr6.sin6_addr.s6_addr, addr6_3, sizeof(addr6_3));
ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len ); ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr6, sizeof(sockaddr6), NULL, address6, &len );
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
todo_wine todo_wine
{ {
ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
ok( !strcmp( address6, expect6_3_3 ), "Expected: %s, got: %s\n", expect6_3_3, address6 ); ok( !strcmp( address6, expect6_3_3 ), "Expected: %s, got: %s\n", expect6_3_3, address6 );
ok( len == sizeof(expect6_3_3), "Got size %d\n", len); ok( len == sizeof(expect6_3_3), "Got size %d\n", len);
} }
......
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