3 #include <boost/tuple/tuple.hpp>
4 #include <boost/tuple/tuple_comparison.hpp>
6 #include <netinet/ip.h>
7 #include <netinet/udp.h>
8 #include "dnsparser.hh"
10 using namespace boost;
13 struct QuestionIdentifier
18 bool operator<(const QuestionIdentifier& rhs) const
21 tie(d_sourceip, d_destip, d_sourceport, d_destport, d_qname, d_qtype, d_id) <
22 tie(rhs.d_sourceip, rhs.d_destip, rhs.d_sourceport, rhs.d_destport, rhs.d_qname, rhs.d_qtype, rhs.d_id);
25 // the canonical direction is that of the question
26 static QuestionIdentifier create(const struct ip* ip, const struct udphdr* udp, const MOADNSParser& mdp)
28 QuestionIdentifier ret;
30 memcpy(&ret.d_sourceip, &ip->ip_dst, sizeof(ret.d_sourceip));
31 ret.d_sourceip=htonl(ret.d_sourceip);
33 memcpy(&ret.d_destip, &ip->ip_src, sizeof(ret.d_destip));
34 ret.d_destip=htonl(ret.d_destip);
36 ret.d_sourceport=htons(udp->uh_dport);
37 ret.d_destport=htons(udp->uh_sport);
40 memcpy(&ret.d_sourceip, &ip->ip_src, sizeof(ret.d_sourceip));
41 ret.d_sourceip=htonl(ret.d_sourceip);
43 memcpy(&ret.d_destip, &ip->ip_dst, sizeof(ret.d_destip));
44 ret.d_destip=htonl(ret.d_destip);
46 ret.d_sourceport=htons(udp->uh_sport);
47 ret.d_destport=htons(udp->uh_dport);
49 ret.d_qname=mdp.d_qname;
50 ret.d_qtype=mdp.d_qtype;
51 ret.d_id=mdp.d_header.id;
58 uint16_t d_sourceport;
68 inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi)
70 s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from ";
71 u_int32_t rint=qi.d_sourceip;
73 s<< (rint>>24 & 0xff)<<".";
74 s<< (rint>>16 & 0xff)<<".";
75 s<< (rint>>8 & 0xff)<<".";
77 s<<":"<<qi.d_sourceport;
81 s<< (rint>>24 & 0xff)<<".";
82 s<< (rint>>16 & 0xff)<<".";
83 s<< (rint>>8 & 0xff)<<".";
85 return s<<":"<<qi.d_destport;