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, ...@@ -5894,24 +5894,29 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
protocol = lpProtocolInfo->iProtocol; protocol = lpProtocolInfo->iProtocol;
} }
/* convert the socket family and type */ if (!type && (af || protocol))
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) || WSAPROTOCOL_INFOW infow;
(protocol == IPPROTO_UDP && type == SOCK_DGRAM))
{ /* default to the first valid protocol */
af = AF_INET; if (!protocol)
} protocol = valid_protocols[0];
else
if (WS_EnterSingleProtocolW(protocol, &infow))
{ {
SetLastError(WSAEPROTOTYPE); type = infow.iSocketType;
return INVALID_SOCKET;
/* 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 ) SERVER_START_REQ( create_socket )
{ {
req->family = af; req->family = af;
......
...@@ -1788,7 +1788,6 @@ todo_wine ...@@ -1788,7 +1788,6 @@ todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err); ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0); sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n"); ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
closesocket(sock); closesocket(sock);
...@@ -1800,14 +1799,12 @@ todo_wine ...@@ -1800,14 +1799,12 @@ todo_wine
ok(WSASocketA(0, SOCK_STREAM, -1, NULL, 0, 0) == INVALID_SOCKET, ok(WSASocketA(0, SOCK_STREAM, -1, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n"); "WSASocketA should have failed\n");
err = WSAGetLastError(); err = WSAGetLastError();
todo_wine
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err); ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ok(WSASocketA(0, -1, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET, ok(WSASocketA(0, -1, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n"); "WSASocketA should have failed\n");
err = WSAGetLastError(); err = WSAGetLastError();
todo_wine
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err); ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
...@@ -1821,7 +1818,6 @@ todo_wine ...@@ -1821,7 +1818,6 @@ todo_wine
ok(WSASocketA(0, -1, -1, NULL, 0, 0) == INVALID_SOCKET, ok(WSASocketA(0, -1, -1, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n"); "WSASocketA should have failed\n");
err = WSAGetLastError(); err = WSAGetLastError();
todo_wine
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err); ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
...@@ -1832,7 +1828,6 @@ todo_wine ...@@ -1832,7 +1828,6 @@ todo_wine
ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err); ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
sock = WSASocketA(AF_INET, 0, IPPROTO_TCP, NULL, 0, 0); sock = WSASocketA(AF_INET, 0, IPPROTO_TCP, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n"); ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
closesocket(sock); closesocket(sock);
...@@ -1864,7 +1859,6 @@ todo_wine ...@@ -1864,7 +1859,6 @@ todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err); ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0); sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n"); ok(sock != INVALID_SOCKET, "WSASocketA should have succeeded\n");
closesocket(sock); closesocket(sock);
...@@ -1992,20 +1986,17 @@ todo_wine ...@@ -1992,20 +1986,17 @@ todo_wine
* from WSAEnumProtocols that has the flag PFL_MATCHES_PROTOCOL_ZERO * from WSAEnumProtocols that has the flag PFL_MATCHES_PROTOCOL_ZERO
* is returned */ * is returned */
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0); sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
todo_wine
ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n", ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n",
WSAGetLastError()); WSAGetLastError());
size = sizeof(socktype); size = sizeof(socktype);
socktype = 0xdead; socktype = 0xdead;
err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size); err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size);
todo_wine
ok(!err, "getsockopt failed with %d\n", WSAGetLastError()); ok(!err, "getsockopt failed with %d\n", WSAGetLastError());
for(i = 0; i < items; i++) for(i = 0; i < items; i++)
{ {
if(pi[i].dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO) if(pi[i].dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO)
{ {
todo_wine
ok(socktype == pi[i].iSocketType, "Wrong socket type, expected %d received %d\n", ok(socktype == pi[i].iSocketType, "Wrong socket type, expected %d received %d\n",
pi[i].iSocketType, socktype); pi[i].iSocketType, socktype);
break; break;
...@@ -2019,14 +2010,12 @@ todo_wine ...@@ -2019,14 +2010,12 @@ todo_wine
for (i = 0; i < sizeof(autoprotocols) / sizeof(autoprotocols[0]); i++) for (i = 0; i < sizeof(autoprotocols) / sizeof(autoprotocols[0]); i++)
{ {
sock = WSASocketA(0, 0, autoprotocols[i], NULL, 0, 0); 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", ok(sock != INVALID_SOCKET, "Failed to create socket for protocol %d, received %d\n",
autoprotocols[i], WSAGetLastError()); autoprotocols[i], WSAGetLastError());
size = sizeof(socktype); size = sizeof(socktype);
socktype = 0xdead; socktype = 0xdead;
err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size); err = getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *) &socktype, &size);
todo_wine
ok(!err, "getsockopt failed with %d\n", WSAGetLastError()); ok(!err, "getsockopt failed with %d\n", WSAGetLastError());
for (err = 1, j = 0; j < items; j++) for (err = 1, j = 0; j < items; j++)
...@@ -2036,13 +2025,11 @@ todo_wine ...@@ -2036,13 +2025,11 @@ todo_wine
if (socktype == pi[j].iSocketType) if (socktype == pi[j].iSocketType)
err = 0; err = 0;
else else
todo_wine
ok(0, "Wrong socket type, expected %d received %d\n", ok(0, "Wrong socket type, expected %d received %d\n",
pi[j].iSocketType, socktype); pi[j].iSocketType, socktype);
break; break;
} }
} }
todo_wine
ok(!err, "Protocol %d not found in WSAEnumProtocols\n", autoprotocols[i]); ok(!err, "Protocol %d not found in WSAEnumProtocols\n", autoprotocols[i]);
closesocket(sock); 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