]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/anadns.hh
Merge pull request #2014 from rubenk/bison
[thirdparty/pdns.git] / pdns / anadns.hh
1 #ifndef PDNS_ANADNS_HH
2 #define PDNS_ANADNS_HH
3 #include <boost/tuple/tuple.hpp>
4 #include <boost/tuple/tuple_comparison.hpp>
5 #include <string>
6 #include <netinet/ip.h>
7 #include <netinet/udp.h>
8 #include "dnsparser.hh"
9 #include "iputils.hh"
10 #include "namespaces.hh"
11
12 struct QuestionIdentifier
13 {
14 QuestionIdentifier()
15 {}
16
17 bool operator<(const QuestionIdentifier& rhs) const
18 {
19 return
20 tie(d_source, d_dest, d_qname, d_qtype, d_id) <
21 tie(rhs.d_source, rhs.d_dest, rhs.d_qname, rhs.d_qtype, rhs.d_id);
22 }
23
24 // the canonical direction is that of the question
25 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
26 {
27 QuestionIdentifier ret;
28
29 if(mdp.d_header.qr) {
30 ret.d_source = dst;
31 ret.d_dest = src;
32 }
33 else {
34 ret.d_source = src;
35 ret.d_dest = dst;
36 }
37 ret.d_qname=mdp.d_qname;
38 ret.d_qtype=mdp.d_qtype;
39 ret.d_id=mdp.d_header.id;
40 return ret;
41 }
42
43 ComboAddress d_source, d_dest;
44
45 string d_qname;
46 uint16_t d_qtype;
47 uint16_t d_id;
48 };
49
50 inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi)
51 {
52 s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from "<<qi.d_source.toStringWithPort();
53
54 s<<" to " << qi.d_dest.toStringWithPort();
55 return s;
56 }
57
58
59 #endif