NATPMP fixes

This commit is contained in:
Arvid Norberg
2026-04-27 15:09:06 +02:00
committed by Arvid Norberg
parent 3c3f64e7a7
commit a68a697567
2 changed files with 9 additions and 7 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ namespace libtorrent {
namespace errors {
// See RFC 6887 Section 7.4
enum pcp_errors
enum pcp_errors : int
{
pcp_success = 0,
pcp_unsupp_version,
+8 -6
View File
@@ -591,6 +591,7 @@ void natpmp::on_resend_request(port_mapping_t const i, error_code const& e)
void natpmp::resend_request(port_mapping_t const i)
{
TORRENT_ASSERT(i >= port_mapping_t{0});
if (m_currently_mapping != i) return;
// if we're shutting down, don't retry, just move on
@@ -698,7 +699,8 @@ void natpmp::on_reply(error_code const& e
if (m_version == version_pcp && !aux::is_v6(m_socket.local_endpoint(ec)))
{
m_version = version_natpmp;
resend_request(m_currently_mapping);
if (m_currently_mapping != port_mapping_t{-1})
resend_request(m_currently_mapping);
send_get_ip_address_request();
}
return;
@@ -713,12 +715,12 @@ void natpmp::on_reply(error_code const& e
return;
}
int lifetime = 0;
std::uint32_t lifetime = 0;
if (version == version_pcp)
{
lifetime = aux::numeric_cast<int>(read_uint32(in));
lifetime = read_uint32(in);
}
int const time = aux::numeric_cast<int>(read_uint32(in));
std::uint32_t const time = read_uint32(in);
if (version == version_pcp) in += 12; // reserved
TORRENT_UNUSED(time);
@@ -760,7 +762,7 @@ void natpmp::on_reply(error_code const& e
int const private_port = read_uint16(in);
int const public_port = read_uint16(in);
if (version == version_natpmp)
lifetime = aux::numeric_cast<int>(read_uint32(in));
lifetime = read_uint32(in);
address external_addr;
if (version == version_pcp)
{
@@ -779,7 +781,7 @@ void natpmp::on_reply(error_code const& e
#ifndef TORRENT_DISABLE_LOGGING
char msg[200];
int const num_chars = std::snprintf(msg, sizeof(msg), "<== port map ["
" transport: %s protocol: %s local: %d external: %d ttl: %d ]"
" transport: %s protocol: %s local: %d external: %d ttl: %u ]"
, version_to_string(protocol_version(version))
, (protocol == portmap_protocol::udp ? "udp" : "tcp")
, private_port, public_port, lifetime);