DNSQuery.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2000-2003 Barak Weichselbaum <barak@komodia.com> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00017 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00018 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00019 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00020 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00021 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00022 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00023 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00024 * SUCH DAMAGE. 00025 * 00026 * Contact info: 00027 * ------------- 00028 * 00029 * Site: http://www.komodia.com 00030 * Main contact: barak@komodia.com 00031 * For custom projects, 00032 * consulting, or other 00033 * paid services: sales@komodia.com 00034 */ 00035 00036 #ifndef _DNSQuery_H_ 00037 #define _DNSQuery_H_ 00038 00039 #include "ErrorHandler.h" 00040 00041 #include <vector> 00042 00043 namespace KomodiaDNS 00044 { 00045 00046 // Header of the DNS question 00047 typedef struct _DnsQuestionHeader 00048 { 00049 std::string sName; // Variable 00050 unsigned short usType; // Too many fields 00051 unsigned short usClass; 00052 00053 } DnsQuestionHeader; 00054 00055 typedef DnsQuestionHeader FAR * LPDnsQuestionHeader; 00056 00057 #define DnsQuestionHeaderLength sizeof(DnsQuestionHeader) 00058 00059 #define DnsQuestionCopyHeader sizeof(unsigned short)*2 00060 00061 //Our DNS query class 00062 class CDNSQuery : public CErrorHandler 00063 { 00064 public: 00065 typedef enum _DnsQueryTypes 00066 { 00067 A=1, //a host address 00068 NS=2, //an authoritative name server 00069 MD=3, //a mail destination (Obsolete - use MX) 00070 MF=4, //a mail forwarder (Obsolete - use MX) 00071 CNAME=5, //the canonical name for an alias 00072 SOA=6, //marks the start of a zone of authority 00073 MB=7, //a mailbox domain name (EXPERIMENTAL) 00074 MG=8, //a mail group member (EXPERIMENTAL) 00075 MR=9, //a mail rename domain name (EXPERIMENTAL) 00076 NLL=10, //a null RR (EXPERIMENTAL) 00077 WKS=11, //a well known service description 00078 PTR=12, //a domain name pointer 00079 HINFO=13, //host information 00080 MINFO=14, //mailbox or mail list information 00081 MX=15, //mail exchange 00082 TXT=16, //text strings, 00083 ERR=17 //Internal error, not part of DNS 00084 } DNSQueryTypes; 00085 public: 00086 //Get a query 00087 const DnsQuestionHeader& GetQuery(int iIndex)const; 00088 00089 //Get teh query string 00090 std::string GetQueryString(int iIndex)const; 00091 00092 //Get queries count 00093 int GetQueryCount()const; 00094 00095 //Get the first query type (usually, for the answer parsing) 00096 DNSQueryTypes GetFirstQueryType()const; 00097 00098 //Parse a buffer 00099 int Parse(const char* pBuffer, 00100 int iNumber); 00101 00102 //How many question do we have 00103 unsigned short GetQuestionCount()const; 00104 00105 //Add a query to the DNS query 00106 void AddQuery(const std::string& rDomain, 00107 DNSQueryTypes aType); 00108 00109 //Get the serialization size 00110 unsigned short GetSerializationSize()const; 00111 00112 //Serialize the buffer 00113 unsigned short SerializeQuery(char* pBuffer)const; 00114 00115 //Copy operator 00116 CDNSQuery& operator=(const CDNSQuery& rQuery); 00117 00118 //Ctor and Dtor 00119 CDNSQuery(); 00120 CDNSQuery(const CDNSQuery& rQuery); 00121 virtual ~CDNSQuery(); 00122 private: 00123 //Our vector of questions 00124 typedef std::vector<DnsQuestionHeader> QueryVector; 00125 private: 00126 //The Query array 00127 QueryVector m_aQueries; 00128 }; 00129 00130 //of namespace 00131 } 00132 00133 #endif |