From ebcc91b91489ca1e295d6b9198e9d18db080351d Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Sat, 18 May 2019 23:20:37 +0200 Subject: [PATCH] add DoH support to sdig --- pdns/Makefile.am | 5 +++-- pdns/sdig.cc | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index b479d4f4db..b8ef5d4973 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -498,9 +498,10 @@ sdig_SOURCES = \ sillyrecords.cc \ sstuff.hh \ statbag.cc \ - unix_utility.cc + unix_utility.cc \ + minicurl.cc minicurl.hh -sdig_LDADD = $(LIBCRYPTO_LIBS) +sdig_LDADD = $(LIBCRYPTO_LIBS) $(LIBCURL) sdig_LDFLAGS = $(AM_LDFLAGS) $(LIBCRYPTO_LDFLAGS) calidns_SOURCES = \ diff --git a/pdns/sdig.cc b/pdns/sdig.cc index 34828442d3..7fc65f7f31 100644 --- a/pdns/sdig.cc +++ b/pdns/sdig.cc @@ -10,6 +10,7 @@ #include "statbag.hh" #include #include "ednssubnet.hh" +#include "minicurl.hh" StatBag S; bool hidettl=false; @@ -24,7 +25,7 @@ string ttl(uint32_t ttl) void usage() { cerr<<"sdig"< ednsnm; uint16_t xpfcode = 0, xpfversion = 0, xpfproto = 0; char *xpfsrc = NULL, *xpfdst = NULL; @@ -149,9 +151,21 @@ try } string reply; - ComboAddress dest(argv[1] + (*argv[1]=='@'), atoi(argv[2])); + string question(packet.begin(), packet.end()); + ComboAddress dest; + if(*argv[1]=='h') + doh = true; + else + dest = ComboAddress(argv[1] + (*argv[1]=='@'), atoi(argv[2])); - if(tcp) { + if(doh) { + MiniCurl mc; + MiniCurl::MiniCurlHeaders mch; + mch.insert(std::make_pair("Content-Type", "application/dns-message")); + mch.insert(std::make_pair("Accept", "application/dns-message")); + reply = mc.postURL(argv[1], question, mch); + } + else if(tcp) { Socket sock(dest.sin4.sin_family, SOCK_STREAM); sock.connect(dest); uint16_t len; @@ -159,7 +173,7 @@ try if(sock.write((char *) &len, 2) != 2) throw PDNSException("tcp write failed"); - sock.writen(string(packet.begin(), packet.end())); + sock.writen(question); if(sock.read((char *) &len, 2) != 2) throw PDNSException("tcp read failed"); @@ -181,7 +195,7 @@ try else //udp { Socket sock(dest.sin4.sin_family, SOCK_DGRAM); - sock.sendTo(string(packet.begin(), packet.end()), dest); + sock.sendTo(question, dest); int result=waitForData(sock.getHandle(), 10); if(result < 0) throw std::runtime_error("Error waiting for data: "+string(strerror(errno))); -- 2.47.2