dns_packet.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_network.h"
00035 #include "../../Core/System/sharedptr.h"
00036 #include "../../Core/Text/string_types.h"
00037 
00038 class CL_DataBuffer;
00039 class CL_DNSResourceRecord;
00040 class CL_DNSPacket_Impl;
00041 
00045 class CL_API_NETWORK CL_DNSPacket
00046 {
00049 
00050 public:
00051         CL_DNSPacket();
00052 
00056         CL_DNSPacket(const CL_DataBuffer &data);
00057 
00058         CL_DNSPacket(
00059                 int query_id,
00060                 int opcode,
00061                 bool recursion_desired,
00062                 const CL_String &question_name,
00063                 int question_type,
00064                 int question_class);
00065 
00066         ~CL_DNSPacket();
00067 
00071 
00072 public:
00073         const CL_DataBuffer &get_data() const;
00074 
00075         unsigned short get_query_id() const;
00076 
00080         bool is_query() const;
00081 
00085         bool is_response() const;
00086 
00087         enum Opcode
00088         {
00089                 opcode_query          = 0,
00090                 opcode_inverse_query  = 1,
00091                 opcode_status         = 2
00092         };
00093 
00097         int get_opcode() const;
00098 
00102         bool is_authoriative_answer() const;
00103 
00107         bool is_truncated() const;
00108 
00112         bool is_recursion_desired() const;
00113 
00117         bool is_recursion_available() const;
00118 
00119         enum ResponseCode
00120         {
00121                 response_ok               = 0,
00122                 response_format_error     = 1,
00123                 response_server_failure   = 2,
00124                 response_name_error       = 3,
00125                 response_not_implemented  = 4,
00126                 response_refused          = 5
00127         };
00128 
00132         int get_response_code() const;
00133 
00137         int get_question_count() const;
00138 
00142         int get_answer_count() const;
00143 
00147         int get_nameserver_count() const;
00148 
00152         int get_additional_count() const;
00153 
00159         CL_String get_question_name(int index) const;
00160 
00166         int get_question_type(int index) const;
00167 
00173         int get_question_class(int index) const;
00174 
00180         CL_DNSResourceRecord get_answer(int index) const;
00181 
00187         CL_DNSResourceRecord get_nameserver(int index) const;
00188 
00194         CL_DNSResourceRecord get_additional(int index) const;
00195 
00199 
00200 public:
00201 
00205         void set_data(const CL_DataBuffer &data);
00206 
00210         void set_query_id(unsigned short query_id);
00211 
00215 
00216 private:
00217         CL_SharedPtr<CL_DNSPacket_Impl> impl;
00219 };
00220