}
// the canonical direction is that of the question
- static QuestionIdentifier create(const struct ip* ip, const struct udphdr* udp, const MOADNSParser& mdp)
+ static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
{
QuestionIdentifier ret;
- struct ip6_hdr* ip6 = (struct ip6_hdr*)ip;
+
if(mdp.d_header.qr) {
- if(ip->ip_v!=6) {
- ret.d_source.sin4.sin_addr = ip->ip_dst;
- ret.d_dest.sin4.sin_addr = ip->ip_src;
- }
- else {
- ret.d_source.sin6.sin6_addr = ip6->ip6_dst;
- ret.d_dest.sin6.sin6_addr = ip6->ip6_src;
- }
- ret.d_dest.sin4.sin_port = udp->uh_sport;
- ret.d_source.sin4.sin_port = udp->uh_dport;
+ ret.d_source = dst;
+ ret.d_dest = src;
}
else {
- if(ip->ip_v != 6) {
- ret.d_source.sin4.sin_addr = ip->ip_src;
- ret.d_dest.sin4.sin_addr = ip->ip_dst;
- }
- else {
- ret.d_source.sin6.sin6_addr = ip6->ip6_src;
- ret.d_dest.sin6.sin6_addr = ip6->ip6_dst;
- }
- ret.d_source.sin4.sin_port = udp->uh_sport;
- ret.d_dest.sin4.sin_port = udp->uh_dport;
-
+ ret.d_source = src;
+ ret.d_dest = dst;
}
ret.d_qname=mdp.d_qname;
ret.d_qtype=mdp.d_qtype;
return false;
}
+ComboAddress PcapPacketReader::getSource() const
+{
+ ComboAddress ret;
+ if(d_ip->ip_v == 4) {
+ ret.sin4.sin_family = AF_INET;
+ ret.sin4.sin_addr = d_ip->ip_src;
+ ret.sin4.sin_port = d_udp->uh_sport; // should deal with TCP too!
+ } else {
+ ret.sin6.sin6_family = AF_INET6;
+ ret.sin6.sin6_addr = d_ip6->ip6_src;
+ ret.sin6.sin6_port = d_udp->uh_sport; // should deal with TCP too!
+ }
+ return ret;
+}
+
+ComboAddress PcapPacketReader::getDest() const
+{
+ ComboAddress ret;
+ if(d_ip->ip_v == 4) {
+ ret.sin4.sin_family = AF_INET;
+ ret.sin4.sin_addr = d_ip->ip_dst;
+ ret.sin4.sin_port = d_udp->uh_dport; // should deal with TCP too!
+ } else {
+ ret.sin6.sin6_family = AF_INET6;
+ ret.sin6.sin6_addr = d_ip6->ip6_dst;
+ ret.sin6.sin6_port = d_udp->uh_dport; // should deal with TCP too!
+ }
+ return ret;
+}
+
PcapPacketWriter::PcapPacketWriter(const string& fname, PcapPacketReader& ppr) : d_fname(fname), d_ppr(ppr)
{
typedef map<uint32_t,uint32_t> cumul_t;
cumul_t cumul;
unsigned int untracked=0, errorresult=0, reallylate=0, nonRDQueries=0, queries=0;
+ unsigned int ipv4Packets=0, ipv6Packets=0;
typedef map<uint16_t,uint32_t> rcodes_t;
rcodes_t rcodes;
time_t lowestTime=2000000000, highestTime=0;
-
while(pr.getUDPPacket()) {
if((ntohs(pr.d_udp->uh_dport)==5300 || ntohs(pr.d_udp->uh_sport)==5300 ||
ntohs(pr.d_udp->uh_dport)==53 || ntohs(pr.d_udp->uh_sport)==53) &&
pr.d_len > 12) {
try {
MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
+ if(pr.d_ip->ip_v == 4)
+ ++ipv4Packets;
+ else
+ ++ipv6Packets;
+
if(!mdp.d_header.qr) {
if(!mdp.d_header.rd)
nonRDQueries++;
string name=mdp.d_qname+"|"+DNSRecordContent::NumberToType(mdp.d_qtype);
- QuestionIdentifier qi=QuestionIdentifier::create(pr.d_ip, pr.d_udp, mdp);
+ QuestionIdentifier qi=QuestionIdentifier::create(pr.getSource(), pr.getDest(), mdp);
if(!mdp.d_header.qr) {
// cout<<"Question for '"<< name <<"'\n";
}
}
}
- cerr<<"Timespan: "<<(highestTime-lowestTime)/3600.0<<" hours"<<endl;
+ cout<<"Timespan: "<<(highestTime-lowestTime)/3600.0<<" hours"<<endl;
- cerr<<"Saw "<<pr.d_correctpackets<<" correct packets, "<<pr.d_runts<<" runts, "<< pr.d_oversized<<" oversize, "<<
+ cout<<"Saw "<<pr.d_correctpackets<<" correct packets, "<<pr.d_runts<<" runts, "<< pr.d_oversized<<" oversize, "<<
pr.d_nonetheripudp<<" unknown encaps, "<<dnserrors<<" dns decoding errors, "<<bogus<<" bogus packets"<<endl;
-
+ cout<<"IPv4: "<<ipv4Packets<<" packets, IPv6: "<<ipv6Packets<<" packets"<<endl;
unsigned int unanswered=0;
for(statmap_t::const_iterator i=statmap.begin(); i!=statmap.end(); ++i) {
if(!i->second.d_answercount) {
}
}
- cerr<< boost::format("%d (%.02f%% of all) queries did not request recursion") % nonRDQueries % ((nonRDQueries*100.0)/queries) << endl;
- cerr<<statmap.size()<<" packets went unanswered, of which "<< statmap.size()-unanswered<<" were answered on exact retransmit"<<endl;
- cerr<<untracked<<" answers could not be matched to questions"<<endl;
- cerr<<dnserrors<<" answers were unsatisfactory (indefinite, or SERVFAIL)"<<endl;
- cerr<<reallylate<<" answers (would be) discarded because older than 2 seconds"<<endl;
+ cout<< boost::format("%d (%.02f%% of all) queries did not request recursion") % nonRDQueries % ((nonRDQueries*100.0)/queries) << endl;
+ cout<<statmap.size()<<" queries went unanswered, of which "<< statmap.size()-unanswered<<" were answered on exact retransmit"<<endl;
+ cout<<untracked<<" responses could not be matched to questions"<<endl;
+ cout<<dnserrors<<" responses were unsatisfactory (indefinite, or SERVFAIL)"<<endl;
+ cout<<reallylate<<" responses (would be) discarded because older than 2 seconds"<<endl;
#if 0
ns_r_noerror = 0, /* No error occurred. */
ns_r_formerr = 1, /* Format error. */
ns_r_refused = 5, /* Operation refused. */
#endif
- cerr<<"Rcode\tCount\n";
+ cout<<"Rcode\tCount\n";
for(rcodes_t::const_iterator i=rcodes.begin(); i!=rcodes.end(); ++i)
- cerr<<i->first<<"\t"<<i->second<<endl;
+ cout<<i->first<<"\t"<<i->second<<endl;
uint32_t sum=0;
ofstream stats("stats");
lastperc=sum*100.0/totpackets;
}
}
-
if(totpackets)
- cerr<<"Average response time: "<<tottime/totpackets<<" usec"<<endl;
+ cout<<"Average response time: "<<tottime/totpackets<<" usec"<<endl;
}
catch(std::exception& e)
{