]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/anadns.hh
Fix compilation on systems that do not define HOST_NAME_MAX
[thirdparty/pdns.git] / pdns / anadns.hh
CommitLineData
12471842
PL
1/*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
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.
8 *
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.
12 *
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.
17 *
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.
21 */
e8c59f2d 22#pragma once
9a450843
BH
23#include <boost/tuple/tuple.hpp>
24#include <boost/tuple/tuple_comparison.hpp>
25#include <string>
26#include <netinet/ip.h>
27#include <netinet/udp.h>
28#include "dnsparser.hh"
8b422c02 29#include "iputils.hh"
61b26744 30#include "namespaces.hh"
9a450843
BH
31
32struct QuestionIdentifier
33{
34 QuestionIdentifier()
35 {}
36
37 bool operator<(const QuestionIdentifier& rhs) const
38 {
39 return
ef890b79 40 tie(d_id, d_qtype, d_source, d_dest, d_qname) <
41 tie(rhs.d_id, rhs.d_qtype, rhs.d_source, rhs.d_dest, rhs.d_qname);
9a450843
BH
42 }
43
ef890b79 44
9a450843 45 // the canonical direction is that of the question
ef890b79 46 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const struct dnsheader& header, const DNSName& qname, uint16_t qtype)
9a450843
BH
47 {
48 QuestionIdentifier ret;
a5d9353e 49
ef890b79 50 if(header.qr) {
a5d9353e 51 ret.d_source = dst;
52 ret.d_dest = src;
9a450843
BH
53 }
54 else {
a5d9353e 55 ret.d_source = src;
56 ret.d_dest = dst;
9a450843 57 }
ef890b79 58 ret.d_qname=qname;
59 ret.d_qtype=qtype;
60 ret.d_id=ntohs(header.id);
9a450843
BH
61 return ret;
62 }
63
ef890b79 64 // the canonical direction is that of the question
65 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
66 {
67 return create(src, dst, mdp.d_header, mdp.d_qname, mdp.d_qtype);
68 }
69
70
8b422c02 71 ComboAddress d_source, d_dest;
9a450843 72
af6406f5 73 DNSName d_qname;
9a450843
BH
74 uint16_t d_qtype;
75 uint16_t d_id;
9a450843
BH
76};
77
78inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi)
79{
81aa6d25 80 s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from "<<qi.d_source.toStringWithPort();
9a450843 81
8b422c02 82 s<<" to " << qi.d_dest.toStringWithPort();
83 return s;
9a450843 84}