#!/usr/bin/perl
# check for black holes

use Socket;

open(IN, "formail -c -x received:|") || die "Cant open input";
close(STDIN);
while (<IN>) {
  m/[[]([0-9.]+)[]]/ && push @hosts, $1;
}
# we have now hosts at @hosts
# $host[0] = where we receive
# $host[$#host] = original sender

for ($i = 0; $i <= $#hosts; $i++) {
  @ia = split(/\./, $hosts[$i]);
  $iaddr = pack('C4', @ia);
  $name = gethostbyaddr ($iaddr, AF_INET);
  if (gethostbyname(sprintf("%d.%d.%d.%d.inputs.orbs.org", 
			    $ia[3],$ia[2], $ia[1], $ia[0]))) {
    printf "\t%d: %s [%s] IN ORBS\n", $i, $name?$name:"unknown",$hosts[$i];
    exit (1);
  }
}
exit(0);
