Module: wine Branch: master Commit: cabb350f2f7310759b2c2cd9232980d260e6d584 URL: http://source.winehq.org/git/wine.git/?a=commit;h=cabb350f2f7310759b2c2cd923...
Author: Kai Blin kai.blin@gmail.com Date: Mon May 26 10:02:42 2008 +0200
ws2_32: Add support for FROM_PROTOCOL_INFO to WSASocket().
---
dlls/ws2_32/socket.c | 29 +++++++++++------------------ dlls/ws2_32/tests/sock.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/winsock2.h | 2 ++ 3 files changed, 55 insertions(+), 18 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index d0d2a13..ab57388 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -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? */ diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 405b47e..8aaa72f 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -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(); diff --git a/include/winsock2.h b/include/winsock2.h index a302331..b73fde3 100644 --- a/include/winsock2.h +++ b/include/winsock2.h @@ -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