Commit 35e54fa5 authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

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

parent 8e29fcdd
......@@ -5894,24 +5894,29 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
protocol = lpProtocolInfo->iProtocol;
}
/* 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 (!type && (af || protocol))
{
if ((protocol == IPPROTO_TCP && type == SOCK_STREAM) ||
(protocol == IPPROTO_UDP && type == SOCK_DGRAM))
{
af = AF_INET;
}
else
WSAPROTOCOL_INFOW infow;
/* default to the first valid protocol */
if (!protocol)
protocol = valid_protocols[0];
if (WS_EnterSingleProtocolW(protocol, &infow))
{
SetLastError(WSAEPROTOTYPE);
return INVALID_SOCKET;
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);
SERVER_START_REQ( create_socket )
{
req->family = af;
......
......@@ -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);
......
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