From a65659f52f7988d17b2c98e4a1b7184d983cbd69 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 14 Nov 2009 20:35:24 +0000 Subject: [PATCH] broadcast sockets now join every network interface --- ChangeLog | 2 ++ include/libtorrent/broadcast_socket.hpp | 2 +- src/broadcast_socket.cpp | 26 ++++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2bb7ad038..de6cfaf4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -105,6 +105,8 @@ release 0.14.7 * fixed move_storage when source doesn't exist * fixed DHT state save bug for node-id * fixed typo in python binding session_status struct + * broadcast sockets now join every network interface (used for UPnP and + local peer discovery) release 0.14.6 diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index edf97832d..72635853a 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -91,7 +91,7 @@ namespace libtorrent , std::size_t bytes_transferred); void open_unicast_socket(io_service& ios, address const& addr); void open_multicast_socket(io_service& ios, address const& addr - , bool loopback); + , bool loopback, error_code& ec); // these sockets are used to // join the multicast group (on each interface) diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index 69edfebc7..4f37449ae 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -191,15 +191,6 @@ namespace libtorrent error_code ec; std::vector interfaces = enum_net_interfaces(ios, ec); -#if TORRENT_USE_IPV6 - if (multicast_endpoint.address().is_v4()) -#endif - open_multicast_socket(ios, address_v4::any(), loopback); -#if TORRENT_USE_IPV6 - else - open_multicast_socket(ios, address_v6::any(), loopback); -#endif - for (std::vector::const_iterator i = interfaces.begin() , end(interfaces.end()); i != end; ++i) { @@ -208,20 +199,24 @@ namespace libtorrent // ignore any loopback interface if (is_loopback(i->interface_address)) continue; + ec.clear(); + open_multicast_socket(ios, i->interface_address, loopback, ec); #ifndef NDEBUG -// std::cerr << "broadcast socket [ if: " << i->interface_address.to_v4().to_string() -// << " group: " << multicast_endpoint.address() << " ]" << std::endl; +// extern std::string print_address(address const& addr); +// fprintf(stderr, "broadcast socket [ if: %s group: %s ] %s\n" +// , i->interface_address.to_string().c_str() +// , print_address(multicast_endpoint.address()).c_str() +// , ec.message().c_str()); #endif open_unicast_socket(ios, i->interface_address); } } void broadcast_socket::open_multicast_socket(io_service& ios - , address const& addr, bool loopback) + , address const& addr, bool loopback, error_code& ec) { using namespace asio::ip::multicast; - error_code ec; boost::shared_ptr s(new datagram_socket(ios)); s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec); if (ec) return; @@ -265,7 +260,10 @@ namespace libtorrent error_code e; i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e); #ifndef NDEBUG -// std::cerr << " sending on " << i->socket->local_endpoint().address().to_string() << " to: " << m_multicast_endpoint << std::endl; +// extern std::string print_address(address const& addr); +// extern std::string print_endpoint(udp::endpoint const& ep); +// fprintf(stderr, " sending on %s to: %s\n", print_address(i->socket->local_endpoint().address()).c_str() +// , print_endpoint(m_multicast_endpoint).c_str()); #endif if (e) {