sub append
{
+ return 0 unless $active;
+
my $suffix = shift;
my @in = @_;
my @out;
if ($suffix) {
my $fn = _fn() . ".$suffix";
- my $r = rand;
- my $fh = IO::File->new (">>$fn.$r");
- if ($fh) {
+ my $fh = IO::File->new;
+ if ($fh->open("$fn", "a+")) {
+ $fh->seek(0, 2); # belt and braces !!
print $fh "$_\n" for @in;
$fh->close;
- move "$fn.$r", $fn;
} else {
- LogDbg('err', "DXCIDR::append error appending to $fn.$r $!");
+ LogDbg('err', "DXCIDR::append error appending to $fn $!");
}
} else {
LogDbg('err', "DXCIDR::append require badip suffix");
sub add
{
+ return 0 unless $active;
my $count = 0;
for my $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;