]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dns.cc
6 #include "arguments.hh"
9 #include <boost/algorithm/string.hpp>
10 #include <boost/lexical_cast.hpp>
11 #include <boost/assign/list_of.hpp>
12 #include "dnsparser.hh"
14 std::vector
<std::string
> RCode::rcodes_s
= boost::assign::list_of
18 ("Non-Existent domain")
21 ("Name Exists when it should not")
22 ("RR Set Exists when it should not")
23 ("RR Set that should exist does not")
24 ("Server Not Authoritative for zone / Not Authorized")
25 ("Name not contained in zone")
31 ("Bad OPT Version / TSIG Signature Failure")
32 ("Key not recognized")
33 ("Signature out of time window")
35 ("Duplicate key name")
36 ("Algorithm not supported")
40 std::string
RCode::to_s(unsigned short rcode
) {
41 if (rcode
> RCode::rcodes_s
.size()-1 )
42 return std::string("Err#")+boost::lexical_cast
<std::string
>(rcode
);
43 return RCode::rcodes_s
[rcode
];
46 class BoundsCheckingPointer
49 explicit BoundsCheckingPointer(const char* a
, unsigned int length
)
50 : d_ptr(a
), d_length(length
)
53 explicit BoundsCheckingPointer(const std::string
& str
)
54 : d_ptr(str
.c_str()), d_length(str
.size())
58 char operator[](unsigned int offset
) const
62 throw runtime_error("out of bounds: "+boost::lexical_cast
<string
>(offset
)+" >= " + boost::lexical_cast
<string
>(d_length
));
66 const unsigned int d_length
;
70 // goal is to hash based purely on the question name, and turn error into 'default'
71 uint32_t hashQuestion(const char* packet
, uint16_t len
, uint32_t init
)
77 const unsigned char* end
= (const unsigned char*)packet
+len
;
78 const unsigned char* pos
= (const unsigned char*)packet
+12;
80 unsigned char labellen
;
81 while((labellen
=*pos
++) && pos
< end
) {
82 if(pos
+ labellen
+ 1 > end
) // include length field in hash
84 ret
=burtleCI(pos
, labellen
+1, ret
);
91 string
& attodot(string
&str
)
93 if(str
.find_first_of("@")==string::npos
)
96 for (unsigned int i
= 0; i
< str
.length(); i
++)
101 } else if (str
[i
] == '.') {
102 str
.insert(i
++, "\\");
108 vector
<DNSResourceRecord
> convertRRS(const vector
<DNSRecord
>& in
)
110 vector
<DNSResourceRecord
> out
;
111 for(const auto& d
: in
) {
112 DNSResourceRecord rr
;
114 rr
.qtype
= QType(d
.d_type
);
116 rr
.content
= d
.d_content
->getZoneRepresentation();
118 rr
.qclass
= d
.d_class
;