Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / p2p / base / tcpport.cc
index d83623f..069323a 100644 (file)
@@ -121,6 +121,7 @@ void TCPPort::PrepareAddress() {
     if (socket_->GetState() == talk_base::AsyncPacketSocket::STATE_BOUND ||
         socket_->GetState() == talk_base::AsyncPacketSocket::STATE_CLOSED)
       AddAddress(socket_->GetLocalAddress(), socket_->GetLocalAddress(),
+                 talk_base::SocketAddress(),
                  TCP_PROTOCOL_NAME, LOCAL_PORT_TYPE,
                  ICE_TYPE_PREFERENCE_HOST_TCP, true);
   } else {
@@ -128,8 +129,9 @@ void TCPPort::PrepareAddress() {
     // Note: We still add the address, since otherwise the remote side won't
     // recognize our incoming TCP connections.
     AddAddress(talk_base::SocketAddress(ip(), 0),
-               talk_base::SocketAddress(ip(), 0), TCP_PROTOCOL_NAME,
-               LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST_TCP, true);
+               talk_base::SocketAddress(ip(), 0), talk_base::SocketAddress(),
+               TCP_PROTOCOL_NAME, LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST_TCP,
+               true);
   }
 }
 
@@ -221,7 +223,7 @@ void TCPPort::OnReadyToSend(talk_base::AsyncPacketSocket* socket) {
 
 void TCPPort::OnAddressReady(talk_base::AsyncPacketSocket* socket,
                              const talk_base::SocketAddress& address) {
-  AddAddress(address, address, "tcp",
+  AddAddress(address, address, talk_base::SocketAddress(), "tcp",
              LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST_TCP,
              true);
 }
@@ -235,7 +237,7 @@ TCPConnection::TCPConnection(TCPPort* port, const Candidate& candidate,
     int opts = (candidate.protocol() == SSLTCP_PROTOCOL_NAME) ?
         talk_base::PacketSocketFactory::OPT_SSLTCP : 0;
     socket_ = port->socket_factory()->CreateClientTcpSocket(
-        talk_base::SocketAddress(port_->Network()->ip(), 0),
+        talk_base::SocketAddress(port->ip(), 0),
         candidate.address(), port->proxy(), port->user_agent(), opts);
     if (socket_) {
       LOG_J(LS_VERBOSE, this) << "Connecting from "
@@ -291,9 +293,19 @@ int TCPConnection::GetError() {
 
 void TCPConnection::OnConnect(talk_base::AsyncPacketSocket* socket) {
   ASSERT(socket == socket_);
-  LOG_J(LS_VERBOSE, this) << "Connection established to "
-                          << socket->GetRemoteAddress().ToSensitiveString();
-  set_connected(true);
+  // Do not use this connection if the socket bound to a different address than
+  // the one we asked for. This is seen in Chrome, where TCP sockets cannot be
+  // given a binding address, and the platform is expected to pick the
+  // correct local address.
+  if (socket->GetLocalAddress().ipaddr() == port()->ip()) {
+    LOG_J(LS_VERBOSE, this) << "Connection established to "
+                            << socket->GetRemoteAddress().ToSensitiveString();
+    set_connected(true);
+  } else {
+    LOG_J(LS_WARNING, this) << "Dropping connection as TCP socket bound to a "
+                            << "different address from the local candidate.";
+    socket_->Close();
+  }
 }
 
 void TCPConnection::OnClose(talk_base::AsyncPacketSocket* socket, int error) {