$fn .= ".$suffix" if $suffix;
my $fh = IO::File->new($fn);
my @out;
+ my $ecount;
+ my $line;
+
if ($fh) {
while (<$fh>) {
chomp;
+ ++$line;
next if /^\s*\#/;
next unless /[\.:]/;
+ next unless $_;
+ unless (is_ipaddr($_)) {
+ ++$ecount;
+ LogDbg('err', qq(DXCIDR: $fn line $line: '$_' not an ip address));
+ if ($ecount > 10) {
+ LogDbg('err', qq(DXCIDR: More than 10 errors in $fn at/after line $line: '$_' - INVALID INPUT FILE));
+ return ();
+ }
+ }
push @out, $_;
}
$fh->close;
{
my $suffix = shift;
my @in = _read($suffix);
+ return 0 unless @in;
return scalar add(@in);
}
sub append
{
+ return 0 unless $active;
+
my $suffix = shift;
my @in = @_;
my @out;
sub add
{
+ return 0 unless $active;
my $count = 0;
for my $ip (@_) {
# protect against stupid or malicious
+ next unless is_ipaddr($ip);
next if $ip =~ /^127\./;
next if $ip =~ /^::1$/;
if ($ip =~ /\./) {
sub clean_prep
{
+ return unless $active;
+
if ($ipv4 && $count4) {
$ipv4->clean;
$ipv4->prep_find;
sub list
{
+ return () unless $active;
my @out;
push @out, $ipv4->list if $count4;
push @out, $ipv6->list if $count6;
sub reload
{
+ return 0 unless $active;
+
new();
my $count = 0;
sub new
{
+ return 0 unless $active;
+
$ipv4 = Net::CIDR::Lite->new;
$ipv6 = Net::CIDR::Lite->new;
$count4 = $count6 = 0;