Async 1.8.0
Async::DnsResourceRecordPTR Class Reference

A class for representing a PTR DNS resource record. More...

#include <AsyncDnsResourceRecord.h>

Inheritance diagram for Async::DnsResourceRecordPTR:
Async::DnsResourceRecordCRTP< DnsResourceRecordPTR > Async::DnsResourceRecord Async::DnsResourceRecord

Public Types

using DName = std::string
 
- Public Types inherited from Async::DnsResourceRecordCRTP< DnsResourceRecordPTR >
using List
 The type for a list of resource records.
 
- Public Types inherited from Async::DnsResourceRecord
enum class  Type {
  ANY , A , PTR , CNAME ,
  SRV , A , PTR , CNAME ,
  SRV
}
 The record type. More...
 
enum class  Class { IN , IN }
 The record class. More...
 
enum class  Type {
  ANY , A , PTR , CNAME ,
  SRV , A , PTR , CNAME ,
  SRV
}
 
enum class  Class { IN , IN }
 
using Name = std::string
 
using Ttl = uint32_t
 
using List = std::vector<std::unique_ptr<DnsResourceRecord>>
 The type for a list of resource records.
 

Public Member Functions

 DnsResourceRecordPTR (const Name &name, Ttl ttl, const DName &dname="")
 Constructor.
 
virtual bool operator== (const DnsResourceRecordPTR &other) const
 Equality comparison operator.
 
virtual std::string toString (void) const
 The string representation of this record.
 
void setName (const DName &dname)
 Set the FQDN for this record.
 
const DNamedname (void) const
 The FQDN for this record.
 
 DnsResourceRecordPTR (const std::string &name, uint32_t ttl, const std::string &dname="")
 
 ~DnsResourceRecordPTR (void)
 
virtual const Type type (void) const
 The type of record.
 
virtual std::string toString (void) const
 The string representation of this record.
 
void setName (const std::string &dname)
 
const std::string & dname (void) const
 
- Public Member Functions inherited from Async::DnsResourceRecordCRTP< DnsResourceRecordPTR >
 DnsResourceRecordCRTP (const Name &name, Ttl ttl)
 Constructor.
 
virtual DnsResourceRecordclone (void) const
 Clone this class.
 
virtual bool operator== (const DnsResourceRecord &other) const
 Equality comparison operator.
 
- Public Member Functions inherited from Async::DnsResourceRecord
 DnsResourceRecord (const Name &name, Ttl ttl)
 Constructor.
 
virtual ~DnsResourceRecord (void)
 Destructor.
 
Class classId (void) const
 The DNS class for the record.
 
const char * classStr (void) const
 The DNS class for the record as a string.
 
const std::string & typeStr (void) const
 The type of record as a string.
 
void setName (const Name &name)
 Set the name for this record.
 
const Namename (void) const
 The name of this record.
 
void setTtl (Ttl ttl)
 Set the TTL for this record.
 
Ttl ttl (void) const
 The TTL for this record.
 
 DnsResourceRecord (const std::string &name, uint32_t ttl)
 Default constructor.
 
 DnsResourceRecord (const DnsResourceRecord &)=delete
 Disallow copy construction.
 
DnsResourceRecordoperator= (const DnsResourceRecord &)=delete
 Disallow copy assignment.
 
virtual ~DnsResourceRecord (void)
 Destructor.
 
Class classId (void) const
 A_brief_member_function_description.
 
const char * classStr (void) const
 
const std::string & typeStr (void) const
 
void setName (const std::string &name)
 
const std::string & name (void) const
 
void setTtl (uint32_t ttl)
 
uint32_t ttl (void) const
 

Static Public Member Functions

static const Type staticType (void)
 The type for this specific class.
 
static const Type staticType (void)
 
- Static Public Member Functions inherited from Async::DnsResourceRecord
static const Type staticType (void)
 The type for this specific class.
 
static const std::string & typeToString (Type type)
 The type for this specific class represented as a string.
 
static const std::string & typeToString (Type type)
 

Additional Inherited Members

- Static Public Attributes inherited from Async::DnsResourceRecord
static constexpr Ttl MAX_TTL = 0x7fffffff
 The maximum allowed value for a TTL.
 

Detailed Description

A class for representing a PTR DNS resource record.

Author
Tobias Blomberg / SM0SVX
Date
2021-05-22

This class represents a PTR DNS resource record. One or more resource records is the result of performing a DNS query. This specific resource record maps an IP address to hostnames.

#include <iostream>
#include <AsyncDnsLookup.h>
using namespace Async;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
dns.resultsReady.connect(mem_fun(*this, &MyClass::onResultsReady));
dns.lookup("www.svxlink.org");
//dns.lookup("www.svxlink.org", DnsLookup::Type::CNAME);
//dns.lookup("185.199.110.153");
//dns.lookup("185.199.110.153", DnsLookup::Type::PTR);
//dns.lookup("153.110.199.185.in-addr.arpa.", DnsLookup::Type::PTR);
//std::string srv = "_svxreflector._tcp.test.svxlink.org";
//dns.addStaticResourceRecord(
// new DnsResourceRecordSRV(srv, 3600, 15, 10, 5304, "localhost."));
//dns.lookup(srv, DnsLookup::Type::SRV);
std::cout << "Starting " << dns.typeStr() << " record query for \""
<< dns.label() << "\"..." << std::endl;
}
void onResultsReady(DnsLookup& dns)
{
if (!dns.lookupFailed())
{
// Simple IP address lookup API
std::cout << "IP addresses received:\n";
for (auto& addr : dns.addresses())
{
std::cout << addr << std::endl;
}
std::cout << std::endl;
// Access to all resource records
std::cout << "All resource records received:\n";
for (auto& rr : dns.resourceRecords())
{
std::cout << rr->toString() << std::endl;
}
std::cout << std::endl;
// Access A records with full detail
dns.resourceRecords(a_rrs);
if (!a_rrs.empty())
{
std::cout << "A records received:\n";
for (auto& rr : a_rrs)
{
std::cout << rr->name() << "\t" << rr->ttl() << "\t" << rr->ip()
<< std::endl;
}
std::cout << std::endl;
}
// Access PTR records with full detail
dns.resourceRecords(ptr_rrs);
if (!ptr_rrs.empty())
{
std::cout << "PTR records received:\n";
for (auto& rr : ptr_rrs)
{
std::cout << rr->name() << "\t" << rr->ttl() << "\t" << rr->dname()
<< std::endl;
}
std::cout << std::endl;
}
// Access CNAME records with full detail
dns.resourceRecords(cname_rrs);
if (!cname_rrs.empty())
{
std::cout << "CNAME records received:\n";
for (auto& rr : cname_rrs)
{
std::cout << rr->name() << "\t" << rr->ttl() << "\t" << rr->cname()
<< std::endl;
}
std::cout << std::endl;
}
// Access SRV records with full detail
dns.resourceRecords(srv_rrs);
if (!srv_rrs.empty())
{
std::cout << "SRV records received:\n";
for (auto& rr : srv_rrs)
{
std::cout << rr->name() << "\t" << rr->ttl() << "\t" << rr->prio()
<< " " << rr->weight() << " " << rr->port() << " "
<< rr->target() << std::endl;
}
}
}
else
{
std::cout << "*** ERROR: The " << dns.typeStr()
<< " record DNS lookup for " << dns.label()
<< " failed" << std::endl;
}
Application::app().quit();
}
private:
DnsLookup dns;
};
int main(int argc, char **argv)
{
MyClass dns;
app.exec();
}
The core class for writing asyncronous cpp applications.
Contains a class for executing DNS queries.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
A class for performing asynchronous DNS lookups.
DnsResourceRecord::List resourceRecords(Type type=Type::ANY) const
Return all matching resource records.
const std::string & label(void) const
Return the associated label.
std::string typeStr(void) const
Return the type of lookup as a string.
bool lookupFailed(void) const
Check if the lookup failed.
std::vector< IpAddress > addresses(void)
Return the addresses for the host in the query.
std::vector< std::unique_ptr< DnsResourceRecord > > List
The type for a list of resource records.
Namespace for the asynchronous programming classes.

Definition at line 223 of file AsyncResourceRecord.h.

Member Typedef Documentation

◆ DName

Definition at line 414 of file AsyncDnsResourceRecord.h.

Constructor & Destructor Documentation

◆ DnsResourceRecordPTR() [1/2]

Async::DnsResourceRecordPTR::DnsResourceRecordPTR ( const Name & name,
Ttl ttl,
const DName & dname = "" )
inline

Constructor.

Parameters
nameThe name of this record
ttlThe time-to-live, in seconds, for this record
dnameThe FQDN associaated with this record name

Definition at line 427 of file AsyncDnsResourceRecord.h.

◆ DnsResourceRecordPTR() [2/2]

Async::DnsResourceRecordPTR::DnsResourceRecordPTR ( const std::string & name,
uint32_t ttl,
const std::string & dname = "" )
inline

Definition at line 228 of file AsyncResourceRecord.h.

◆ ~DnsResourceRecordPTR()

Async::DnsResourceRecordPTR::~DnsResourceRecordPTR ( void )
inline

Definition at line 231 of file AsyncResourceRecord.h.

Member Function Documentation

◆ dname() [1/2]

const DName & Async::DnsResourceRecordPTR::dname ( void ) const
inline

The FQDN for this record.

Returns
Return the FQDN for this record

Definition at line 465 of file AsyncDnsResourceRecord.h.

Referenced by operator==(), setName(), setName(), and toString().

◆ dname() [2/2]

const std::string & Async::DnsResourceRecordPTR::dname ( void ) const
inline

Definition at line 242 of file AsyncResourceRecord.h.

◆ operator==()

virtual bool Async::DnsResourceRecordPTR::operator== ( const DnsResourceRecordPTR & other) const
inlinevirtual

Equality comparison operator.

Parameters
otherThe other resource record to comapare to
Returns
Return true if the two records are equal

NOTE: The TTL is not used in the comparison.

Implements Async::DnsResourceRecordCRTP< DnsResourceRecordPTR >.

Definition at line 438 of file AsyncDnsResourceRecord.h.

References dname(), and Async::DnsResourceRecord::operator==().

◆ setName() [1/2]

void Async::DnsResourceRecordPTR::setName ( const DName & dname)
inline

Set the FQDN for this record.

Parameters
dnameThe new FQDN for this record

Definition at line 459 of file AsyncDnsResourceRecord.h.

References dname().

◆ setName() [2/2]

void Async::DnsResourceRecordPTR::setName ( const std::string & dname)
inline

Definition at line 241 of file AsyncResourceRecord.h.

References dname().

◆ staticType() [1/2]

static const Type Async::DnsResourceRecordPTR::staticType ( void )
inlinestatic

The type for this specific class.

Definition at line 419 of file AsyncDnsResourceRecord.h.

References Async::DnsResourceRecord::PTR.

Referenced by type().

◆ staticType() [2/2]

static const Type Async::DnsResourceRecordPTR::staticType ( void )
inlinestatic

Definition at line 226 of file AsyncResourceRecord.h.

References Async::DnsResourceRecord::PTR.

◆ toString() [1/2]

virtual std::string Async::DnsResourceRecordPTR::toString ( void ) const
inlinevirtual

The string representation of this record.

Returns
Return the string representation of this record

Reimplemented from Async::DnsResourceRecord.

Definition at line 448 of file AsyncDnsResourceRecord.h.

References dname(), and Async::DnsResourceRecord::toString().

◆ toString() [2/2]

virtual std::string Async::DnsResourceRecordPTR::toString ( void ) const
inlinevirtual

The string representation of this record.

Returns
Return the string representation of this record

Reimplemented from Async::DnsResourceRecord.

Definition at line 234 of file AsyncResourceRecord.h.

References dname(), and Async::DnsResourceRecord::toString().

◆ type()

virtual const Type Async::DnsResourceRecordPTR::type ( void ) const
inlinevirtual

The type of record.

Returns
Return the type of this record

Reimplemented from Async::DnsResourceRecordCRTP< DnsResourceRecordPTR >.

Definition at line 233 of file AsyncResourceRecord.h.

References staticType().


The documentation for this class was generated from the following files: