ws2_32: Add support for FROM_PROTOCOL_INFO to WSASocket().

oldstable
Kai Blin 2008-05-26 10:02:42 +02:00 committed by Alexandre Julliard
parent 3978df4e52
commit cabb350f2f
3 changed files with 55 additions and 18 deletions

View File

@ -297,6 +297,7 @@ static const int ws_af_map[][2] =
#ifdef HAVE_IPX
MAP_OPTION( AF_IPX ),
#endif
{FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO},
};
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_STREAM ),
MAP_OPTION( SOCK_RAW ),
{FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO},
};
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_IGMP ),
MAP_OPTION( IPPROTO_RAW ),
{FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO},
};
static const int ws_aiflag_map[][2] =
@ -3781,28 +3784,18 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
return ret;
}
/* check and convert the socket family */
/* convert the socket family and type */
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);
if (type == -1)
{
SetLastError(WSAESOCKTNOSUPPORT);
return INVALID_SOCKET;
}
/* check the protocol type */
if ( protocol < 0 ) /* don't support negative values */
if (lpProtocolInfo)
{
SetLastError(WSAEPROTONOSUPPORT);
return INVALID_SOCKET;
if (af == FROM_PROTOCOL_INFO)
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? */

View File

@ -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)
{
INT ret;
@ -2054,6 +2095,7 @@ START_TEST( sock )
test_UDP();
test_getservbyname();
test_WSASocket();
test_WSAAddressToStringA();
test_WSAAddressToStringW();

View File

@ -75,6 +75,8 @@ extern "C" {
/* protocol types */
#define FROM_PROTOCOL_INFO (-1)
#ifndef USE_WS_PREFIX
#define SOCK_STREAM 1
#define SOCK_DGRAM 2