dns_packet.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include "../api_network.h"
33 #include <memory>
34 
35 namespace clan
36 {
39 
40 class DataBuffer;
41 class DNSResourceRecord;
42 class DNSPacket_Impl;
43 
45 class CL_API_NETWORK DNSPacket
46 {
49 
50 public:
51  DNSPacket();
52 
56  DNSPacket(const DataBuffer &data);
57 
58  DNSPacket(
59  int query_id,
60  int opcode,
61  bool recursion_desired,
62  const std::string &question_name,
63  int question_type,
64  int question_class);
65 
66  ~DNSPacket();
67 
71 
72 public:
73  const DataBuffer &get_data() const;
74 
75  unsigned short get_query_id() const;
76 
80  bool is_query() const;
81 
85  bool is_response() const;
86 
87  enum Opcode
88  {
89  opcode_query = 0,
90  opcode_inverse_query = 1,
91  opcode_status = 2
92  };
93 
97  int get_opcode() const;
98 
102  bool is_authoriative_answer() const;
103 
107  bool is_truncated() const;
108 
112  bool is_recursion_desired() const;
113 
117  bool is_recursion_available() const;
118 
120  {
121  response_ok = 0,
122  response_format_error = 1,
123  response_server_failure = 2,
124  response_name_error = 3,
125  response_not_implemented = 4,
126  response_refused = 5
127  };
128 
132  int get_response_code() const;
133 
137  int get_question_count() const;
138 
142  int get_answer_count() const;
143 
147  int get_nameserver_count() const;
148 
152  int get_additional_count() const;
153 
159  std::string get_question_name(int index) const;
160 
166  int get_question_type(int index) const;
167 
173  int get_question_class(int index) const;
174 
180  DNSResourceRecord get_answer(int index) const;
181 
187  DNSResourceRecord get_nameserver(int index) const;
188 
194  DNSResourceRecord get_additional(int index) const;
195 
199 
200 public:
201 
205  void set_data(const DataBuffer &data);
206 
210  void set_query_id(unsigned short query_id);
211 
215 
216 private:
217  std::shared_ptr<DNSPacket_Impl> impl;
219 };
220 
221 }
222 
ResponseCode
Definition: dns_packet.h:119
Opcode
Definition: dns_packet.h:87
DNS packet.
Definition: dns_packet.h:45
General purpose data buffer.
Definition: databuffer.h:43
DNS resource record.
Definition: dns_resource_record.h:45