From: Peter van Dijk Date: Tue, 3 Dec 2019 11:45:00 +0000 (+0100) Subject: sdig: support reading packets from stdin X-Git-Tag: auth-4.3.0-alpha1~8^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F8027%2Fhead;p=thirdparty%2Fpdns.git sdig: support reading packets from stdin --- diff --git a/docs/manpages/sdig.1.rst b/docs/manpages/sdig.1.rst index a363e00f0d..90d875894f 100644 --- a/docs/manpages/sdig.1.rst +++ b/docs/manpages/sdig.1.rst @@ -12,6 +12,7 @@ Description :program:`sdig` sends a DNS query to *IP-ADDRESS-OR-DOH-URL* on port *PORT* and displays the answer in a formatted way. If the address starts with an ``h``, it is assumed to be a DoH endpoint, and *PORT* is ignored. If qname and qtype are both `-` and tcp is used, multiple lines are read from stdin, where each line contains a qname and a type. +If the address is ``stdin``, a DNS packet is read from stdin instead of from the network, and *PORT* is ignored. Options ------- diff --git a/pdns/sdig.cc b/pdns/sdig.cc index 5ea08579b8..5ebf9ef7d3 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -190,6 +190,7 @@ try { bool showflags = false; bool hidesoadetails = false; bool doh = false; + bool stdin = false; boost::optional ednsnm; uint16_t xpfcode = 0, xpfversion = 0, xpfproto = 0; char *xpfsrc = NULL, *xpfdst = NULL; @@ -260,6 +261,8 @@ try { ComboAddress dest; if (*argv[1] == 'h') { doh = true; + } else if(strcmp(argv[1], "stdin") == 0) { + stdin = true; } else { dest = ComboAddress(argv[1] + (*argv[1] == '@'), atoi(argv[2])); } @@ -297,6 +300,10 @@ try { #else throw PDNSException("please link sdig against libcurl for DoH support"); #endif + } else if (stdin) { + std::istreambuf_iterator begin(std::cin), end; + reply = string(begin, end); + printReply(reply, showflags, hidesoadetails); } else if (tcp) { Socket sock(dest.sin4.sin_family, SOCK_STREAM); sock.connect(dest);