]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
sdig: support reading packets from stdin 8027/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 3 Dec 2019 11:45:00 +0000 (12:45 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 3 Dec 2019 11:45:00 +0000 (12:45 +0100)
docs/manpages/sdig.1.rst
pdns/sdig.cc

index a363e00f0da656f7abd2ec9b7559b6208e69e413..90d875894f839084654e6b04a461a399cb1e30a4 100644 (file)
@@ -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
 -------
index 5ea08579b89ab983b72c6db5b418830cc7360066..5ebf9ef7d34738bb4c42b5b9d8873e06eaea572c 100644 (file)
@@ -190,6 +190,7 @@ try {
   bool showflags = false;
   bool hidesoadetails = false;
   bool doh = false;
+  bool stdin = false;
   boost::optional<Netmask> 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<char> 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);