DwmDns-0.1.0
DwmDnsMessageQuestion.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/DwmDns/tags/DwmDns-0.1.0/classes/include/DwmDnsMessageQuestion.hh 10136 $
3 // @(#) $Id: DwmDnsMessageQuestion.hh 10136 2018-01-28 06:01:09Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2000, 2016, 2018
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMDNSMESSAGEQUESTION_HH_
43 #define _DWMDNSMESSAGEQUESTION_HH_
44 
45 #include <cstdint>
46 #include <string>
47 
48 #include "DwmDnsLabelPositions.hh"
49 
50 namespace Dwm {
51 
52  namespace Dns {
53 
54  //------------------------------------------------------------------------
58  //------------------------------------------------------------------------
60  {
61  public:
62  //----------------------------------------------------------------------
64  //----------------------------------------------------------------------
65  static constexpr uint16_t k_typeA = 1;
66  static constexpr uint16_t k_typeNS = 2;
67  static constexpr uint16_t k_typeCNAME = 5;
68  static constexpr uint16_t k_typeSOA = 6;
69  static constexpr uint16_t k_typeMB = 7;
70  static constexpr uint16_t k_typeMG = 8;
71  static constexpr uint16_t k_typeMR = 9;
72  static constexpr uint16_t k_typePTR = 12;
73  static constexpr uint16_t k_typeHINFO = 13;
74  static constexpr uint16_t k_typeMINFO = 14;
75  static constexpr uint16_t k_typeMX = 15;
76  static constexpr uint16_t k_typeTXT = 16;
77  static constexpr uint16_t k_typeRP = 17;
78  static constexpr uint16_t k_typeKEY = 25;
79  static constexpr uint16_t k_typeAAAA = 28;
80  static constexpr uint16_t k_typeLOC = 29;
81  static constexpr uint16_t k_typeSRV = 33;
82  static constexpr uint16_t k_typeCERT = 37;
83  static constexpr uint16_t k_typeDS = 43;
84  static constexpr uint16_t k_typeSSHFP = 44;
85  static constexpr uint16_t k_typeRRSIG = 46;
86  static constexpr uint16_t k_typeNSEC = 47;
87  static constexpr uint16_t k_typeDNSKEY = 48;
88  static constexpr uint16_t k_typeDHCID = 49;
89  static constexpr uint16_t k_typeNSEC3 = 50;
90  static constexpr uint16_t k_typeNSEC3PARAM = 51;
91  static constexpr uint16_t k_typeTLSA = 52;
92  static constexpr uint16_t k_typeSMIMEA = 53;
93  static constexpr uint16_t k_typeCDS = 59;
94  static constexpr uint16_t k_typeCDNSKEY = 60;
95  static constexpr uint16_t k_typeOPENPGPKEY = 61;
96  static constexpr uint16_t k_typeURI = 256;
97  static constexpr uint16_t k_typeCAA = 257;
98 
99  //----------------------------------------------------------------------
101  //----------------------------------------------------------------------
102  static constexpr uint16_t k_classIN = 1;
103  static constexpr uint16_t k_classCH = 3;
104  static constexpr uint16_t k_classHS = 4;
105  static constexpr uint16_t k_classANY = 255;
106  static constexpr uint16_t k_classUNKNOWN = 0xFFFF;
107 
108  //----------------------------------------------------------------------
110  //----------------------------------------------------------------------
111  MessageQuestion();
112 
113  //----------------------------------------------------------------------
116  //----------------------------------------------------------------------
117  MessageQuestion(const std::string & qname, uint16_t qtype,
118  uint16_t qclass);
119 
120  //----------------------------------------------------------------------
122  //----------------------------------------------------------------------
123  bool operator == (const MessageQuestion & question) const;
124 
125  //----------------------------------------------------------------------
127  //----------------------------------------------------------------------
128  const std::string & QName() const;
129 
130  //----------------------------------------------------------------------
132  //----------------------------------------------------------------------
133  const std::string & QName(const std::string & qname);
134 
135  //----------------------------------------------------------------------
137  //----------------------------------------------------------------------
138  uint16_t QType() const;
139 
140  //----------------------------------------------------------------------
142  //----------------------------------------------------------------------
143  uint16_t QType(uint16_t qtype);
144 
145  //----------------------------------------------------------------------
147  //----------------------------------------------------------------------
148  uint16_t QClass() const;
149 
150  //----------------------------------------------------------------------
152  //----------------------------------------------------------------------
153  uint16_t QClass(uint16_t qclass);
154 
155  //----------------------------------------------------------------------
161  //----------------------------------------------------------------------
162  uint8_t *Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen,
163  LabelPositions & lps) const;
164 
165  //----------------------------------------------------------------------
171  //----------------------------------------------------------------------
172  const uint8_t *Decode(const uint8_t *pkt, const uint8_t *ptr,
173  uint16_t pktlen);
174 
175  private:
176  std::string _qname;
177  uint16_t _qtype;
178  uint16_t _qclass;
179  };
180 
181  } // namespace Dns
182 
183 } // namespace Dwm
184 
185 #endif // _DWMDNSMESSAGEQUESTION_HH_
Dwm::Dns::LabelPositions class definition.
bool operator==(const MessageQuestion &question) const
Equal-to operator, mostly useful for unit testing.
static constexpr uint16_t k_typeA
Query types.
Definition: DwmDnsMessageQuestion.hh:65
MessageQuestion()
Constructs an empty question.
uint8_t * Encode(uint8_t *pkt, uint8_t *ptr, uint16_t pktlen, LabelPositions &lps) const
Encodes the question into buffer @ pkt of length pktlen, starting at ptr.
Encapsulates a DNS message question.
Definition: DwmDnsMessageQuestion.hh:59
Definition: DwmDnsEtcHosts.hh:60
const uint8_t * Decode(const uint8_t *pkt, const uint8_t *ptr, uint16_t pktlen)
Decodes the question from buffer pkt of length pktlen, starting at ptr.
static constexpr uint16_t k_classIN
Query classes.
Definition: DwmDnsMessageQuestion.hh:102
A helper class used when performing label sequence compression.
Definition: DwmDnsLabelPositions.hh:57
uint16_t QType() const
Returns the QTYPE of the question.
uint16_t QClass() const
Returns the QCLASS of the question.
const std::string & QName() const
Returns the QNAME from the question.