add load/badip.pl
[spider.git] / perl / DXCIDR.pm
index 506b9693ed9e54c49f2d8d3425ba4c2e62c7f10e..2ef0d1937954dccd2f004bd5777e72a9da773e92 100644 (file)
@@ -16,7 +16,7 @@ use DXUtil;
 use DXLog;
 use IO::File;
 use File::Copy;
-use Socket qw(inet_pton inet_ntop);
+use Socket qw(AF_INET AF_INET6 inet_pton inet_ntop);
 
 our $active = 0;
 our $badipfn = "badip";
@@ -85,6 +85,8 @@ sub _put
 
 sub add
 {
+       my $count = 0;
+       
        for my $ip (@_) {
                # protect against stupid or malicious
                next if /^127\./;
@@ -95,6 +97,7 @@ sub add
                                next;
                        } 
                        $ipv4->add_any($ip);
+                       ++$count;
                        ++$count4;
                } elsif (/:/) {
                        if ($ipv6->find($ip)) {
@@ -102,6 +105,7 @@ sub add
                                next;
                        } 
                        $ipv6->add_any($ip);
+                       ++$count;
                        ++$count6;
                        LogDbg('DXProt', "DXCIDR: Added IPV6 $ip address");
                }
@@ -114,6 +118,7 @@ sub add
                $ipv6->prep_find;
                _put($ipv6, 6);
        }
+       return $count;
 }
 
 sub save
@@ -128,7 +133,7 @@ sub _sort
        my @in;
        my @out;
        for (@_) {
-               push @in, [inet_pton($_), split m|/|];
+               push @in, [inet_pton(m|:|?AF_INET6:AF_INET, $_), split m|/|];
        }
        @out = sort {$a->[0] <=> $b->[0]} @in;
        return map { "$_->[1]/$_->[2]"} @out;