mirror of
https://github.com/transmission/transmission
synced 2025-02-07 06:54:40 +00:00
* fix: check if address is valid in `tr_address::is_any()` * refactor: add static implementation of `tr_address::is_valid()`
This commit is contained in:
parent
6e7fdef721
commit
5a6f0a5623
3 changed files with 13 additions and 7 deletions
|
@ -186,7 +186,7 @@ bool tr_global_ip_cache::try_shutdown() noexcept
|
|||
|
||||
tr_address tr_global_ip_cache::bind_addr(tr_address_type type) const noexcept
|
||||
{
|
||||
if (type == TR_AF_INET || type == TR_AF_INET6)
|
||||
if (tr_address::is_valid(type))
|
||||
{
|
||||
if (auto const addr = tr_address::from_string(mediator_.settings_bind_addr(type)); addr && type == addr->type)
|
||||
{
|
||||
|
|
|
@ -243,7 +243,7 @@ struct tr_address
|
|||
static auto constexpr CompactAddrBytes = std::array{ 4U, 16U };
|
||||
static_assert(std::size(CompactAddrBytes) == NUM_TR_AF_INET_TYPES);
|
||||
|
||||
[[nodiscard]] static auto constexpr any(tr_address_type type) noexcept
|
||||
[[nodiscard]] static auto any(tr_address_type type) noexcept
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -252,18 +252,24 @@ struct tr_address
|
|||
case TR_AF_INET6:
|
||||
return tr_address{ TR_AF_INET6, { IN6ADDR_ANY_INIT } };
|
||||
default:
|
||||
TR_ASSERT_MSG(false, "invalid type");
|
||||
return tr_address{};
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto is_valid() const noexcept
|
||||
[[nodiscard]] static constexpr auto is_valid(tr_address_type type) noexcept
|
||||
{
|
||||
return type == TR_AF_INET || type == TR_AF_INET6;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto is_valid() const noexcept
|
||||
{
|
||||
return is_valid(type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_any() const noexcept
|
||||
{
|
||||
return *this == any(type);
|
||||
return is_valid() ? *this == any(type) : false;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -818,7 +818,7 @@ public:
|
|||
|
||||
[[nodiscard]] bool has_ip_protocol(tr_address_type type) const noexcept
|
||||
{
|
||||
TR_ASSERT(type == TR_AF_INET || type == TR_AF_INET6);
|
||||
TR_ASSERT(tr_address::is_valid(type));
|
||||
return global_ip_cache_->has_ip_protocol(type);
|
||||
}
|
||||
|
||||
|
@ -826,7 +826,7 @@ public:
|
|||
|
||||
[[nodiscard]] std::optional<tr_address> global_address(tr_address_type type) const noexcept
|
||||
{
|
||||
TR_ASSERT(type == TR_AF_INET || type == TR_AF_INET6);
|
||||
TR_ASSERT(tr_address::is_valid(type));
|
||||
return global_ip_cache_->global_addr(type);
|
||||
}
|
||||
|
||||
|
@ -837,7 +837,7 @@ public:
|
|||
|
||||
[[nodiscard]] std::optional<tr_address> global_source_address(tr_address_type type) const noexcept
|
||||
{
|
||||
TR_ASSERT(type == TR_AF_INET || type == TR_AF_INET6);
|
||||
TR_ASSERT(tr_address::is_valid(type));
|
||||
return global_ip_cache_->global_source_addr(type);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue