From 41e015928a0446979cd1da49eb4a26da4a694f12 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Fri, 31 Mar 2017 14:55:20 +0200 Subject: [PATCH] DNSName: add getLastLabel() function --- pdns/dnsname.cc | 7 +++++++ pdns/dnsname.hh | 1 + 2 files changed, 8 insertions(+) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 3f98d8487..ac93e2d51 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -340,6 +340,13 @@ std::string DNSName::getRawLabel(unsigned int pos) const throw std::out_of_range("trying to get label at position "+std::to_string(pos)+" of a DNSName that only has "+std::to_string(currentPos)+" labels"); } +DNSName DNSName::getLastLabel() const +{ + DNSName ret(*this); + ret.trimToLabels(1); + return ret; +} + bool DNSName::chopOff() { if(d_storage.empty() || d_storage[0]==0) diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index eba45665c..4caf7438f 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -83,6 +83,7 @@ public: void prependRawLabel(const std::string& str); //!< Prepend this unescaped label std::vector getRawLabels() const; //!< Individual raw unescaped labels std::string getRawLabel(unsigned int pos) const; //!< Get the specified raw unescaped label + DNSName getLastLabel() const; //!< Get the DNSName of the last label bool chopOff(); //!< Turn www.powerdns.com. into powerdns.com., returns false for . DNSName makeRelative(const DNSName& zone) const; DNSName makeLowerCase() const -- 2.50.0