diff options
-rwxr-xr-x | cpp/src/Ice/Network.cpp | 39 | ||||
-rwxr-xr-x | cpp/src/Ice/Network.h | 3 | ||||
-rwxr-xr-x | cpp/src/Ice/UdpTransceiver.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/udp/AllTests.cpp | 2 |
4 files changed, 37 insertions, 9 deletions
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<DatagramSocket^>(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 diff --git a/cpp/src/Ice/Network.h b/cpp/src/Ice/Network.h index 441fa79b893..f558cff3e13 100755 --- a/cpp/src/Ice/Network.h +++ b/cpp/src/Ice/Network.h @@ -303,8 +303,7 @@ ICE_API void setMcastGroup(SOCKET, const Address&, const std::string&); ICE_API void setMcastInterface(SOCKET, const std::string&, const Address&); ICE_API void setMcastTtl(SOCKET, int, const Address&); ICE_API void setReuseAddress(SOCKET, bool); - -ICE_API Address doBind(SOCKET, const Address&); +ICE_API Address doBind(SOCKET, const Address&, const std::string& intf = ""); ICE_API void doListen(SOCKET, int); #ifndef ICE_OS_UWP diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 4621750689e..00c035b557a 100755 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -142,7 +142,7 @@ IceInternal::UdpTransceiver::bind() const_cast<Address&>(_addr) = getAddressForServer("", _port, getProtocolSupport(_addr), false); #endif - const_cast<Address&>(_addr) = doBind(_fd, _addr); + const_cast<Address&>(_addr) = doBind(_fd, _addr, _mcastInterface); if(getPort(_mcastAddr) == 0) { setPort(_mcastAddr, getPort(_addr)); diff --git a/cpp/test/Ice/udp/AllTests.cpp b/cpp/test/Ice/udp/AllTests.cpp index 8356acbf1cf..e2e00f19da2 100644 --- a/cpp/test/Ice/udp/AllTests.cpp +++ b/cpp/test/Ice/udp/AllTests.cpp @@ -149,7 +149,7 @@ allTests(const CommunicatorPtr& communicator) } base = communicator->stringToProxy("test -d:" + endpoint); TestIntfPrxPtr objMcast = ICE_UNCHECKED_CAST(TestIntfPrx, base); -#if !defined(ICE_OS_UWP) && (!defined(__APPLE__) || (defined(__APPLE__) && !TARGET_OS_IPHONE)) +#if (!defined(__APPLE__) || (defined(__APPLE__) && !TARGET_OS_IPHONE)) cout << "testing udp multicast... " << flush; nRetry = 5; |