21#ifndef G_NET_DNS_MESSAGE_H
22#define G_NET_DNS_MESSAGE_H
36 class DnsMessageRecordType ;
37 class DnsMessageQuestion ;
38 class DnsMessageNameParser ;
39 class DnsMessageRequest ;
40 class DnsMessageDumper ;
54 G_EXCEPTION( Error ,
"dns message error" ) ;
58 explicit DnsMessage(
const std::vector<char> & buffer ) ;
67 unsigned int ID()
const ;
73 unsigned int OPCODE()
const ;
88 unsigned int Z()
const ;
91 unsigned int RCODE()
const ;
114 RR rr(
unsigned int n )
const ;
123 const char *
p()
const ;
126 std::size_t
n()
const ;
129 unsigned int byte(
unsigned int byte_index )
const ;
132 unsigned int word(
unsigned int byte_index )
const ;
135 std::string
span(
unsigned int begin ,
unsigned int end )
const ;
152 friend class DnsMessageDumper ;
154 void reject(
unsigned int rcode ) ;
157 std::vector<char> m_buffer ;
167 static unsigned int value(
const std::string & type_name ) ;
170 static std::string
name(
unsigned int type_value ) ;
190 bool isa(
const std::string & )
const ;
193 unsigned int type()
const ;
196 unsigned int size()
const ;
199 std::string
name()
const ;
206 friend class DnsMessageDumper ;
207 std::string rdata_dname(
unsigned int rdata_offset )
const ;
208 std::string rdata_dname(
unsigned int * rdata_offset_p )
const ;
209 std::string rdata_span(
unsigned int begin )
const ;
210 std::string rdata_span(
unsigned int begin ,
unsigned int end )
const ;
211 unsigned int rdata_offset()
const ;
212 unsigned int rdata_size()
const ;
213 unsigned int rdata_byte(
unsigned int offset )
const ;
214 unsigned int rdata_word(
unsigned int offset )
const ;
218 unsigned int m_offset ;
219 unsigned int m_size ;
220 unsigned int m_type ;
221 unsigned int m_class ;
222 unsigned int m_rdata_offset ;
223 unsigned int m_rdata_size ;
236 unsigned int size()
const ;
239 std::string
qname()
const ;
243 unsigned int m_size ;
244 std::string m_qname ;
254 static unsigned int size(
const DnsMessage & msg ,
unsigned int ) ;
257 static std::string
read(
const DnsMessage & msg ,
unsigned int ) ;
276 const char *
p()
const ;
279 std::size_t
n()
const ;
283 void q(
const std::string & domain ,
char ) ;
284 void q(
const std::string & ) ;
285 void q(
unsigned int ) ;
The GNet::Address class encapsulates a TCP/UDP transport address.
An implementation class used by GNet::DnsMessage to parse compressed domain names.
static unsigned int size(const DnsMessage &msg, unsigned int)
Returns the size of the compressed name.
static std::string read(const DnsMessage &msg, unsigned int)
Returns the decompressed name, made up of the labels with dots inbetween.
Represents DNS question record.
DnsMessageQuestion(const DnsMessage &, unsigned int offset)
Constructor.
std::string qname() const
Returns the subject of the question.
unsigned int size() const
Returns the record size.
Represents DNS response record.
unsigned int type() const
Returns the type value().
DnsMessageRR(const DnsMessage &, unsigned int offset)
Constructor.
Address address() const
Returns the Address if isa(A) or isa(AAAA).
unsigned int size() const
Returns the size.
bool isa(const std::string &) const
Returns true if the type() has the given name().
std::string name() const
Returns the NAME.
A static class for mapping between a RR type name, such as "AAAA", and its corresponding numeric valu...
static std::string name(unsigned int type_value)
Returns the type name for the given type value.
static unsigned int value(const std::string &type_name)
Returns the type value for the given type name.
Represents a DNS query message.
std::size_t n() const
Returns message size.
const char * p() const
Returns a pointer to the message data.
DnsMessageRequest(const std::string &type, const std::string &hostname, unsigned int id=0U)
Constructor.
A DNS message parser, with static factory functions for message composition.
Address rrAddress(unsigned int n) const
Returns the address in the n'th record treated as a RR record.
unsigned int ANCOUNT() const
Returns the header ANCOUNT field, ie.
Question question(unsigned int n) const
Returns the n'th record as a Question record.
unsigned int RCODE() const
Returns the header RCODE.
bool QR() const
Returns the header QR (query/response).
unsigned int Z() const
Returns the header Z value (zero).
unsigned int QDCOUNT() const
Returns the header QDCOUNT field, ie.
std::size_t n() const
Returns the raw data size.
unsigned int NSCOUNT() const
Returns the header NSCOUNT field, ie.
unsigned int ARCOUNT() const
Returns the header ARCOUNT field, ie.
bool AA() const
Returns the header AA flag (authorative).
const char * p() const
Returns the raw data.
unsigned int OPCODE() const
Returns the header OPCODE.
static DnsMessage rejection(const DnsMessage &request, unsigned int rcode)
Factory function for a failure response based on the given request message.
bool TC() const
Returns the header TC flag (truncated).
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).
std::string span(unsigned int begin, unsigned int end) const
Returns the data in the given half-open byte range.
unsigned int byte(unsigned int byte_index) const
Returns byte at the given offset.
std::vector< Address > addresses() const
Returns the Answer addresses.
bool RD() const
Returns the header RD (recursion desired).
static DnsMessage empty()
Factory function for an unusable object.
unsigned int ID() const
Returns the header ID.
bool RA() const
Returns the header RA (recursion available).
RR rr(unsigned int n) const
Returns the n'th record as a RR record.
unsigned int word(unsigned int byte_index) const
Returns word at the given byte offset.
std::string hostname()
Returns the hostname.