From 309feebccb92c0df7323bf6901516896cb140289 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Wed, 23 Oct 2019 16:30:52 +0200 Subject: [PATCH] sdig: make query class selectable --- docs/manpages/sdig.1.rst | 2 ++ pdns/sdig.cc | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/manpages/sdig.1.rst b/docs/manpages/sdig.1.rst index cddacafa7..5f1e62019 100644 --- a/docs/manpages/sdig.1.rst +++ b/docs/manpages/sdig.1.rst @@ -20,6 +20,8 @@ Options These options can be added to the commandline in any order. +class *CLASSNUM* + Send the query in the numbered class (like 3 for CHAOS) instead of the default 1 (for IN). dnssec Set the DO bit to request DNSSEC information. ednssubnet *SUBNET* diff --git a/pdns/sdig.cc b/pdns/sdig.cc index d46e58a7d..5ea08579b 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -32,7 +32,7 @@ void usage() cerr << "sdig" << endl; cerr << "Syntax: sdig IP-ADDRESS-OR-DOH-URL PORT QUESTION QUESTION-TYPE " "[dnssec] [ednssubnet SUBNET/MASK] [hidesoadetails] [hidettl] " - "[recurse] [showflags] [tcp] [xpf XPFDATA]" + "[recurse] [showflags] [tcp] [xpf XPFDATA] [class CLASSNUM]" << endl; } @@ -58,9 +58,10 @@ const string nameForClass(uint16_t qclass, uint16_t qtype) void fillPacket(vector& packet, const string& q, const string& t, bool dnssec, const boost::optional ednsnm, bool recurse, uint16_t xpfcode, uint16_t xpfversion, - uint64_t xpfproto, char* xpfsrc, char* xpfdst) + uint64_t xpfproto, char* xpfsrc, char* xpfdst, + uint16_t qclass) { - DNSPacketWriter pw(packet, DNSName(q), DNSRecordContent::TypeToNumber(t)); + DNSPacketWriter pw(packet, DNSName(q), DNSRecordContent::TypeToNumber(t), qclass); if (dnssec || ednsnm || getenv("SDIGBUFSIZE")) { char* sbuf = getenv("SDIGBUFSIZE"); @@ -192,6 +193,7 @@ try { boost::optional ednsnm; uint16_t xpfcode = 0, xpfversion = 0, xpfproto = 0; char *xpfsrc = NULL, *xpfdst = NULL; + uint16_t qclass = QClass::IN; for (int i = 1; i < argc; i++) { if ((string)argv[i] == "--help") { @@ -244,6 +246,13 @@ try { xpfsrc = argv[++i]; xpfdst = argv[++i]; } + if (strcmp(argv[i], "class") == 0) { + if (argc < i+2) { + cerr << "class needs an argument"< packet; fillPacket(packet, name, type, dnssec, ednsnm, recurse, xpfcode, xpfversion, - xpfproto, xpfsrc, xpfdst); + xpfproto, xpfsrc, xpfdst, qclass); MiniCurl mc; MiniCurl::MiniCurlHeaders mch; mch.insert(std::make_pair("Content-Type", "application/dns-message")); @@ -294,7 +303,7 @@ try { for (const auto& it : questions) { vector packet; fillPacket(packet, it.first, it.second, dnssec, ednsnm, recurse, xpfcode, - xpfversion, xpfproto, xpfsrc, xpfdst); + xpfversion, xpfproto, xpfsrc, xpfdst, qclass); uint16_t len = htons(packet.size()); if (sock.write((const char *)&len, 2) != 2) @@ -326,7 +335,7 @@ try { { vector packet; fillPacket(packet, name, type, dnssec, ednsnm, recurse, xpfcode, xpfversion, - xpfproto, xpfsrc, xpfdst); + xpfproto, xpfsrc, xpfdst, qclass); string question(packet.begin(), packet.end()); Socket sock(dest.sin4.sin_family, SOCK_DGRAM); sock.sendTo(question, dest); -- 2.40.0