Owen Rudge : wsdapi: Implement IWSDUdpAddress_GetTransportAddress[Ex].
Module: wine Branch: master Commit: d140cd504ab7d0c0d3e9a07668138a9bec80df28 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d140cd504ab7d0c0d3e9a07668... Author: Owen Rudge <orudge(a)codeweavers.com> Date: Wed Jun 28 22:13:15 2017 +0100 wsdapi: Implement IWSDUdpAddress_GetTransportAddress[Ex]. Signed-off-by: Owen Rudge <orudge(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- dlls/wsdapi/address.c | 57 ++++++++++++++++++++++++++++++++++++++++----- dlls/wsdapi/tests/address.c | 28 +++++++++++----------- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/dlls/wsdapi/address.c b/dlls/wsdapi/address.c index 587d090..05c4bb9 100644 --- a/dlls/wsdapi/address.c +++ b/dlls/wsdapi/address.c @@ -35,6 +35,8 @@ typedef struct IWSDUdpAddressImpl { IWSDUdpAddress IWSDUdpAddress_iface; LONG ref; SOCKADDR_STORAGE sockAddr; + WCHAR ipv4Address[25]; + WCHAR ipv6Address[64]; } IWSDUdpAddressImpl; static inline IWSDUdpAddressImpl *impl_from_IWSDUdpAddress(IWSDUdpAddress *iface) @@ -121,16 +123,59 @@ static HRESULT WINAPI IWSDUdpAddressImpl_SetPort(IWSDUdpAddress *This, WORD wPor return E_NOTIMPL; } -static HRESULT WINAPI IWSDUdpAddressImpl_GetTransportAddress(IWSDUdpAddress *This, LPCWSTR *ppszAddress) +static HRESULT WINAPI IWSDUdpAddressImpl_GetTransportAddressEx(IWSDUdpAddress *This, BOOL fSafe, LPCWSTR *ppszAddress) { - FIXME("(%p, %p)\n", This, ppszAddress); - return E_NOTIMPL; + IWSDUdpAddressImpl *impl = impl_from_IWSDUdpAddress(This); + SOCKADDR_STORAGE storage; + DWORD size; + + TRACE("(%p, %d, %p)\n", This, fSafe, ppszAddress); + + if (ppszAddress == NULL) + return E_POINTER; + + *ppszAddress = NULL; + + switch (((SOCKADDR_IN *) &impl->sockAddr)->sin_family) + { + case AF_INET: + size = sizeof(impl->ipv4Address) / sizeof(WCHAR); + + if (WSAAddressToStringW((LPSOCKADDR) &impl->sockAddr, sizeof(SOCKADDR_IN), NULL, impl->ipv4Address, &size) == 0) + { + *ppszAddress = impl->ipv4Address; + return S_OK; + } + + break; + + case AF_INET6: + size = sizeof(impl->ipv6Address) / sizeof(WCHAR); + + /* Copy the SOCKADDR structure so we can remove the scope ID if not required */ + memcpy(&storage, &impl->sockAddr, sizeof(SOCKADDR_IN6)); + + if (!fSafe) + ((SOCKADDR_IN6 *) &storage)->sin6_scope_id = 0; + + if (WSAAddressToStringW((LPSOCKADDR) &storage, sizeof(SOCKADDR_IN6), NULL, impl->ipv6Address, &size) == 0) + { + *ppszAddress = impl->ipv6Address; + return S_OK; + } + + break; + + default: + return S_OK; + } + + return HRESULT_FROM_WIN32(WSAGetLastError()); } -static HRESULT WINAPI IWSDUdpAddressImpl_GetTransportAddressEx(IWSDUdpAddress *This, BOOL fSafe, LPCWSTR *ppszAddress) +static HRESULT WINAPI IWSDUdpAddressImpl_GetTransportAddress(IWSDUdpAddress *This, LPCWSTR *ppszAddress) { - FIXME("(%p, %d, %p)\n", This, fSafe, ppszAddress); - return E_NOTIMPL; + return IWSDUdpAddressImpl_GetTransportAddressEx(This, FALSE, ppszAddress); } static HRESULT WINAPI IWSDUdpAddressImpl_SetTransportAddress(IWSDUdpAddress *This, LPCWSTR pszAddress) diff --git a/dlls/wsdapi/tests/address.c b/dlls/wsdapi/tests/address.c index b26a3b9..2142045 100644 --- a/dlls/wsdapi/tests/address.c +++ b/dlls/wsdapi/tests/address.c @@ -95,7 +95,7 @@ static void GetSetTransportAddress_udp_tests(void) ok(udpAddress != NULL, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n"); rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); + ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); ok(returnedAddress == NULL, "GetTransportAddress returned unexpected address: %08x\n", rc); /* Try setting a null address */ @@ -111,12 +111,12 @@ static void GetSetTransportAddress_udp_tests(void) ok(rc == S_OK, "SetTransportAddress(ipv4Address) failed: %08x\n", rc); rc = IWSDUdpAddress_GetTransportAddress(udpAddress, NULL); - todo_wine ok(rc == E_POINTER, "GetTransportAddress(NULL) returned unexpected result: %08x\n", rc); + ok(rc == E_POINTER, "GetTransportAddress(NULL) returned unexpected result: %08x\n", rc); rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); - todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress)); - todo_wine ok(lstrcmpW(returnedAddress, ipv4Address) == 0, "Returned address != ipv4Address (%s)\n", wine_dbgstr_w(returnedAddress)); + ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); + ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress)); + ok(lstrcmpW(returnedAddress, ipv4Address) == 0, "Returned address != ipv4Address (%s)\n", wine_dbgstr_w(returnedAddress)); /* Try setting an IPv4 address with a port number */ rc = IWSDUdpAddress_SetTransportAddress(udpAddress, ipv4AddressWithPort); @@ -127,17 +127,17 @@ static void GetSetTransportAddress_udp_tests(void) ok(rc == S_OK, "SetTransportAddress(ipv6Address) failed: %08x\n", rc); rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); - todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress)); - todo_wine ok(lstrcmpW(returnedAddress, ipv6Address) == 0, "Returned address != ipv6Address (%s)\n", wine_dbgstr_w(returnedAddress)); + ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); + ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress)); + ok(lstrcmpW(returnedAddress, ipv6Address) == 0, "Returned address != ipv6Address (%s)\n", wine_dbgstr_w(returnedAddress)); /* Try setting an IPv6 address with a port number */ rc = IWSDUdpAddress_SetTransportAddress(udpAddress, ipv6AddressWithPort); ok(rc == S_OK, "SetTransportAddress(ipv6AddressWithPort) failed: %08x\n", rc); rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); - todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress)); + ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc); + ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress)); todo_wine ok(lstrcmpW(returnedAddress, ipv6AddressWithPort) == 0, "Returned address != ipv6AddressWithPort (%s)\n", wine_dbgstr_w(returnedAddress)); /* Release the object */ @@ -324,7 +324,7 @@ static void GetSetSockaddr_udp_tests(void) /* Check that GetTransportAddress returns the address set via the socket */ rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); + ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: %p\n", returnedAddress); todo_wine ok(lstrcmpW(returnedAddress, expectedIpv4TransportAddr) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress)); @@ -341,7 +341,7 @@ static void GetSetSockaddr_udp_tests(void) /* Check that GetTransportAddress returns the address set via the socket */ rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); + ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: %p\n", returnedAddress); todo_wine ok(lstrcmpW(returnedAddress, expectedIpv4TransportAddrNoPort) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress)); @@ -364,7 +364,7 @@ static void GetSetSockaddr_udp_tests(void) /* Check that GetTransportAddress returns the address set via the socket */ rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); + ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: %p\n", returnedAddress); todo_wine ok(lstrcmpW(returnedAddress, expectedIpv6TransportAddr) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress)); @@ -381,7 +381,7 @@ static void GetSetSockaddr_udp_tests(void) /* Check that GetTransportAddress returns the address set via the socket */ rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress); - todo_wine ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); + ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc); todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: %p\n", returnedAddress); todo_wine ok(lstrcmpW(returnedAddress, expectedIpv6TransportAddrNoPort) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress));
participants (1)
-
Alexandre Julliard