Skip to content

Commit

Permalink
Merge pull request #14665 from Habbie/sdig-stdin-improvements
Browse files Browse the repository at this point in the history
auth sdig: some improvements for stdin mode
  • Loading branch information
Habbie authored Oct 10, 2024
2 parents 76b0035 + 703e8e2 commit 2699c40
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pdns/sdig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,24 @@ static void fillPacket(vector<uint8_t>& packet, const string& q, const string& t
pw.getHeader()->id = htons(qid);
}

static void printReply(const string& reply, bool showflags, bool hidesoadetails, bool dumpluaraw)
static void printReply(const string& reply, bool showflags, bool hidesoadetails, bool dumpluaraw, bool ignoreId = false)
{
MOADNSParser mdp(false, reply);
if (!s_expectedIDs.count(ntohs(mdp.d_header.id))) {

if (!ignoreId && (s_expectedIDs.count(ntohs(mdp.d_header.id)) == 0U)) {
cout << "ID " << ntohs(mdp.d_header.id) << " was not expected, this response was not meant for us!"<<endl;
}
s_expectedIDs.erase(ntohs(mdp.d_header.id));

cout << "Reply to question for qname='" << mdp.d_qname.toString()
<< "', qtype=" << DNSRecordContent::NumberToType(mdp.d_qtype) << endl;
cout << (mdp.d_header.qr ? "Reply to question" : "Question") << " for qname='" << mdp.d_qname.toString()
<< "', qtype=" << DNSRecordContent::NumberToType(mdp.d_qtype);

if (ignoreId) {
// if we did not generate the ID, the user might be interested in seeing it
cout << ", ID=" << ntohs(mdp.d_header.id);
}

cout << endl;
cout << "Rcode: " << mdp.d_header.rcode << " ("
<< RCode::to_s(mdp.d_header.rcode) << "), RD: " << mdp.d_header.rd
<< ", QR: " << mdp.d_header.qr;
Expand Down Expand Up @@ -378,7 +386,7 @@ try {
reply = reply.substr(2);
}

printReply(reply, showflags, hidesoadetails, dumpluaraw);
printReply(reply, showflags, hidesoadetails, dumpluaraw, true);
} else if (tcp) {
std::shared_ptr<TLSCtx> tlsCtx{nullptr};
if (dot) {
Expand Down

0 comments on commit 2699c40

Please sign in to comment.