From 85fe75d1cbaf372f0a98558adcd5a612a0e19602 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 5 Feb 2014 21:24:46 +0100 Subject: Add the option to bind to a specific address --- src/connection.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/connection.cpp') diff --git a/src/connection.cpp b/src/connection.cpp index 92f9f8ec2..f8c68ed2e 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -1597,8 +1597,8 @@ void ConnectionSendThread::processNonReliableCommand(ConnectionCommand &c) return; case CONNCMD_SERVE: LOG(dout_con<getDesc()<<" UDP processing CONNCMD_SERVE port=" - <getDesc()<<" UDP processing CONNCMD_CONNECT"<getDesc()<<"UDP serving at port "<getDesc() + <<"UDP serving at port " << bind_address.serializeString() <m_udpSocket.Bind(port); + m_connection->m_udpSocket.Bind(bind_address); m_connection->SetPeerID(PEER_ID_SERVER); } catch(SocketException &e){ @@ -1658,7 +1659,14 @@ void ConnectionSendThread::connect(Address address) e.peerAdded(peer->id, peer->address); m_connection->putEvent(e); - m_connection->m_udpSocket.Bind(0); + Address bind_addr; + + if (address.isIPv6()) + bind_addr.setAddress((IPv6AddressBytes*) NULL); + else + bind_addr.setAddress(0,0,0,0); + + m_connection->m_udpSocket.Bind(bind_addr); // Send a dummy packet to server with peer_id = PEER_ID_INEXISTENT m_connection->SetPeerID(PEER_ID_INEXISTENT); @@ -1716,7 +1724,8 @@ void ConnectionSendThread::send(u16 peer_id, u8 channelnum, assert(channelnum < CHANNEL_COUNT); PeerHelper peer = m_connection->getPeerNoEx(peer_id); - if(!peer) { + if(!peer) + { LOG(dout_con<getDesc()<<" peer: peer_id="<>>NOT<<< found on sending packet" << ", channel " << (channelnum % 0xFF) @@ -2766,10 +2775,10 @@ void Connection::putCommand(ConnectionCommand &c) } } -void Connection::Serve(unsigned short port) +void Connection::Serve(Address bind_addr) { ConnectionCommand c; - c.serve(port); + c.serve(bind_addr); putCommand(c); } -- cgit v1.2.3