Index: webrtc/base/virtualsocketserver.cc |
diff --git a/webrtc/base/virtualsocketserver.cc b/webrtc/base/virtualsocketserver.cc |
index 9b0e48d1d86b1f025ee72de61cda3a8f352c02d9..51eccdd9292cdfe4e66623f47a37d4ab50f43f9b 100644 |
--- a/webrtc/base/virtualsocketserver.cc |
+++ b/webrtc/base/virtualsocketserver.cc |
@@ -286,6 +286,12 @@ int VirtualSocket::RecvFrom(void* pv, size_t cb, SocketAddress* paddr) { |
size_t data_read = std::min(cb, packet->size()); |
memcpy(pv, packet->data(), data_read); |
*paddr = packet->from(); |
+ // HACK(any_address): when the incoming packet is from a binding of the any |
juberti1
2015/08/06 00:35:26
Can this be done on the send side? i.e. in AddPack
pthatcher1
2015/08/06 01:06:18
I was thinking the same thing. That would be more
guoweis_webrtc
2015/08/06 08:50:06
Done.
|
+ // address, translate it to the default interface here such that the STUN |
+ // server will see a valid interface. |
+ if (paddr->IsAnyIP()) { |
+ *paddr = server_->TryMapAnyAddressToDefault(*paddr); |
+ } |
if (data_read < packet->size()) { |
packet->Consume(data_read); |
@@ -661,7 +667,17 @@ VirtualSocket* VirtualSocketServer::LookupBinding(const SocketAddress& addr) { |
SocketAddress normalized(addr.ipaddr().Normalized(), |
addr.port()); |
AddressMap::iterator it = bindings_->find(normalized); |
- return (bindings_->end() != it) ? it->second : NULL; |
+ VirtualSocket* socket = (bindings_->end() != it) ? it->second : NULL; |
+ if (socket || addr.ipaddr() != default_interface(addr.ipaddr().family())) { |
+ return socket; |
+ } |
+ |
+ // HACK(any_address): If we can't find a binding, maybe this is resulted from |
juberti1
2015/08/06 00:35:26
Is this still needed if we do the change I suggest
guoweis_webrtc
2015/08/06 08:50:06
yes, since the binding of the default route just d
|
+ // RecvFrom where we translate the any address to the default interface. |
+ SocketAddress sock_addr = |
+ EmptySocketAddressWithFamily(addr.ipaddr().family()); |
+ sock_addr.SetPort(addr.port()); |
+ return LookupBinding(sock_addr); |
} |
int VirtualSocketServer::Unbind(const SocketAddress& addr, |
@@ -1080,4 +1096,15 @@ bool VirtualSocketServer::CanInteractWith(VirtualSocket* local, |
return false; |
} |
+const SocketAddress VirtualSocketServer::TryMapAnyAddressToDefault( |
pthatcher1
2015/08/06 01:06:18
I think a better name would be GetDefaultRouteIfNe
guoweis_webrtc
2015/08/06 08:50:06
Done.
|
+ const SocketAddress& addr) { |
+ IPAddress default_ip = default_interface(addr.ipaddr().family()); |
+ if (!addr.IsAnyIP() || IPIsUnspec(default_ip)) { |
+ return addr; |
+ } |
+ SocketAddress address = addr; |
+ address.SetIP(default_ip); |
+ return address; |
+} |
+ |
} // namespace rtc |