From 5e23d9328bf37e773fd838674ce1e79f03b5565d Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 28 Jul 2025 11:29:40 +0200 Subject: [PATCH] dnsname: Add a comment about what `DNSName::matches` accepts Signed-off-by: Remi Gacogne (cherry picked from commit 7394dd09afce13c1cd287c2b63f8d129e8be22af) Signed-off-by: Remi Gacogne --- pdns/dnsname.hh | 3 ++- pdns/test-dnsname_cc.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 8d7a9571e7..b09a004b5c 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -112,7 +112,8 @@ public: bool isPartOf(const DNSName& rhs) const; //!< Are we part of the rhs name? Note that name.isPartOf(name). inline bool operator==(const DNSName& rhs) const; //!< DNS-native comparison (case insensitive) - empty compares to empty bool operator!=(const DNSName& other) const { return !(*this == other); } - bool matches(const std::string_view& wire_uncompressed) const; // DNS-native (case insensitive) comparison against raw data in wire format + // !< DNS-native (case insensitive) comparison against raw data in wire format. The view has to start with the DNS name, but does not have to contain only a DNS name. For example passing a view of a DNS packet starting just after the DNS header is OK. + bool matches(const std::string_view& wire_uncompressed) const; std::string toString(const std::string& separator=".", const bool trailing=true) const; //!< Our human-friendly, escaped, representation void toString(std::string& output, const std::string& separator=".", const bool trailing=true) const; diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 63207ad66d..cf24bacd77 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -1042,7 +1042,7 @@ BOOST_AUTO_TEST_CASE(test_raw_data_comparison) { const std::string_view raw(reinterpret_cast(query.data()) + sizeof(dnsheader), query.size() - sizeof(dnsheader)); BOOST_CHECK(aroot.matches(raw)); - DNSName differentCase("A.RooT-Servers.NET"); + const DNSName differentCase("A.RooT-Servers.NET"); BOOST_CHECK(differentCase.matches(raw)); const DNSName broot("b.root-servers.net"); -- 2.47.3