ws2_32: Auto detect the socket type and family based on the protocol.

This commit is contained in:
Bruno Jesus 2013-09-17 10:00:37 -03:00 committed by Alexandre Julliard
parent 8e29fcddb9
commit 35e54fa59b
2 changed files with 19 additions and 27 deletions

View File

@ -5894,24 +5894,29 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
protocol = lpProtocolInfo->iProtocol;
}
if (!type && (af || protocol))
{
WSAPROTOCOL_INFOW infow;
/* default to the first valid protocol */
if (!protocol)
protocol = valid_protocols[0];
if (WS_EnterSingleProtocolW(protocol, &infow))
{
type = infow.iSocketType;
/* after win2003 it's no longer possible to pass AF_UNSPEC
using the protocol info struct */
if (!lpProtocolInfo && af == WS_AF_UNSPEC)
af = infow.iAddressFamily;
}
}
/* convert the socket family and type */
af = convert_af_w2u(af);
type = convert_socktype_w2u(type);
if ( af == AF_UNSPEC) /* did they not specify the address family? */
{
if ((protocol == IPPROTO_TCP && type == SOCK_STREAM) ||
(protocol == IPPROTO_UDP && type == SOCK_DGRAM))
{
af = AF_INET;
}
else
{
SetLastError(WSAEPROTOTYPE);
return INVALID_SOCKET;
}
}
SERVER_START_REQ( create_socket )
{
req->family = af;

View File

@ -1788,7 +1788,6 @@ todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
closesocket(sock);
@ -1800,14 +1799,12 @@ todo_wine
ok(WSASocketA(0, SOCK_STREAM, -1, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
SetLastError(0xdeadbeef);
ok(WSASocketA(0, -1, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
SetLastError(0xdeadbeef);
@ -1821,7 +1818,6 @@ todo_wine
ok(WSASocketA(0, -1, -1, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
SetLastError(0xdeadbeef);
@ -1832,7 +1828,6 @@ todo_wine
ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
sock = WSASocketA(AF_INET, 0, IPPROTO_TCP, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
closesocket(sock);
@ -1864,7 +1859,6 @@ todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
closesocket(sock);
@ -1992,20 +1986,17 @@ todo_wine
* from WSAEnumProtocols that has the flag PFL_MATCHES_PROTOCOL_ZERO
* is returned */
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n",
WSAGetLastError());
size = sizeof(socktype);
socktype = 0xdead;
err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size);
todo_wine
ok(!err, "getsockopt failed with %d\n", WSAGetLastError());
for(i = 0; i < items; i++)
{
if(pi[i].dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO)
{
todo_wine
ok(socktype == pi[i].iSocketType, "Wrong socket type, expected %d received %d\n",
pi[i].iSocketType, socktype);
break;
@ -2019,14 +2010,12 @@ todo_wine
for (i = 0; i < sizeof(autoprotocols) / sizeof(autoprotocols[0]); i++)
{
sock = WSASocketA(0, 0, autoprotocols[i], NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "Failed to create socket for protocol %d, received %d\n",
autoprotocols[i], WSAGetLastError());
size = sizeof(socktype);
socktype = 0xdead;
err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size);
todo_wine
ok(!err, "getsockopt failed with %d\n", WSAGetLastError());
for (err = 1, j = 0; j < items; j++)
@ -2036,13 +2025,11 @@ todo_wine
if (socktype == pi[j].iSocketType)
err = 0;
else
todo_wine
ok(0, "Wrong socket type, expected %d received %d\n",
pi[j].iSocketType, socktype);
break;
}
}
todo_wine
ok(!err, "Protocol %d not found in WSAEnumProtocols\n", autoprotocols[i]);
closesocket(sock);