mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
fix: more misc net.cc fixes (#6735)
* feat: accept ipv6 string in square brackets for `tr_address::from_string()` * test: add test case for ipv6 string in square brackets * fix: include square brackets in host component According to RFC3986: host = IP-literal / IPv4address / reg-name IP-literal = "[" ( IPv6address / IPvFuture ) "]" * fix: set ipv6-only socket before binding UDP socket Will return EINVAL on Linux otherwise * refactor: simplify code using `evutil` when binding TCP socket * fix: do not set SO_REUSEADDR for listening sockets on Windows systems Reason: https://stackoverflow.com/a/14388707/11390656 * fix: do not enclose ipv4 address string in square brackets
This commit is contained in:
@@ -340,8 +340,13 @@ std::optional<tr_url_parsed_t> tr_urlParse(std::string_view url)
|
||||
auto remain = parsed.authority;
|
||||
if (tr_strv_starts_with(remain, '['))
|
||||
{
|
||||
remain.remove_prefix(1); // '['
|
||||
parsed.host = tr_strv_sep(&remain, ']');
|
||||
pos = remain.find(']');
|
||||
if (pos == std::string_view::npos)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
parsed.host = remain.substr(0, pos + 1);
|
||||
remain.remove_prefix(pos + 1);
|
||||
if (tr_strv_starts_with(remain, ':'))
|
||||
{
|
||||
remain.remove_prefix(1);
|
||||
@@ -389,7 +394,7 @@ std::optional<tr_url_parsed_t> tr_urlParse(std::string_view url)
|
||||
std::optional<tr_url_parsed_t> tr_urlParseTracker(std::string_view url)
|
||||
{
|
||||
auto const parsed = tr_urlParse(url);
|
||||
return parsed && tr_isValidTrackerScheme(parsed->scheme) ? std::make_optional(*parsed) : std::nullopt;
|
||||
return parsed && tr_isValidTrackerScheme(parsed->scheme) ? parsed : std::nullopt;
|
||||
}
|
||||
|
||||
bool tr_urlIsValidTracker(std::string_view url)
|
||||
|
||||
Reference in New Issue
Block a user