#!/afs/athena/contrib/perl/perl
#
# this just calls res_dom_tmp.pl and joins
#
# USAGE:  $0 output-file domain1 [domain2 [domain3 ...]]

unshift(@INC,"/mit/marc/perl");

require 'resolv.pl';

open(FOO, "> ".shift(@ARGV)) || die "$0: couldn't open file\n";

@ARGV || die "$0: no domain specified\n";

sub byipaddr {
    @IPa = split(/\./,(split("\t",$HOST[$a]))[0]);
    @IPb = split(/\./,(split("\t",$HOST[$b]))[0]);

    ($IPa[0] <=> $IPb[0]) || ($IPa[1] <=> $IPb[1])
	|| ($IPa[2] <=> $IPb[2]) || ($IPa[3] <=> $IPb[3]);
}


$size = 0;
while(@ARGV) {
    open (HOSTS, "/mit/bert/PERL/res_dom.pl ".shift(@ARGV)." |")
	|| die "$0: couldn't open file (or find res_dom.pl)\n";

    while (<HOSTS>) {chop; $HOST[$size++] = $_;}
}

@SORTEDHOST = @HOST[sort byipaddr $[..$#HOST];

print "\nStuff sorted. Saving...\n";

for ($foo=0; $foo<$size; $foo++) {
    print FOO $SORTEDHOST[$foo],"\n";
}
