From 528cbac17a6c372d1698c82e30df0fdfc78a5ccc Mon Sep 17 00:00:00 2001 From: Guillaume Le Vaillant Date: Fri, 14 Apr 2023 13:34:30 +0200 Subject: Show IPv6 addresses in connection list --- src/cryptonote_protocol/cryptonote_protocol_handler.inl | 5 +++++ src/daemon/rpc_command_executor.cpp | 13 ++++++++++--- src/rpc/core_rpc_server_commands_defs.h | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 6c36a3b5b..cc7e044f5 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -378,6 +378,11 @@ namespace cryptonote cnx.ip = cnx.host; cnx.port = std::to_string(cntxt.m_remote_address.as().port()); } + else if (cntxt.m_remote_address.get_type_id() == epee::net_utils::ipv6_network_address::get_type_id()) + { + cnx.ip = cnx.host; + cnx.port = std::to_string(cntxt.m_remote_address.as().port()); + } cnx.rpc_port = cntxt.m_rpc_port; cnx.rpc_credits_per_hash = cntxt.m_rpc_credits_per_hash; diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index f0407eece..83620f417 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -644,7 +644,14 @@ bool t_rpc_command_executor::print_connections() { } } - tools::msg_writer() << std::setw(30) << std::left << "Remote Host" + auto longest_host = *std::max_element(res.connections.begin(), res.connections.end(), + [](const auto &info1, const auto &info2) + { + return info1.address.length() < info2.address.length(); + }); + int host_field_width = std::max(15, 8 + (int) longest_host.address.length()); + + tools::msg_writer() << std::setw(host_field_width) << std::left << "Remote Host" << std::setw(8) << "Type" << std::setw(6) << "SSL" << std::setw(20) << "Peer id" @@ -661,11 +668,11 @@ bool t_rpc_command_executor::print_connections() { for (auto & info : res.connections) { std::string address = info.incoming ? "INC " : "OUT "; - address += info.ip + ":" + info.port; + address += info.address; //std::string in_out = info.incoming ? "INC " : "OUT "; tools::msg_writer() //<< std::setw(30) << std::left << in_out - << std::setw(30) << std::left << address + << std::setw(host_field_width) << std::left << address << std::setw(8) << (get_address_type_name((epee::net_utils::address_type)info.address_type)) << std::setw(6) << (info.ssl ? "yes" : "no") << std::setw(20) << info.peer_id diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 46e52d42f..e6c07ce77 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -88,7 +88,7 @@ namespace cryptonote // advance which version they will stop working with // Don't go over 32767 for any of these #define CORE_RPC_VERSION_MAJOR 3 -#define CORE_RPC_VERSION_MINOR 15 +#define CORE_RPC_VERSION_MINOR 16 #define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor)) #define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR) -- cgit v1.2.3 From 7c543c82205c3522510e8da616edc795922ce9f3 Mon Sep 17 00:00:00 2001 From: jeffro256 Date: Sun, 28 Sep 2025 12:40:53 -0500 Subject: daemon: fix print_cn command when 0 connections Deferencing the result of `std::max_element()` when `res.connections` has 0 elements leads to UB, and segfaults in practice. Co-authored-by: iamamyth --- src/daemon/rpc_command_executor.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 83620f417..f6746b8ad 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -644,12 +644,9 @@ bool t_rpc_command_executor::print_connections() { } } - auto longest_host = *std::max_element(res.connections.begin(), res.connections.end(), - [](const auto &info1, const auto &info2) - { - return info1.address.length() < info2.address.length(); - }); - int host_field_width = std::max(15, 8 + (int) longest_host.address.length()); + int host_field_width = 15; + for (const auto &conn : res.connections) + host_field_width = std::max(host_field_width, 8 + (int) conn.address.length()); tools::msg_writer() << std::setw(host_field_width) << std::left << "Remote Host" << std::setw(8) << "Type" -- cgit v1.2.3