E-MailRelay
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
GNet::DnsMessage Class Reference

A DNS message parser, with static factory functions for message composition. More...

#include <gdnsmessage.h>

Public Types

using Question = DnsMessageQuestion
 
using RR = DnsMessageRR
 

Public Member Functions

 DnsMessage (const std::vector< char > &buffer)
 Constructor. More...
 
 DnsMessage (const char *, std::size_t)
 Constructor. More...
 
std::vector< Addressaddresses () const
 Returns the Answer addresses. More...
 
unsigned int ID () const
 Returns the header ID. More...
 
bool QR () const
 Returns the header QR (query/response). More...
 
unsigned int OPCODE () const
 Returns the header OPCODE. More...
 
bool AA () const
 Returns the header AA flag (authorative). More...
 
bool TC () const
 Returns the header TC flag (truncated). More...
 
bool RD () const
 Returns the header RD (recursion desired). More...
 
bool RA () const
 Returns the header RA (recursion available). More...
 
unsigned int Z () const
 Returns the header Z value (zero). More...
 
unsigned int RCODE () const
 Returns the header RCODE. More...
 
unsigned int QDCOUNT () const
 Returns the header QDCOUNT field, ie. More...
 
unsigned int ANCOUNT () const
 Returns the header ANCOUNT field, ie. More...
 
unsigned int NSCOUNT () const
 Returns the header NSCOUNT field, ie. More...
 
unsigned int ARCOUNT () const
 Returns the header ARCOUNT field, ie. More...
 
Question question (unsigned int n) const
 Returns the n'th record as a Question record. More...
 
RR rr (unsigned int n) const
 Returns the n'th record as a RR record. More...
 
Address rrAddress (unsigned int n) const
 Returns the address in the n'th record treated as a RR record. More...
 
const char * p () const
 Returns the raw data. More...
 
std::size_t n () const
 Returns the raw data size. More...
 
unsigned int byte (unsigned int byte_index) const
 Returns byte at the given offset. More...
 
unsigned int word (unsigned int byte_index) const
 Returns word at the given byte offset. More...
 
std::string span (unsigned int begin, unsigned int end) const
 Returns the data in the given half-open byte range. More...
 

Static Public Member Functions

static DnsMessage request (const std::string &type, const std::string &hostname, unsigned int id=0U)
 Factory function for a request message of the give type ("A", "AAAA", etc). More...
 
static DnsMessage rejection (const DnsMessage &request, unsigned int rcode)
 Factory function for a failure response based on the given request message. More...
 
static DnsMessage empty ()
 Factory function for an unusable object. More...
 

Friends

class DnsMessageDumper
 

Detailed Description

A DNS message parser, with static factory functions for message composition.

A DnsMessage contains a Header and four sections: Question, Answer, Authority and Additional. The Question section contains Question records (DnsMessageQuestion) while the Answer, Authority and Additional sections contain RR records (DnsMessageRR). Each RR has a standard header followed by RDATA.

See also
RFC-1035

Definition at line 51 of file gdnsmessage.h.

Member Typedef Documentation

◆ Question

Definition at line 55 of file gdnsmessage.h.

◆ RR

Definition at line 56 of file gdnsmessage.h.

Constructor & Destructor Documentation

◆ DnsMessage() [1/2]

GNet::DnsMessage::DnsMessage ( const std::vector< char > &  buffer)
explicit

Constructor.

Definition at line 93 of file gdnsmessage.cpp.

◆ DnsMessage() [2/2]

GNet::DnsMessage::DnsMessage ( const char *  p,
std::size_t  n 
)

Constructor.

Definition at line 100 of file gdnsmessage.cpp.

Member Function Documentation

◆ AA()

bool GNet::DnsMessage::AA ( ) const

Returns the header AA flag (authorative).

Definition at line 169 of file gdnsmessage.cpp.

◆ addresses()

std::vector< GNet::Address > GNet::DnsMessage::addresses ( ) const

Returns the Answer addresses.

Definition at line 126 of file gdnsmessage.cpp.

◆ ANCOUNT()

unsigned int GNet::DnsMessage::ANCOUNT ( ) const

Returns the header ANCOUNT field, ie.

the number of RR records in the Answer section.

Definition at line 204 of file gdnsmessage.cpp.

◆ ARCOUNT()

unsigned int GNet::DnsMessage::ARCOUNT ( ) const

Returns the header ARCOUNT field, ie.

the number of RR records in the Additional section.

Definition at line 214 of file gdnsmessage.cpp.

◆ byte()

unsigned int GNet::DnsMessage::byte ( unsigned int  byte_index) const

Returns byte at the given offset.

Definition at line 136 of file gdnsmessage.cpp.

◆ empty()

GNet::DnsMessage GNet::DnsMessage::empty ( )
static

Factory function for an unusable object.

Most methods will throw, except n() will return zero.

Definition at line 115 of file gdnsmessage.cpp.

◆ ID()

unsigned int GNet::DnsMessage::ID ( ) const

Returns the header ID.

Definition at line 154 of file gdnsmessage.cpp.

◆ n()

std::size_t GNet::DnsMessage::n ( ) const

Returns the raw data size.

Definition at line 110 of file gdnsmessage.cpp.

◆ NSCOUNT()

unsigned int GNet::DnsMessage::NSCOUNT ( ) const

Returns the header NSCOUNT field, ie.

the number of RR records in the Authority section.

Definition at line 209 of file gdnsmessage.cpp.

◆ OPCODE()

unsigned int GNet::DnsMessage::OPCODE ( ) const

Returns the header OPCODE.

Definition at line 164 of file gdnsmessage.cpp.

◆ p()

const char * GNet::DnsMessage::p ( ) const

Returns the raw data.

Definition at line 105 of file gdnsmessage.cpp.

◆ QDCOUNT()

unsigned int GNet::DnsMessage::QDCOUNT ( ) const

Returns the header QDCOUNT field, ie.

the number of records in the Question section.

Definition at line 199 of file gdnsmessage.cpp.

◆ QR()

bool GNet::DnsMessage::QR ( ) const

Returns the header QR (query/response).

Definition at line 159 of file gdnsmessage.cpp.

◆ question()

GNet::DnsMessageQuestion GNet::DnsMessage::question ( unsigned int  n) const

Returns the n'th record as a Question record.

Precondition: n < QDCOUNT()

Definition at line 244 of file gdnsmessage.cpp.

◆ RA()

bool GNet::DnsMessage::RA ( ) const

Returns the header RA (recursion available).

Definition at line 184 of file gdnsmessage.cpp.

◆ RCODE()

unsigned int GNet::DnsMessage::RCODE ( ) const

Returns the header RCODE.

Definition at line 194 of file gdnsmessage.cpp.

◆ RD()

bool GNet::DnsMessage::RD ( ) const

Returns the header RD (recursion desired).

Definition at line 179 of file gdnsmessage.cpp.

◆ rejection()

GNet::DnsMessage GNet::DnsMessage::rejection ( const DnsMessage request,
unsigned int  rcode 
)
static

Factory function for a failure response based on the given request message.

Definition at line 219 of file gdnsmessage.cpp.

◆ request()

GNet::DnsMessage GNet::DnsMessage::request ( const std::string &  type,
const std::string &  hostname,
unsigned int  id = 0U 
)
static

Factory function for a request message of the give type ("A", "AAAA", etc).

The type name is interpreted by DnsMessageRecordType::value().

Definition at line 120 of file gdnsmessage.cpp.

◆ rr()

GNet::DnsMessageRR GNet::DnsMessage::rr ( unsigned int  n) const

Returns the n'th record as a RR record.

The returned object retains a reference to this DnsMessage, so prefer rrAddress(). Precondition: n >= QDCOUNT() && n < (QDCOUNT()+ANCOUNT()+NSCOUNT()+ARCOUNT())

Definition at line 253 of file gdnsmessage.cpp.

◆ rrAddress()

GNet::Address GNet::DnsMessage::rrAddress ( unsigned int  n) const

Returns the address in the n'th record treated as a RR record.

Definition at line 267 of file gdnsmessage.cpp.

◆ span()

std::string GNet::DnsMessage::span ( unsigned int  begin,
unsigned int  end 
) const

Returns the data in the given half-open byte range.

Definition at line 147 of file gdnsmessage.cpp.

◆ TC()

bool GNet::DnsMessage::TC ( ) const

Returns the header TC flag (truncated).

Definition at line 174 of file gdnsmessage.cpp.

◆ word()

unsigned int GNet::DnsMessage::word ( unsigned int  byte_index) const

Returns word at the given byte offset.

Definition at line 142 of file gdnsmessage.cpp.

◆ Z()

unsigned int GNet::DnsMessage::Z ( ) const

Returns the header Z value (zero).

Definition at line 189 of file gdnsmessage.cpp.

Friends And Related Function Documentation

◆ DnsMessageDumper

friend class DnsMessageDumper
friend

Definition at line 152 of file gdnsmessage.h.


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