[PATCH] ws2_32: Provide default protocol for SOCK_STREAM and SOCK_DGRAM
Windows provides a default protocol in socket() if af is AF_INET or AF_INET6 type is SOCK_STREAM or SOCK_DGRAM and protocol is 0. Signed-off-by: Robin Ebert <ebertrobin2002(a)gmail.com> --- dlls/ws2_32/socket.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index d7eddde..de30ee4 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -835,6 +835,12 @@ static const int ws_poll_map[][2] = { WS_POLLRDBAND, POLLPRI } }; +static const int ws_default_protocol_map[][2] = +{ + { WS_SOCK_STREAM, WS_IPPROTO_TCP }, + { WS_SOCK_DGRAM, WS_IPPROTO_UDP } +}; + static const char magic_loopback_addr[] = {127, 12, 34, 56}; #ifndef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS @@ -1660,6 +1666,26 @@ static int convert_poll_u2w(int events) return ret; } +static int get_default_protocol(int type) +{ + int i, ret; + for(i = ret = 0; i < ARRAY_SIZE(ws_default_protocol_map); i++) + { + if (ws_default_protocol_map[i][0] == type) + { + ret = ws_default_protocol_map[i][1]; + break; + } + } + + if(!ret) + WARN("selecting default protocol failed: type %i\n", type); + else + TRACE("selected %i as default protocol: type %i\n", ret, type); + + return ret; +} + static int set_ipx_packettype(int sock, int ptype) { #ifdef HAS_IPX @@ -7643,6 +7669,19 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol, protocol = lpProtocolInfo->iProtocol; } + /* + Windows provides a default protocol + if af is AF_INET or AF_INET6, + type is SOCKET_STREAM or SOCKET_DGRAM + and protocol is 0 + */ + if (!protocol + && (af == WS_AF_INET || af == WS_AF_INET6) + && (type == WS_SOCK_STREAM || type == WS_SOCK_DGRAM)) + { + protocol = get_default_protocol(type); + } + if (!type && (af || protocol)) { int autoproto = protocol; -- 2.20.1
Hi Robin, Is not specifying a protocol actually causing an issue? or is it just appearing in winsock output? What application are you using? The linux socket function defaults a protocol when its 0 already. Regards Alistair
Hi Alistair, I haven't thought of this. I'm not that familiar with linux syscalls. Not specifying a default protocol makes getsockopt return wrong value with level = SOL_SOCKET and optname = SO_PROTOCOL_INFOW. It leads to a "fixme:winsock:WS_EnterSingleProtocolW unknown Protocol" and an invalid returned WSAPROTOCOL_INFOW in optval but i guess this issue needs to be fixed in the server call in ws_protocol_info then. Regards Robin
participants (2)
-
Alistair Leslie-Hughes -
Robin Ebert