Description: Update rbl.monitor to latest version
Author: Dario Minnucci <midget@debian.org>
Last-Update: 2011-05-04
Index: mon-contrib/monitors/dnsbl/rbl.monitor
===================================================================
--- mon-contrib.orig/monitors/dnsbl/rbl.monitor	2011-05-04 17:53:36.983228918 +0200
+++ mon-contrib/monitors/dnsbl/rbl.monitor	2011-05-04 17:56:34.856557698 +0200
@@ -1,13 +1,10 @@
 #!/usr/bin/perl
-#
+
 # rbl.monitor - check RBL blacklists for an IP address.  Uses asynch I/O
 # to send all the requests simultaneously
-#
-# Based on original work by Tim Haynes, re-written by Ed Ravin to
-# use asynchronous I/O.
-#
-# $Id: rbl.monitor,v 1.3 2010/05/22 12:35:23 trockij Exp $
-#
+
+# Copyright (c) 2007, 2008 by Ed Ravin <eravin@panix.com>.  License is GNU.
+# Available to the public courtesy of Public Access Networks http://panix.com
 
 my $usage="\
 Usage: rbl.monitor [options] hostname [...]
@@ -77,9 +74,9 @@
 my $sel	 = IO::Select->new();
 my $starttime= time;
 
-my %hostpart2host;
+my %revip2host;
 
-# gethostbyname is non-reentrant, so do all the queries up front
+# gethostbyname is non-reentrant, so parse the hostnames to test up front
 foreach my $host (@ARGV) {
 	my $hostdata= gethostbyname($host);
 	if (!defined($hostdata)) {
@@ -87,14 +84,16 @@
 		push @detail, "$host: bad hostname";
 		next;
 	}
-	my $hostpart= join(".", reverse(unpack("C4", $hostdata)));
-	$hostpart2host{$hostpart}= $host;
+	my $revip= join(".", reverse(unpack("C4", $hostdata)));
+	$revip2host{$revip}= $host;
 }
 
 # start all the queries
-foreach my $hostpart (keys %hostpart2host) {
+foreach my $revip (keys %revip2host) {
 	foreach my $rbl (@rbls2check) {
-		my $dnssock=  $res->bgsend(join(".", $hostpart, $rbl));
+		my $dnssock=  $res->bgsend(join(".", $revip, $rbl));
+		die "$0: Net::DNS::Resolver::bgsend returns undef - too many open files?\n"
+			unless defined($dnssock);
 		push @sockets, $dnssock;
 		$sel->add($dnssock);
 	}
@@ -108,16 +107,18 @@
 		last MAINLOOP;
 	}
 	foreach my $sock (@ready) {
-		my ($authority, $ipaddress, $hostpart, $host);
+		my ($authority, $ipaddress, $revip, $forwardip, $host);
 		my $packet = $res->bgread($sock);
 		foreach my $rr ($packet->answer) {
 			if ($rr->type eq "A") {
 				$ipaddress= $rr->address;
 				$authority= $rr->name;
-				if ($authority=~ /^(\d+\.\d+\.\d+\.\d+)\./) {
-					$hostpart= $1;
-					$host= $hostpart2host{$hostpart};
-				} else { $host= "???" }
+				my $q= \$packet->question;
+				my @qquads= split('\.',${$$q}{qname});
+				splice(@qquads, 4);
+				$revip= join('.', @qquads);
+				$forwardip= join('.', reverse(@qquads));
+				$host= $revip2host{$revip} || $forwardip;
 				push @summary, $host
 					unless grep /^$host$/, @summary;
 				push @detail, "$host: $authority: " . $rr->address;
