#!/usr/bin/perl

open (STDERR, ">&STDOUT");
select ((select(STDOUT), $| = 1)[0]); # Synchronize STDOUT
select ((select(STDERR), $| = 1)[0]); # with STDERR

($dns_lib = $0) =~ s:(^|/)[^/]*$::;
($script=$0) =~ s:^.*/([^/]*)$:$1:;	# Get the simple name of this script.

push (@INC, $dns_lib);

require 5.0;
require 'dns_lib.perl';

use Getopt::Long;
$Getopt::Long::autoabbrev=1;    # Allow keyword abbreviations (to uniqueness).
$Getopt::Long::getopt_compat=1; # Allow both "--foo=bar" and "+foo=bar" style.
#$Getopt::Long::option_start='(--|-|\+)';       # [Use the defaults]
#$Getopt::Long::order=$Getopt::Long::REQUIRE_ORDER; # Options can't intermingle
$Getopt::Long::order=$Getopt::Long::PERMUTE;    # or options may intermingle.
$Getopt::Long::ignorecase=1;    # Don't consider case in options.
$Getopt::Long::debug=0;         ### Debug ###

$opt_help = ($#ARGV < 0);

&GetOptions ('help') || die "\nTry: $script --help for more information.\n\n";

if ($opt_help) { 
 
    print <<"EndOfHelp";
Usage: $script [OPTION] [zone]
 
  --help   This page.

  zone     The fully qualified name of the zone in which the
           SOA record resides.
 
EndOfHelp
    
    exit;

} # End if - help

$name = $ARGV[0];

if (($name =~ m/^[\d\.]+$/o) || ($name =~ m/\.in-addr\.arpa\.*$/o)) {

    $name = &verify_subnet ($name);
    $name = &reverse_ip ($name) if $name !~ m/\.in-addr\.arpa\.*$/o;

} else {

    $name = &verify_name ($name);

}

$path = &zone_to_path ($name).'.soa';
die "\nNo SOA record for $name\n" unless -e (&zone_to_path ($name).'.soa');
print "\nSOA record for $name:\n\n";
&print_dns ($name, '.soa');
print "\n";

exit;

