ClanLib  2.3.7
dns_packet.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 
31 
32 #pragma once
33 
34 #include "../api_network.h"
35 #include "../../Core/System/sharedptr.h"
36 #include "../../Core/Text/string_types.h"
37 
38 class CL_DataBuffer;
40 class CL_DNSPacket_Impl;
41 
46 {
49 
50 public:
51  CL_DNSPacket();
52 
56  CL_DNSPacket(const CL_DataBuffer &data);
57 
59  int query_id,
60  int opcode,
61  bool recursion_desired,
62  const CL_String &question_name,
63  int question_type,
64  int question_class);
65 
66  ~CL_DNSPacket();
67 
71 
72 public:
73  const CL_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  CL_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  CL_DNSResourceRecord get_answer(int index) const;
181 
187  CL_DNSResourceRecord get_nameserver(int index) const;
188 
194  CL_DNSResourceRecord get_additional(int index) const;
195 
199 
200 public:
201 
205  void set_data(const CL_DataBuffer &data);
206 
210  void set_query_id(unsigned short query_id);
211 
215 
216 private:
217  CL_SharedPtr<CL_DNSPacket_Impl> impl;
219 };
220