Async 1.8.0
Async::DnsResourceRecord Class Referenceabstract

The base class for representing a DNS resource record. More...

#include <AsyncDnsResourceRecord.h>

Inheritance diagram for Async::DnsResourceRecord:
Async::DnsResourceRecordCRTP< DnsResourceRecordA > Async::DnsResourceRecordCRTP< DnsResourceRecordCNAME > Async::DnsResourceRecordCRTP< DnsResourceRecordPTR > Async::DnsResourceRecordCRTP< DnsResourceRecordSRV > Async::DnsResourceRecordA Async::DnsResourceRecordCNAME Async::DnsResourceRecordCRTP< Derived > Async::DnsResourceRecordPTR Async::DnsResourceRecordSRV

Public Types

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

 DnsResourceRecord (const Name &name, Ttl ttl)
 Constructor.
 
virtual ~DnsResourceRecord (void)
 Destructor.
 
virtual DnsResourceRecordclone (void) const =0
 Clone this class.
 
virtual bool operator== (const DnsResourceRecord &other) const
 Equality comparison operator.
 
Class classId (void) const
 The DNS class for the record.
 
const char * classStr (void) const
 The DNS class for the record as a string.
 
virtual const Type type (void) const =0
 The type of record.
 
const std::string & typeStr (void) const
 The type of record as a string.
 
virtual std::string toString (void) const
 The string representation of this record.
 
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
 
virtual const Type type (void) const =0
 
const std::string & typeStr (void) const
 
virtual std::string toString (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 std::string & typeToString (Type type)
 The type for this specific class represented as a string.
 
static const std::string & typeToString (Type type)
 

Static Public Attributes

static constexpr Ttl MAX_TTL = 0x7fffffff
 The maximum allowed value for a TTL.
 

Detailed Description

The base class for representing a DNS resource record.

A_brief_class_description.

Author
Tobias Blomberg / SM0SVX
Date
2021-05-22

This is the base class for representing a DNS resource record. One or more resource records is the result of performing a DNS query.

#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.
Author
Tobias Blomberg / SM0SVX
Date
2021-05-22

A_detailed_class_description

#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();
}

Definition at line 120 of file AsyncResourceRecord.h.

Member Typedef Documentation

◆ List

using Async::DnsResourceRecord::List = std::vector<std::unique_ptr<DnsResourceRecord>>

The type for a list of resource records.

Definition at line 138 of file AsyncDnsResourceRecord.h.

◆ Name

using Async::DnsResourceRecord::Name = std::string

Definition at line 122 of file AsyncDnsResourceRecord.h.

◆ Ttl

Definition at line 123 of file AsyncDnsResourceRecord.h.

Member Enumeration Documentation

◆ Class [1/2]

The record class.

Enumerator
IN 
IN 

Definition at line 133 of file AsyncDnsResourceRecord.h.

◆ Class [2/2]

Enumerator
IN 
IN 

Definition at line 124 of file AsyncResourceRecord.h.

◆ Type [1/2]

enum class Async::DnsResourceRecord::Type
strong

The record type.

Enumerator
ANY 
PTR 
CNAME 
SRV 
PTR 
CNAME 
SRV 

Definition at line 128 of file AsyncDnsResourceRecord.h.

◆ Type [2/2]

enum class Async::DnsResourceRecord::Type
strong
Enumerator
ANY 
PTR 
CNAME 
SRV 
PTR 
CNAME 
SRV 

Definition at line 123 of file AsyncResourceRecord.h.

Constructor & Destructor Documentation

◆ DnsResourceRecord() [1/3]

Async::DnsResourceRecord::DnsResourceRecord ( const Name & name,
Ttl ttl )
inline

Constructor.

Parameters
nameThe name of this record
ttlThe time-to-live, in seconds, for this record

Definition at line 173 of file AsyncDnsResourceRecord.h.

◆ ~DnsResourceRecord() [1/2]

virtual Async::DnsResourceRecord::~DnsResourceRecord ( void )
inlinevirtual

Destructor.

Definition at line 179 of file AsyncDnsResourceRecord.h.

◆ DnsResourceRecord() [2/3]

Async::DnsResourceRecord::DnsResourceRecord ( const std::string & name,
uint32_t ttl )
inline

Default constructor.

Definition at line 144 of file AsyncResourceRecord.h.

◆ DnsResourceRecord() [3/3]

Async::DnsResourceRecord::DnsResourceRecord ( const DnsResourceRecord & )
delete

Disallow copy construction.

◆ ~DnsResourceRecord() [2/2]

virtual Async::DnsResourceRecord::~DnsResourceRecord ( void )
inlinevirtual

Destructor.

Definition at line 160 of file AsyncResourceRecord.h.

Member Function Documentation

◆ classId() [1/2]

Class Async::DnsResourceRecord::classId ( void ) const
inline

The DNS class for the record.

Returns
Return the DNS class for the record

Definition at line 205 of file AsyncDnsResourceRecord.h.

References IN.

Referenced by operator==().

◆ classId() [2/2]

Class Async::DnsResourceRecord::classId ( void ) const
inline

A_brief_member_function_description.

Parameters
param1Description_of_param1
Returns
Return_value_of_this_member_function

Definition at line 167 of file AsyncResourceRecord.h.

References IN.

◆ classStr() [1/2]

const char * Async::DnsResourceRecord::classStr ( void ) const
inline

The DNS class for the record as a string.

Returns
Return the DNS class as a string for this record

Definition at line 211 of file AsyncDnsResourceRecord.h.

Referenced by toString().

◆ classStr() [2/2]

const char * Async::DnsResourceRecord::classStr ( void ) const
inline

Definition at line 168 of file AsyncResourceRecord.h.

◆ clone()

◆ name() [1/2]

const Name & Async::DnsResourceRecord::name ( void ) const
inline

The name of this record.

Returns
Return the name of this record

Definition at line 250 of file AsyncDnsResourceRecord.h.

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

◆ name() [2/2]

const std::string & Async::DnsResourceRecord::name ( void ) const
inline

Definition at line 185 of file AsyncResourceRecord.h.

◆ operator=()

DnsResourceRecord & Async::DnsResourceRecord::operator= ( const DnsResourceRecord & )
delete

Disallow copy assignment.

◆ operator==()

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

◆ setName() [1/2]

void Async::DnsResourceRecord::setName ( const Name & name)
inline

Set the name for this record.

Parameters
namethe new name of the record

Definition at line 244 of file AsyncDnsResourceRecord.h.

References name().

◆ setName() [2/2]

void Async::DnsResourceRecord::setName ( const std::string & name)
inline

Definition at line 184 of file AsyncResourceRecord.h.

References name().

◆ setTtl() [1/2]

void Async::DnsResourceRecord::setTtl ( Ttl ttl)
inline

Set the TTL for this record.

Parameters
ttlThe time-to-live, in seconds, for this record

Definition at line 256 of file AsyncDnsResourceRecord.h.

References ttl().

◆ setTtl() [2/2]

void Async::DnsResourceRecord::setTtl ( uint32_t ttl)
inline

Definition at line 187 of file AsyncResourceRecord.h.

References ttl().

◆ staticType()

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

The type for this specific class.

Definition at line 148 of file AsyncDnsResourceRecord.h.

References ANY.

◆ toString() [1/2]

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

◆ toString() [2/2]

◆ ttl() [1/2]

Ttl Async::DnsResourceRecord::ttl ( void ) const
inline

The TTL for this record.

Returns
Return the time-to-live, in seconds, for this record

Definition at line 262 of file AsyncDnsResourceRecord.h.

Referenced by setTtl(), setTtl(), and toString().

◆ ttl() [2/2]

uint32_t Async::DnsResourceRecord::ttl ( void ) const
inline

Definition at line 188 of file AsyncResourceRecord.h.

◆ type() [1/2]

◆ type() [2/2]

◆ typeStr() [1/2]

const std::string & Async::DnsResourceRecord::typeStr ( void ) const
inline

The type of record as a string.

Returns
Return the type of this record as a string

Definition at line 223 of file AsyncDnsResourceRecord.h.

References type(), and typeToString().

Referenced by toString().

◆ typeStr() [2/2]

const std::string & Async::DnsResourceRecord::typeStr ( void ) const
inline

Definition at line 171 of file AsyncResourceRecord.h.

References type(), and typeToString().

◆ typeToString() [1/2]

static const std::string & Async::DnsResourceRecord::typeToString ( Type type)
inlinestatic

The type for this specific class represented as a string.

Definition at line 153 of file AsyncDnsResourceRecord.h.

References A, CNAME, PTR, SRV, and type().

Referenced by Async::DnsLookup::typeStr(), and typeStr().

◆ typeToString() [2/2]

static const std::string & Async::DnsResourceRecord::typeToString ( Type type)
inlinestatic

Definition at line 126 of file AsyncResourceRecord.h.

References A, CNAME, PTR, SRV, and type().

Member Data Documentation

◆ MAX_TTL

Ttl Async::DnsResourceRecord::MAX_TTL = 0x7fffffff
staticconstexpr

The maximum allowed value for a TTL.

Definition at line 143 of file AsyncDnsResourceRecord.h.


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