26 #define LABEL_LENGTH(a) ((int)(((a[0] & 0xc0) == 0) ? a[0] & 0x3f : -1))
27 #define LABEL_OFFSET(a) ((int)(((a[0] & 0xc0) == 0xc0) ? ((a[0] & 0x3f) << 8) + a[1] : -1))
28 #define GET_INT16(a,b) ((((int)(a[b])) << 8) + (int)a[b+1])
29 #define GET_INT32(a,b) ((((int)a[b]) << 24) + (((int)a[b+1]) << 16) + (((int)a[b+2]) << 8) + ((int)a[b+3]))
41 MessageBuffer(
unsigned char *data,
int len )
46 MessageBuffer &setData(
unsigned char *data,
int len )
55 unsigned char *getPointer() {
return m_ofs >= m_len ? NULL : m_data + m_ofs; }
56 unsigned char *getPointer(
int ofs ) {
return ofs >= m_len ? NULL : m_data + ofs; }
57 bool validateLength(
int ofs,
int len ) {
return (ofs + len) >= m_len ? false :
true; }
59 int incrementOffset(
int len ) {
return m_ofs = m_ofs + len > m_len ? m_len : m_ofs + len; }
60 int getOffset() {
return m_ofs; }
61 int setOffset(
int ofs ) {
return m_ofs = ofs; }
62 int calculateOffset(
unsigned char *ptr ) {
return (
int)(ptr - m_data); }
64 bool isValid() {
return m_data && m_len > 0; }
68 unsigned char * m_data;
76 Parser(
QueryPtr &q,
unsigned char *rdata,
int rlen );
83 Question* parseQuestion();
84 ResourceRecord* parseResourceRecord();
85 ResourceRecord* parseRR();
86 ResourceRecord* parseA();
87 ResourceRecord* parseNS();
88 ResourceRecord* parseCNAME();
89 ResourceRecord* parseAAAA();
90 ResourceRecord* parseSRV();
91 ResourceRecord* parseNAPTR();
94 void parseDomainName(
EString &dn );
95 void parseCharacterString(
EString &cs );
110 unsigned char *m_rdata;
113 static const int HDR_FIXED_SIZE = 12;
114 static const int HDR_QDCOUNT_OFS = 4;
115 static const int HDR_ANCOUNT_OFS = 6;
116 static const int HDR_NSCOUNT_OFS = 8;
117 static const int HDR_ARCOUNT_OFS = 10;
119 static const int Q_FIXED_SIZE = 4;
120 static const int Q_QTYPE_OFS = 0;
121 static const int Q_QCLASS_OFS = 2;
123 static const int RR_FIXED_SIZE = 10;
124 static const int RR_TYPE_OFS = 0;
125 static const int RR_CLASS_OFS = 2;
126 static const int RR_TTL_OFS = 4;
127 static const int RR_RDLENGTH_OFS = 8;
128 static const int RR_RDATA_OFS = 10;
130 static const int A_FIXED_SIZE = 0;
131 static const int A_ADDRESS_OFS = 0;
133 static const int CNAME_FIXED_SIZE = 0;
134 static const int CNAME_TARGET_OFS = 0;
137 static const int AAAA_FIXED_SIZE = 0;
138 static const int AAAA_ADDRESS_OFS = 0;
141 static const int NAPTR_FIXED_SIZE = 4;
142 static const int NAPTR_ORDER_OFS = 0;
143 static const int NAPTR_PREFERENCE_OFS = 2;
146 static const int SRV_FIXED_SIZE = 6;
147 static const int SRV_PRIORITY_OFS = 0;
148 static const int SRV_WEIGHT_OFS = 2;
149 static const int SRV_PORT_OFS = 4;
150 static const int SRV_TARGET_OFS = 6;
156 #endif // #ifndef DNSPARSER_H