aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2023-01-11 11:41:11 -0500
committerluigi1111 <luigi1111w@gmail.com>2023-01-11 11:41:11 -0500
commit9489586add5116a48039616140bb7267b16ba7b1 (patch)
treec8f533e8a7461d97e932834a1cd8e5d9704d5469
parentMerge pull request #8645 (diff)
parentcommon: DNSResolver can handle hostnames without dot characters (diff)
downloadmonero-9489586add5116a48039616140bb7267b16ba7b1.tar.xz
Merge pull request #8648
8687da6 common: DNSResolver can handle hostnames without dot characters (Jeffrey Ryan)
-rw-r--r--src/common/dns_utils.cpp15
-rw-r--r--src/common/dns_utils.h9
-rw-r--r--tests/unit_tests/dns_resolver.cpp11
3 files changed, 11 insertions, 24 deletions
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index e00421f87..aceefcf36 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -326,11 +326,6 @@ std::vector<std::string> DNSResolver::get_record(const std::string& url, int rec
dnssec_available = false;
dnssec_valid = false;
- if (!check_address_syntax(url.c_str()))
- {
- return addresses;
- }
-
// destructor takes care of cleanup
ub_result_ptr result;
@@ -413,16 +408,6 @@ DNSResolver DNSResolver::create()
return DNSResolver();
}
-bool DNSResolver::check_address_syntax(const char *addr) const
-{
- // if string doesn't contain a dot, we won't consider it a url for now.
- if (strchr(addr,'.') == NULL)
- {
- return false;
- }
- return true;
-}
-
namespace dns_utils
{
diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h
index f9507b42a..81079ba30 100644
--- a/src/common/dns_utils.h
+++ b/src/common/dns_utils.h
@@ -159,15 +159,6 @@ private:
// TODO: modify this to accommodate DNSSEC
std::vector<std::string> get_record(const std::string& url, int record_type, boost::optional<std::string> (*reader)(const char *,size_t), bool& dnssec_available, bool& dnssec_valid);
- /**
- * @brief Checks a string to see if it looks like a URL
- *
- * @param addr the string to be checked
- *
- * @return true if it looks enough like a URL, false if not
- */
- bool check_address_syntax(const char *addr) const;
-
DNSResolverData *m_data;
}; // class DNSResolver
diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp
index a6b733592..d56cbe45b 100644
--- a/tests/unit_tests/dns_resolver.cpp
+++ b/tests/unit_tests/dns_resolver.cpp
@@ -158,6 +158,17 @@ TEST(DNSResolver, GetTXTRecord)
EXPECT_STREQ("donate.getmonero.org", addr.c_str());
}
+TEST(DNSResolver, Localhost)
+{
+ tools::DNSResolver resolver = tools::DNSResolver::create();
+
+ bool avail, valid;
+ std::vector<std::string> ips = resolver.get_ipv4("localhost", avail, valid);
+
+ ASSERT_EQ(1, ips.size());
+ ASSERT_EQ("127.0.0.1", ips[0]);
+}
+
bool is_equal(const char *s, const std::vector<std::string> &v) { return v.size() == 1 && v[0] == s; }
TEST(DNS_PUBLIC, empty) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("").empty()); }