]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dns.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <boost/algorithm/string.hpp>
30 #include <boost/assign/list_of.hpp>
31 #include "dnsparser.hh"
33 std::vector
<std::string
> RCode::rcodes_s
= boost::assign::list_of
37 ("Non-Existent domain")
40 ("Name Exists when it should not")
41 ("RR Set Exists when it should not")
42 ("RR Set that should exist does not")
43 ("Server Not Authoritative for zone / Not Authorized")
44 ("Name not contained in zone")
50 ("Bad OPT Version / TSIG Signature Failure")
51 ("Key not recognized")
52 ("Signature out of time window")
54 ("Duplicate key name")
55 ("Algorithm not supported")
59 std::string
RCode::to_s(unsigned short rcode
) {
60 if (rcode
> RCode::rcodes_s
.size()-1 )
61 return std::string("Err#")+std::to_string(rcode
);
62 return RCode::rcodes_s
[rcode
];
65 class BoundsCheckingPointer
68 explicit BoundsCheckingPointer(const char* a
, size_t length
)
69 : d_ptr(a
), d_length(length
)
72 explicit BoundsCheckingPointer(const std::string
& str
)
73 : d_ptr(str
.c_str()), d_length(str
.size())
77 char operator[](size_t offset
) const
81 throw runtime_error("out of bounds: "+std::to_string(offset
)+" >= " + std::to_string(d_length
));
85 const size_t d_length
;
89 // goal is to hash based purely on the question name, and turn error into 'default'
90 uint32_t hashQuestion(const char* packet
, uint16_t len
, uint32_t init
)
96 const unsigned char* end
= (const unsigned char*)packet
+len
;
97 const unsigned char* pos
= (const unsigned char*)packet
+12;
99 unsigned char labellen
;
100 while((labellen
=*pos
++) && pos
< end
) {
101 if(pos
+ labellen
+ 1 > end
) // include length field in hash
103 ret
=burtleCI(pos
, labellen
+1, ret
);
110 string
& attodot(string
&str
)
112 if(str
.find_first_of("@")==string::npos
)
115 for (unsigned int i
= 0; i
< str
.length(); i
++)
120 } else if (str
[i
] == '.') {
121 str
.insert(i
++, "\\");