From: Remi Gacogne Date: Thu, 24 Mar 2016 15:32:38 +0000 (+0100) Subject: Add unique IDs to match query w/ response in dnspcap2protobuf X-Git-Tag: dnsdist-1.0.0-beta1~58 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9cad4dabddda49ef18907ffde77014e975e8fea;p=pdns Add unique IDs to match query w/ response in dnspcap2protobuf --- diff --git a/pdns/dnspcap2protobuf.cc b/pdns/dnspcap2protobuf.cc index 2b7698a8a..a4dfeff46 100644 --- a/pdns/dnspcap2protobuf.cc +++ b/pdns/dnspcap2protobuf.cc @@ -1,3 +1,7 @@ +#include +#include +#include + #include "dnsmessage.pb.h" #include "iputils.hh" #include "misc.hh" @@ -83,7 +87,8 @@ int main(int argc, char **argv) cerr<<"Error opening output file "< ids; + boost::uuids::random_generator uuidGenerator; while (pr.getUDPPacket()) { const dnsheader* dh=(dnsheader*)pr.d_payload; if (!dh->qdcount) @@ -129,18 +134,26 @@ int main(int argc, char **argv) PBDNSMessage_DNSQuestion question; PBDNSMessage_DNSResponse response; if (!dh->qr) { + boost::uuids::uuid uniqueId = uuidGenerator(); + ids[dh->id] = uniqueId; + message.set_messageid(boost::uuids::to_string(uniqueId)); question.set_qname(qname.toString()); question.set_qtype(qtype); question.set_qclass(qclass); message.set_allocated_question(&question); } else { + const auto& it = ids.find(dh->id); + if (it != ids.end()) { + message.set_messageid(boost::uuids::to_string(it->second)); + } response.set_rcode(dh->rcode); addRRs((const char*) dh, pr.d_len, response); message.set_allocated_response(&response); } std::string str; + //cerr<