diff --git a/examples/Jamfile b/examples/Jamfile index 6c4afc8c3..37a6684d9 100644 --- a/examples/Jamfile +++ b/examples/Jamfile @@ -21,7 +21,6 @@ exe client_test : client_test.cpp ; exe simple_client : simple_client.cpp ; exe dump_torrent : dump_torrent.cpp ; exe make_torrent : make_torrent.cpp ; -exe enum_if : enum_if.cpp ; exe connection_tester : connection_tester.cpp ; exe fragmentation_test : fragmentation_test.cpp ; exe rss_reader : rss_reader.cpp ; diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 75b81f1c2..6ee17bb7d 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -59,7 +59,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/magnet_uri.hpp" #include "libtorrent/bitfield.hpp" #include "libtorrent/peer_info.hpp" -#include "libtorrent/socket_io.hpp" // print_address #include "libtorrent/time.hpp" #include "libtorrent/create_torrent.hpp" @@ -264,6 +263,21 @@ bool is_hex(char const *in, int len) return true; } +std::string print_endpoint(libtorrent::tcp::endpoint const& ep) +{ + using namespace libtorrent; + error_code ec; + char buf[200]; + address const& addr = ep.address(); +#if TORRENT_USE_IPV6 + if (addr.is_v6()) + snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), ep.port()); + else +#endif + snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), ep.port()); + return buf; +} + enum { torrents_all, torrents_downloading, @@ -571,9 +585,9 @@ void print_peer_info(std::string& out, std::vector const& if (print_ip) { - snprintf(str, sizeof(str), "%-30s %-22s", (print_endpoint(i->ip) + + snprintf(str, sizeof(str), "%-30s %-22s", (::print_endpoint(i->ip) + (i->connection_type == peer_info::bittorrent_utp ? " [uTP]" : "")).c_str() - , print_endpoint(i->local_endpoint).c_str()); + , ::print_endpoint(i->local_endpoint).c_str()); out += str; } diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index ce7fe23e5..44cb03a92 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -45,20 +45,20 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - TORRENT_EXPORT bool is_local(address const& a); - TORRENT_EXPORT bool is_loopback(address const& addr); - TORRENT_EXPORT bool is_multicast(address const& addr); - TORRENT_EXPORT bool is_any(address const& addr); - TORRENT_EXPORT bool is_teredo(address const& addr); + TORRENT_EXTRA_EXPORT bool is_local(address const& a); + TORRENT_EXTRA_EXPORT bool is_loopback(address const& addr); + TORRENT_EXTRA_EXPORT bool is_multicast(address const& addr); + TORRENT_EXTRA_EXPORT bool is_any(address const& addr); + TORRENT_EXTRA_EXPORT bool is_teredo(address const& addr); TORRENT_EXTRA_EXPORT int cidr_distance(address const& a1, address const& a2); // determines if the operating system supports IPv6 - TORRENT_EXPORT bool supports_ipv6(); + TORRENT_EXTRA_EXPORT bool supports_ipv6(); TORRENT_EXTRA_EXPORT int common_bits(unsigned char const* b1 , unsigned char const* b2, int n); - TORRENT_EXPORT address guess_local_address(io_service&); + TORRENT_EXTRA_EXPORT address guess_local_address(io_service&); typedef boost::function receive_handler_t; diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index 7c1df2f63..90a1f0309 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -62,20 +62,20 @@ namespace libtorrent // returns a list of the configured IP interfaces // on the machine - TORRENT_EXPORT std::vector enum_net_interfaces(io_service& ios + TORRENT_EXTRA_EXPORT std::vector enum_net_interfaces(io_service& ios , error_code& ec); - TORRENT_EXPORT std::vector enum_routes(io_service& ios, error_code& ec); + TORRENT_EXTRA_EXPORT std::vector enum_routes(io_service& ios, error_code& ec); // return (a1 & mask) == (a2 & mask) - TORRENT_EXPORT bool match_addr_mask(address const& a1, address const& a2, address const& mask); + TORRENT_EXTRA_EXPORT bool match_addr_mask(address const& a1, address const& a2, address const& mask); // returns true if the specified address is on the same // local network as us - TORRENT_EXPORT bool in_local_network(io_service& ios, address const& addr + TORRENT_EXTRA_EXPORT bool in_local_network(io_service& ios, address const& addr , error_code& ec); - TORRENT_EXPORT address get_default_gateway(io_service& ios + TORRENT_EXTRA_EXPORT address get_default_gateway(io_service& ios , error_code& ec); } diff --git a/include/libtorrent/socket_io.hpp b/include/libtorrent/socket_io.hpp index ed10aff0a..201c628cb 100644 --- a/include/libtorrent/socket_io.hpp +++ b/include/libtorrent/socket_io.hpp @@ -43,10 +43,10 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - TORRENT_EXPORT std::string print_address(address const& addr); - TORRENT_EXPORT std::string print_endpoint(tcp::endpoint const& ep); - TORRENT_EXPORT std::string print_endpoint(udp::endpoint const& ep); - TORRENT_EXPORT std::string address_to_bytes(address const& a); + TORRENT_EXTRA_EXPORT std::string print_address(address const& addr); + TORRENT_EXTRA_EXPORT std::string print_endpoint(tcp::endpoint const& ep); + TORRENT_EXTRA_EXPORT std::string print_endpoint(udp::endpoint const& ep); + TORRENT_EXTRA_EXPORT std::string address_to_bytes(address const& a); TORRENT_EXTRA_EXPORT void hash_address(address const& ip, sha1_hash& h); namespace detail diff --git a/src/socket_io.cpp b/src/socket_io.cpp index 9f1b12a47..3700ecca3 100644 --- a/src/socket_io.cpp +++ b/src/socket_io.cpp @@ -67,25 +67,15 @@ namespace libtorrent std::string print_endpoint(tcp::endpoint const& ep) { error_code ec; - std::string ret; + char buf[200]; address const& addr = ep.address(); #if TORRENT_USE_IPV6 if (addr.is_v6()) - { - ret += '['; - ret += addr.to_string(ec); - ret += ']'; - ret += ':'; - ret += to_string(ep.port()).elems; - } + snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), ep.port()); else #endif - { - ret += addr.to_string(ec); - ret += ':'; - ret += to_string(ep.port()).elems; - } - return ret; + snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), ep.port()); + return buf; } std::string print_endpoint(udp::endpoint const& ep) diff --git a/test/Jamfile b/test/Jamfile index 1cad17be5..2a6636e62 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -5,7 +5,11 @@ use-project /torrent : .. ; exe test_natpmp : test_natpmp.cpp /torrent//torrent : multi on full ; +exe enum_if : enum_if.cpp /torrent//torrent + : multi on full ; + explicit test_natpmp ; +explicit enum_if ; lib libtorrent_test : # sources diff --git a/examples/enum_if.cpp b/test/enum_if.cpp similarity index 100% rename from examples/enum_if.cpp rename to test/enum_if.cpp