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 {
// 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);
}
}
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);
}
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 "
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) {