From ceba96fd8069cfb480f22ae5fb7f6f55634d8f1e Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 23 Dec 2016 00:01:25 +0100 Subject: Fixed (ICE-7472) UWP and Mcast interface In UWP the multicast interface must be send when the datagram socket is bind. --- cpp/src/Ice/Network.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'cpp/src/Ice/Network.cpp') diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index f14f7c1fb2e..e53532c48d9 100755 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -2047,7 +2047,7 @@ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string&) try { // - // NOTE: UWP doesn't allow specyfing the interface. + // NOTE: UWP mcast interface is set earlier in doBind. // safe_cast(fd)->JoinMulticastGroup(group.host); @@ -2219,10 +2219,10 @@ checkResultAndWait(IAsyncAction^ action) } #endif +#ifdef ICE_OS_UWP Address -IceInternal::doBind(SOCKET fd, const Address& addr) +IceInternal::doBind(SOCKET fd, const Address& addr, const string& intf) { -#ifdef ICE_OS_UWP Address local; try { @@ -2246,7 +2246,32 @@ IceInternal::doBind(SOCKET fd, const Address& addr) { if(addr.host == nullptr) // inaddr_any { - checkResultAndWait(datagram->BindServiceNameAsync(addr.port)); + NetworkAdapter^ adapter; + if(!intf.empty()) + { + auto s = ref new String(Ice::stringToWstring(intf).c_str()); + auto profiles = NetworkInformation::GetConnectionProfiles(); + for(auto i = profiles->First(); adapter == nullptr && i->HasCurrent; i->MoveNext()) + { + auto names = i->Current->GetNetworkNames(); + for(auto j = names->First(); adapter == nullptr && j->HasCurrent; j->MoveNext()) + { + if(j->Current->Equals(s)) + { + adapter = i->Current->NetworkAdapter; + } + } + } + } + + if(adapter) + { + checkResultAndWait(datagram->BindServiceNameAsync(addr.port, adapter)); + } + else + { + checkResultAndWait(datagram->BindServiceNameAsync(addr.port)); + } } else { @@ -2262,7 +2287,11 @@ IceInternal::doBind(SOCKET fd, const Address& addr) throw; } return local; +} #else +Address +IceInternal::doBind(SOCKET fd, const Address& addr, const string&) +{ int size = getAddressStorageSize(addr); assert(size != 0); @@ -2283,8 +2312,8 @@ IceInternal::doBind(SOCKET fd, const Address& addr) assert(ret != SOCKET_ERROR); # endif return local; -#endif } +#endif #ifndef ICE_OS_UWP -- cgit v1.2.3