ws2_32: Fix WSAStringToAddress parsing for IPv6.

Signed-off-by: Bruno Jesus <bjesus@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Bruno Jesus 2017-03-02 22:21:44 -03:00 committed by Alexandre Julliard
parent 49a2d1b802
commit b60cd68308
2 changed files with 18 additions and 22 deletions

View File

@ -8255,10 +8255,6 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
((LPSOCKADDR_IN)lpAddress)->sin_port = htons(atoi(ptrPort+1));
*ptrPort = '\0';
}
else
{
((LPSOCKADDR_IN)lpAddress)->sin_port = 0;
}
if(inet_aton(workBuffer, &inetaddr) > 0)
{
@ -8269,11 +8265,12 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
res = WSAEINVAL;
break;
}
case WS_AF_INET6:
{
struct in6_addr inetaddr;
char *ptrAddr = workBuffer;
/* If lpAddressLength is too small, tell caller the size we need */
if (*lpAddressLength < sizeof(SOCKADDR_IN6))
{
@ -8287,24 +8284,27 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
((LPSOCKADDR_IN6)lpAddress)->sin6_family = WS_AF_INET6;
/* This one is a bit tricky. An IPv6 address contains colons, so the
* check from IPv4 doesn't work like that. However, IPv6 addresses that
* contain a port are written with braces like [fd12:3456:7890::1]:12345
* so what we will do is to look for ']', check if the next char is a
* colon, and if it is, parse the port as in IPv4. */
/* Valid IPv6 addresses can also be surrounded by [ ], and in this case
* a port number may follow after like in [fd12:3456:7890::1]:12345
* We need to cut the brackets and find the port if any. */
ptrPort = strchr(workBuffer, ']');
if(ptrPort && *(++ptrPort) == ':')
if(*workBuffer == '[')
{
((LPSOCKADDR_IN6)lpAddress)->sin6_port = htons(atoi(ptrPort+1));
ptrPort = strchr(workBuffer, ']');
if (!ptrPort)
{
SetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
if (ptrPort[1] == ':')
((LPSOCKADDR_IN6)lpAddress)->sin6_port = htons(atoi(ptrPort + 2));
*ptrPort = '\0';
}
else
{
((LPSOCKADDR_IN6)lpAddress)->sin6_port = 0;
ptrAddr = workBuffer + 1;
}
if(inet_pton(AF_INET6, workBuffer, &inetaddr) > 0)
if(inet_pton(AF_INET6, ptrAddr, &inetaddr) > 0)
{
memcpy(&((LPSOCKADDR_IN6)lpAddress)->sin6_addr, &inetaddr,
sizeof(struct in6_addr));

View File

@ -3426,7 +3426,6 @@ static void test_WSAStringToAddressA(void)
ret = WSAStringToAddressA( address7, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
&len );
GLE = WSAGetLastError();
todo_wine
ok( ret == 0, "WSAStringToAddressA() failed for IPv6 address: %d\n", GLE);
len = sizeof(sockaddr6);
@ -3436,7 +3435,6 @@ todo_wine
ret = WSAStringToAddressA( address8, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
&len );
GLE = WSAGetLastError();
todo_wine
ok( ret == 0 && sockaddr6.sin6_port == 0xffff,
"WSAStringToAddressA() failed for IPv6 address: %d\n", GLE);
@ -3568,7 +3566,6 @@ static void test_WSAStringToAddressW(void)
ret = WSAStringToAddressW( address7, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
&len );
GLE = WSAGetLastError();
todo_wine
ok( ret == 0, "WSAStringToAddressW() failed for IPv6 address: %d\n", GLE);
len = sizeof(sockaddr6);
@ -3578,7 +3575,6 @@ todo_wine
ret = WSAStringToAddressW( address8, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
&len );
GLE = WSAGetLastError();
todo_wine
ok( ret == 0 && sockaddr6.sin6_port == 0xffff,
"WSAStringToAddressW() failed for IPv6 address: %d\n", GLE);