From: Mark Andrews Date: Tue, 1 Sep 2020 23:40:45 +0000 (+1000) Subject: Dump the returned packet X-Git-Tag: v9.16.7~9^2~2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=02be5fc953792b3ae22c2d7b46690dabde91a12b;p=thirdparty%2Fbind9.git Dump the returned packet --- diff --git a/bin/tests/system/packet.pl b/bin/tests/system/packet.pl index 28d6a0987a4..985b21c26f1 100644 --- a/bin/tests/system/packet.pl +++ b/bin/tests/system/packet.pl @@ -31,7 +31,7 @@ # Note that we do not wait for a response for the server. This is simply # a way of injecting arbitrary packets to test server resposnes. # -# Usage: packet.pl [-a
] [-p ] [-t (udp|tcp)] [-r ] [filename] +# Usage: packet.pl [-a
] [-d] [-p ] [-t (udp|tcp)] [-r ] [filename] # # If not specified, address defaults to 127.0.0.1, port to 53, protocol # to udp, and file to stdin. @@ -46,12 +46,12 @@ use IO::File; use IO::Socket; sub usage { - print ("Usage: packet.pl [-a address] [-p port] [-t (tcp|udp)] [-r ] [file]\n"); + print ("Usage: packet.pl [-a address] [-d] [-p port] [-t (tcp|udp)] [-r ] [file]\n"); exit 1; } my %options={}; -getopts("a:p:t:r:", \%options); +getopts("a:dp:t:r:", \%options); my $addr = "127.0.0.1"; $addr = $options{a} if defined $options{a}; @@ -103,5 +103,38 @@ while ($repeats > 0) { } print ("sent $bytes bytes to $addr:$port\n"); +if (defined $options{d}) { + use Net::DNS; + use Net::DNS::Packet; + + my $rin; + my $rout; + $rin = ''; + vec($rin, fileno($sock), 1) = 1; + select($rout = $rin, undef, undef, 1); + if (vec($rout, fileno($sock), 1)) {{ + my $buf; + if ($proto eq "udp") { + $sock->recv($buf, 512); + } else { + my $n = $sock->sysread($buf, 2); + last unless $n == 2; + my $len = unpack("n", $buf); + $n = $sock->sysread($buf, $len); + last unless $n == $len; + } + + my $response; + if ($Net::DNS::VERSION > 0.68) { + $response = new Net::DNS::Packet(\$buf, 0); + $@ and die $@; + } else { + my $err; + ($response, $err) = new Net::DNS::Packet(\$buf, 0); + $err and die $err; + } + $response->print; + }} +} $sock->close; close $file;