From 4036ad2a9afa4417c670fc52eaf67da37b0f8e45 Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Mon, 9 May 2005 18:38:03 +0000 Subject: Double check the answer from the dns server and optionally enforce a NOERROR response code -- Christoph.Heine in HaDiKo.DE --- lib/Smokeping/probes/AnotherDNS.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/Smokeping/probes') diff --git a/lib/Smokeping/probes/AnotherDNS.pm b/lib/Smokeping/probes/AnotherDNS.pm index 65a1bd4..d4f0397 100644 --- a/lib/Smokeping/probes/AnotherDNS.pm +++ b/lib/Smokeping/probes/AnotherDNS.pm @@ -69,6 +69,7 @@ sub pingone ($) { my $recordtype = $target->{vars}{recordtype}; my $timeout = $target->{vars}{timeout}; my $port = $target->{vars}{port}; + my $require_noerror = $target->{vars}{require_noerror}; $lookuphost = $target->{addr} unless defined $lookuphost; my $packet = Net::DNS::Packet->new( $lookuphost, $recordtype )->data; @@ -93,9 +94,20 @@ sub pingone ($) { my $t1 = [gettimeofday]; $elapsed = tv_interval( $t0, $t1 ); if ( defined $ready ) { - push @times, $elapsed; my $buf = ''; $ready->recv( $buf, &Net::DNS::PACKETSZ ); + my ($recvPacket, $err) = Net::DNS::Packet->new(\$buf); + if (defined $recvPacket) { + if (not $require_noerror) { + push @times, $elapsed; + } else { + # Check the Response Code for the NOERROR. + my $recvHeader = $recvPacket->header(); + if ($recvHeader->rcode() eq "NOERROR") { + push @times, $elapsed; + } + } + } } } @times = @@ -127,6 +139,10 @@ DOC _default => .5, _re => '(\d*\.)?\d+', }, + require_noerror => { + _doc => 'Only Count Answers with Response Status NOERROR.', + _default => 0, + }, recordtype => { _doc => 'Record type to look up.', _default => 'A', -- cgit v1.2.3-24-g4f1b