From 78bdd23406f79737dd5cf3293ebc54c20dbaf453 Mon Sep 17 00:00:00 2001 From: Anton Baskanov Date: Fri, 13 Oct 2023 12:54:41 +0700 Subject: [PATCH] dpwsockx: Broadcast enumeration request in EnumSessions(). --- dlls/dplayx/tests/dplayx.c | 19 ++++++--------- dlls/dpwsockx/dpwsockx_main.c | 46 ++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/dlls/dplayx/tests/dplayx.c b/dlls/dplayx/tests/dplayx.c index 5b765f540b5..8c352837f69 100644 --- a/dlls/dplayx/tests/dplayx.c +++ b/dlls/dplayx/tests/dplayx.c @@ -784,12 +784,7 @@ static SOCKET connectTcp_( int line, unsigned short port ) addr.sin_port = htons( port ); addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); wsResult = connect( sock, (SOCKADDR *) &addr, sizeof( addr ) ); - todo_wine ok_( __FILE__, line)( !wsResult, "connect returned %d.\n", wsResult ); - if ( wsResult == SOCKET_ERROR ) - { - closesocket( sock ); - return INVALID_SOCKET; - } + ok_( __FILE__, line)( !wsResult, "connect returned %d.\n", wsResult ); return sock; } @@ -870,8 +865,8 @@ static unsigned short receiveEnumSessionsRequest_( int line, SOCKET sock, const expectedSize = sizeof( request.spHeader ) + sizeof( request.request ) + expectedPasswordSize; wsResult = receiveMessage_( line, sock, &request, sizeof( request ) ); - todo_wine ok_( __FILE__, line )( wsResult == expectedSize, "recv() returned %d.\n", - wsResult ); + todo_wine_if( expectedPassword ) ok_( __FILE__, line )( wsResult == expectedSize, "recv() returned %d.\n", + wsResult ); if ( wsResult == SOCKET_ERROR ) return 0; @@ -881,10 +876,10 @@ static unsigned short receiveEnumSessionsRequest_( int line, SOCKET sock, const wine_dbgstr_guid( &request.request.appGuid ) ); if ( expectedPassword ) { - ok_( __FILE__, line )( request.request.passwordOffset == 32, "got password offset %lu.\n", - request.request.passwordOffset ); - ok_( __FILE__, line )( !lstrcmpW( request.password, expectedPassword ), "got password %s.\n", - wine_dbgstr_w( request.password ) ); + todo_wine ok_( __FILE__, line )( request.request.passwordOffset == 32, "got password offset %lu.\n", + request.request.passwordOffset ); + todo_wine ok_( __FILE__, line )( !lstrcmpW( request.password, expectedPassword ), "got password %s.\n", + wine_dbgstr_w( request.password ) ); } else { diff --git a/dlls/dpwsockx/dpwsockx_main.c b/dlls/dpwsockx/dpwsockx_main.c index 74eea68f2fc..4a969b1711e 100644 --- a/dlls/dpwsockx/dpwsockx_main.c +++ b/dlls/dpwsockx/dpwsockx_main.c @@ -30,6 +30,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dplay); +#define DPWS_PORT 47624 #define DPWS_START_TCP_PORT 2300 #define DPWS_END_TCP_PORT 2350 @@ -105,15 +106,19 @@ static void DPWS_Stop( DPWS_DATA *dpwsData ) static HRESULT WINAPI DPWSCB_EnumSessions( LPDPSP_ENUMSESSIONSDATA data ) { + DPSP_MSG_HEADER *header = (DPSP_MSG_HEADER *) data->lpMessage; DPWS_DATA *dpwsData; DWORD dpwsDataSize; + SOCKADDR_IN addr; + BOOL true = TRUE; + SOCKET sock; HRESULT hr; - FIXME( "(%p,%ld,%p,%u) stub\n", + TRACE( "(%p,%ld,%p,%u)\n", data->lpMessage, data->dwMessageSize, data->lpISP, data->bReturnStatus ); - hr = IDirectPlaySP_GetSPData( data->lpISP, (void **)&dpwsData, &dpwsDataSize, DPSET_LOCAL ); + hr = IDirectPlaySP_GetSPData( data->lpISP, (void **) &dpwsData, &dpwsDataSize, DPSET_LOCAL ); if ( FAILED( hr ) ) return hr; @@ -121,7 +126,42 @@ static HRESULT WINAPI DPWSCB_EnumSessions( LPDPSP_ENUMSESSIONSDATA data ) if ( FAILED (hr) ) return hr; - return S_OK; + sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); + if ( sock == INVALID_SOCKET ) + { + ERR( "socket() failed\n" ); + return DPERR_UNAVAILABLE; + } + + if ( SOCKET_ERROR == setsockopt( sock, SOL_SOCKET, SO_BROADCAST, (const char *) &true, + sizeof( true ) ) ) + { + ERR( "setsockopt() failed\n" ); + closesocket( sock ); + return DPERR_UNAVAILABLE; + } + + memset( header, 0, sizeof( DPSP_MSG_HEADER ) ); + header->mixed = DPSP_MSG_MAKE_MIXED( data->dwMessageSize, DPSP_MSG_TOKEN_REMOTE ); + header->SockAddr.sin_family = AF_INET; + header->SockAddr.sin_port = dpwsData->tcpAddr.sin_port; + + memset( &addr, 0, sizeof( addr ) ); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = htonl( INADDR_BROADCAST ); + addr.sin_port = htons( DPWS_PORT ); + + if ( SOCKET_ERROR == sendto( sock, data->lpMessage, data->dwMessageSize, 0, (SOCKADDR *) &addr, + sizeof( addr ) ) ) + { + ERR( "sendto() failed\n" ); + closesocket( sock ); + return DPERR_UNAVAILABLE; + } + + closesocket( sock ); + + return DP_OK; } static HRESULT WINAPI DPWSCB_Reply( LPDPSP_REPLYDATA data )