Commit cabb350f authored by Kai Blin's avatar Kai Blin Committed by Alexandre Julliard

ws2_32: Add support for FROM_PROTOCOL_INFO to WSASocket().

parent 3978df4e
...@@ -297,6 +297,7 @@ static const int ws_af_map[][2] = ...@@ -297,6 +297,7 @@ static const int ws_af_map[][2] =
#ifdef HAVE_IPX #ifdef HAVE_IPX
MAP_OPTION( AF_IPX ), MAP_OPTION( AF_IPX ),
#endif #endif
{FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO},
}; };
static const int ws_socktype_map[][2] = static const int ws_socktype_map[][2] =
...@@ -304,6 +305,7 @@ static const int ws_socktype_map[][2] = ...@@ -304,6 +305,7 @@ static const int ws_socktype_map[][2] =
MAP_OPTION( SOCK_DGRAM ), MAP_OPTION( SOCK_DGRAM ),
MAP_OPTION( SOCK_STREAM ), MAP_OPTION( SOCK_STREAM ),
MAP_OPTION( SOCK_RAW ), MAP_OPTION( SOCK_RAW ),
{FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO},
}; };
static const int ws_proto_map[][2] = static const int ws_proto_map[][2] =
...@@ -314,6 +316,7 @@ static const int ws_proto_map[][2] = ...@@ -314,6 +316,7 @@ static const int ws_proto_map[][2] =
MAP_OPTION( IPPROTO_ICMP ), MAP_OPTION( IPPROTO_ICMP ),
MAP_OPTION( IPPROTO_IGMP ), MAP_OPTION( IPPROTO_IGMP ),
MAP_OPTION( IPPROTO_RAW ), MAP_OPTION( IPPROTO_RAW ),
{FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO},
}; };
static const int ws_aiflag_map[][2] = static const int ws_aiflag_map[][2] =
...@@ -3781,28 +3784,18 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol, ...@@ -3781,28 +3784,18 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
return ret; return ret;
} }
/* check and convert the socket family */ /* convert the socket family and type */
af = convert_af_w2u(af); af = convert_af_w2u(af);
if (af == -1)
{
FIXME("Unsupported socket family %d!\n", af);
SetLastError(WSAEAFNOSUPPORT);
return INVALID_SOCKET;
}
/* check the socket type */
type = convert_socktype_w2u(type); type = convert_socktype_w2u(type);
if (type == -1)
{
SetLastError(WSAESOCKTNOSUPPORT);
return INVALID_SOCKET;
}
/* check the protocol type */ if (lpProtocolInfo)
if ( protocol < 0 ) /* don't support negative values */
{ {
SetLastError(WSAEPROTONOSUPPORT); if (af == FROM_PROTOCOL_INFO)
return INVALID_SOCKET; af = lpProtocolInfo->iAddressFamily;
if (type == FROM_PROTOCOL_INFO)
type = lpProtocolInfo->iSocketType;
if (protocol == FROM_PROTOCOL_INFO)
protocol = lpProtocolInfo->iProtocol;
} }
if ( af == AF_UNSPEC) /* did they not specify the address family? */ if ( af == AF_UNSPEC) /* did they not specify the address family? */
......
...@@ -1115,6 +1115,47 @@ static void test_getservbyname(void) ...@@ -1115,6 +1115,47 @@ static void test_getservbyname(void)
} }
} }
static void test_WSASocket(void)
{
SOCKET sock = INVALID_SOCKET;
WSAPROTOCOL_INFOA *pi;
int providers[] = {6, 0};
int ret, err;
UINT pi_size;
ret = WSAEnumProtocolsA(providers, NULL, &pi_size);
ok(ret == SOCKET_ERROR, "WSAEnumProtocolsA({6,0}, NULL, 0) returned %d\n",
ret);
err = WSAGetLastError();
ok(err == WSAENOBUFS, "WSAEnumProtocolsA error is %d, not WSAENOBUFS(%d)\n",
err, WSAENOBUFS);
pi = HeapAlloc(GetProcessHeap(), 0, pi_size);
ok(pi != NULL, "Failed to allocate memory\n");
if (pi == NULL) {
skip("Can't continue without memory.\n");
return;
}
ret = WSAEnumProtocolsA(providers, pi, &pi_size);
ok(ret != SOCKET_ERROR, "WSAEnumProtocolsA failed, last error is %d\n",
WSAGetLastError());
if (ret == 0) {
skip("No protocols enumerated.\n");
HeapFree(GetProcessHeap(), 0, pi);
return;
}
sock = WSASocketA(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO, &pi[0], 0, 0);
ok(sock != INVALID_SOCKET, "Failed to create socket: %d\n",
WSAGetLastError());
closesocket(sock);
HeapFree(GetProcessHeap(), 0, pi);
}
static void test_WSAAddressToStringA(void) static void test_WSAAddressToStringA(void)
{ {
INT ret; INT ret;
...@@ -2054,6 +2095,7 @@ START_TEST( sock ) ...@@ -2054,6 +2095,7 @@ START_TEST( sock )
test_UDP(); test_UDP();
test_getservbyname(); test_getservbyname();
test_WSASocket();
test_WSAAddressToStringA(); test_WSAAddressToStringA();
test_WSAAddressToStringW(); test_WSAAddressToStringW();
......
...@@ -75,6 +75,8 @@ extern "C" { ...@@ -75,6 +75,8 @@ extern "C" {
/* protocol types */ /* protocol types */
#define FROM_PROTOCOL_INFO (-1)
#ifndef USE_WS_PREFIX #ifndef USE_WS_PREFIX
#define SOCK_STREAM 1 #define SOCK_STREAM 1
#define SOCK_DGRAM 2 #define SOCK_DGRAM 2
......
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