Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth sdig: some improvements for stdin mode #14665

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading