{

    use esmith::HostsDB;
    $hosts = esmith::HostsDB->open_ro;

    use esmith::DomainsDB;
    my $ddb = esmith::DomainsDB->open_ro;

    use esmith::util;

    #--------------------------------------------------------
    # Returns a hash of hostnames with IP addresses as values
    #--------------------------------------------------------

    sub get_generic_hostentries 
    {
        #--------------------------------------------------
        # Compute local IP address, netmask and network values.
        #--------------------------------------------------

        my $ipaddrBits  = esmith::util::IPquadToAddr ($LocalIP);
        my $netmaskBits = esmith::util::IPquadToAddr ($LocalNetmask);
        my $networkBits = $ipaddrBits & $netmaskBits;

        #--------------------------------------------------
        # Compute our hostid, and the highest hostid, limiting range
        # to a class B at most (so we don't get a huge output file).
        #--------------------------------------------------

        my $myHostid = (~ $netmaskBits) & $ipaddrBits;

        my $maxHostid = ((~ $netmaskBits) & 0xffffff) - 1;
        $maxHostid = ($maxHostid <= 65534) ? $maxHostid : 65534;

        my %name2ip;
        #--------------------------------------------------
        # Generate A records for the entire local network
        # We can then override particular entries if we need to
        # However, multiple A records are not an issue
        # as long as there is a PTR record pointing to the correct
        # hostname
        #--------------------------------------------------

        for ($i = 1; $i <= $maxHostid; $i++)
        {
            my $ip = esmith::util::IPaddrToQuad ($networkBits | $i);
            my $hostname = sprintf ("pc-%.5d", $i);

            $name2ip{$hostname} = $ip;
        }

        return %name2ip;
    }

    #--------------------------------------------------------
    # Calculates an array of domains that require DNS
    #--------------------------------------------------------
    @domains = map { $_->key } $ddb->get_all_by_prop('type' => 'domain');

    #--------------------------------------------------------
    # Returns an array of domains that require DNS
    #--------------------------------------------------------
    sub get_domains { return @domains; }

    sub get_local_domainname { return $DomainName; }


    #--------------------------------------------------------
    # Returns the IP Address of the host in question.
    #--------------------------------------------------------
    sub host2ip
    {
        my $host = shift;
        my $ip = undef;
        die "Host record must have HostType prop!"
            unless my $hosttype = $host->prop('HostType');

        if ($hosttype eq 'Self')
        {
            $ip = $LocalIP;
        }
        $ip ||= $host->prop('ExternalIP') || $host->prop('InternalIP');
        return $ip;
    }

    #--------------------------------------------------------
    # Returns a hash of IPs to hostnames, representing the 
    # chosen hostnames for reverse dns lookups for each IP.
    #--------------------------------------------------------
    sub get_reverse_lookup_choices
    {
        my %reverse_lookups = ();
        foreach my $host ($hosts->hosts())
        {
            # A remote host must be a DNS alias. 
            next if $host->prop('HostType') eq 'Remote';

            my $alias = $host->prop('ReverseDNS') || "no";
            if ($alias eq "yes")
            {
                # This host is not a DNS alias, so we should make note of it
                # for reverse DNS lookup purposes.
                my $ip = host2ip($host);
                $reverse_lookups{$ip} = $host->{key};
                # Note: Here we clobber any existing key/value pair, so if
                # there is more than one host with the same ip flagged as
                # being the reversedns host, the last one entered in this hash
                # will win. Don't do that. ;-)
            }
        }
        return %reverse_lookups;
    }

    $OUT = '';
}
