diff options
author | Jeffrey Ryan <jeffreyryan@tutanota.com> | 2022-11-16 15:53:15 -0600 |
---|---|---|
committer | Jeffrey Ryan <jeffreyryan@tutanota.com> | 2022-11-17 18:55:09 -0600 |
commit | faaf2af43ba448454449f9aa3df240fd9af9e4d0 (patch) | |
tree | bb20825d758800181a70f27762b68e5760fce440 /src/net | |
parent | Merge pull request #8593 (diff) | |
download | monero-faaf2af43ba448454449f9aa3df240fd9af9e4d0.tar.xz |
p2p: fix exclusive node DNS resolution for certain hosts
Fixes #8633. The function `append_net_address` did not parse hostname + port addresses (e.g. `bar:29080`) correctly if the hostname did not contain a `'.'` character.
@vtnerd comments 1
clear up 2nd conditional statement
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/parse.cpp | 8 | ||||
-rw-r--r-- | src/net/parse.h | 10 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/net/parse.cpp b/src/net/parse.cpp index 1df6175b4..92be492a3 100644 --- a/src/net/parse.cpp +++ b/src/net/parse.cpp @@ -38,7 +38,7 @@ namespace net { void get_network_address_host_and_port(const std::string& address, std::string& host, std::string& port) { - // require ipv6 address format "[addr:addr:addr:...:addr]:port" + // If IPv6 address format with port "[addr:addr:addr:...:addr]:port" if (address.find(']') != std::string::npos) { host = address.substr(1, address.rfind(']') - 1); @@ -47,6 +47,12 @@ namespace net port = address.substr(address.rfind(':') + 1); } } + // Else if IPv6 address format without port e.g. "addr:addr:addr:...:addr" + else if (std::count(address.begin(), address.end(), ':') >= 2) + { + host = address; + } + // Else IPv4, Tor, I2P address or hostname else { host = address.substr(0, address.rfind(':')); diff --git a/src/net/parse.h b/src/net/parse.h index 648076d7b..6ece931c6 100644 --- a/src/net/parse.h +++ b/src/net/parse.h @@ -38,6 +38,16 @@ namespace net { + /*! + * \brief Takes a valid address string (IP, Tor, I2P, or DNS name) and splits it into host and port + * + * The host of an IPv6 addresses in the format "[x:x:..:x]:port" will have the braces stripped. + * For example, when the address is "[ffff::2023]", host will be set to "ffff::2023". + * + * \param address The address string one wants to split + * \param[out] host The host part of the address string. Is always set. + * \param[out] port The port part of the address string. Is only set when address string contains a port. + */ void get_network_address_host_and_port(const std::string& address, std::string& host, std::string& port); /*! |