#!/usr/bin/perl

use strict;

# this is the main loop. Get the questions from QUESTIONS
# and prepare them to feed them to dig. This could later
# even be folded into this script with Net::DNS.

# answer are stored ar $number.valid
# this must be carefully check as the .valid files
# are used to validate answers from other DNS servers

my $question;
my $number;
my $pid=$$;
my $dig="/usr/bin/dig -p 5353 \@localhost ";
my $diff="/usr/bin/diff -u";
my $q;
my @answer;
my @diff;

while (<>) {
	chomp;
	if ( /^#/ ) { next;} # comments
	($number,$question) = split /:/;

	$q=$dig . $question;
	print "Q $number: $q\n";
	@answer = `$q | ./stripdig.pl`;
	if ( $? == -1 ) { 
		print "Failed to query\n";
		exit 1;
	}

	# write the answer to a tmp file
	open ANSWER, ">$number.valid";
		print ANSWER @answer;
	close ANSWER;
}
