+23Mar23=======================================================================
+1. Fix DXCIDR brokenness introduced recently, speeded up DXCIDR::sort, allow
+ sh/badip 2a05:dfc7:402a::1 45.134.225.96 159.69.38.160 to test individual
+ IP address as well as show the default (of every badip).
+2. Speed up and be more strict with input for is_ipaddr(<ip address>).
+22Mar23=======================================================================
+1. Fix warning in DXUtil::difft.
21Mar23=======================================================================
1. Fix DXUtil is_ipaddr function which was accidentally included in previous
commit.
my @in = split /\s+/, $line;
my $maxlth = 0;
my $width = $self->width // 80;
+my $count = 0;
#$DB::single = 1;
-my @list = map {my $s = $_; $s =~ s|/32$||; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list();
-my @l;
-$maxlth //= 20;
-my $n = int ($width/($maxlth+1));
-my $format = "\%-${maxlth}s " x $n;
-chop $format;
-
-my $count = 0;
-
-foreach my $list (@list) {
- if (@in) {
- for my $in (@in) {
- if ($list =~ /$in/i) {
- push @out, $list;
- ++$count;
- }
+# query
+if (@in) {
+ foreach my $ip (@in) {
+ if (DXCIDR::find($ip)) {
+ push @out, "$ip FOUND";
+ ++$count;
+ } else {
+ push @out, "$ip CLEAN";
}
- } else {
+ }
+ return (1, @out);
+} else {
+# list
+ my @list = map {my $s = $_; $s =~ s!/(?:32|128)$!!; $maxlth = length $s if length $s > $maxlth; $s =~ /^1$/?undef:$s} DXCIDR::list();
+ my @l;
+ $maxlth //= 20;
+ my $n = int ($width/($maxlth+1));
+ my $format = "\%-${maxlth}s " x $n;
+ chop $format;
+
+ foreach my $list (@list) {
++$count;
if (@l > $n) {
push @out, sprintf $format, @l;
@l = ();
}
push @l, $list;
- }
-}
-unless (@in) {
+ }
push @l, "" while @l < $n;
push @out, sprintf $format, @l;
}
next unless is_ipaddr($ip);
next if $ip =~ /^127\./;
next if $ip =~ /^::1$/;
- next if find($ip);
+# next if find($ip);
if ($ip =~ /\./) {
eval {$ipv4->add_any($ip)};
if ($@) {
{
my @in;
my @out;
- for (@_) {
- my @ip = split m|/|;
- push @in, [inet_pton(m|:|?AF_INET6:AF_INET, $ip[0]), @ip];
+ my $c;
+ for my $i (@_) {
+ my @s;
+
+ my @ip = split m|/|, $i;
+ if ($ip[0] =~ /:/) {
+ @s = map{$_ ? hex($_) : 0} split /:/, $ip[0];
+ } else {
+ @s = map{$_ ? $_+0 : 0} split /\./, $ip[0];
+ }
+ while (@s < 8) {
+ push @s, 0;
+ }
+# my $s = pack "S*", reverse @s;
+ my $s = pack "n*", @s;
+# my $s = join ':', map {sprintf "%04d:", $_} @s;
+# push @in, [inet_pton(m|:|?AF_INET6:AF_INET, $ip[0]), @ip];
+ push @in, [$s, @ip];
}
- @out = sort {$a->[0] <=> $b->[0]} @in;
+ @out = sort {$a->[0] cmp $b->[0]} @in;
+# @out = sort {$a->[0] <=> $b->[0]} @in;
return map { "$_->[1]/$_->[2]"} @out;
}
$d2r = ($pi/180);
$r2d = (180/$pi);
+our $ptonok;
+
+BEGIN {
+ $ptonok = !defined inet_pton(AF_INET, '016.17.184.1')
+ && !defined inet_pton(AF_INET6, '2067::1:')
+ # Some old versions of Socket are hopelessly broken
+ && length(inet_pton(AF_INET, '1.1.1.1')) == 4;
+}
# a full time for logging and other purposes
sub atime
# is it an ip address?
sub is_ipaddr
{
-
- if ($_[0] =~ /:/) {
- if (inet_pton(AF_INET6, $_[0])) {
- return ($_[0] =~ /([:0-9a-f]+)/);
+ if ($ptonok) {
+ if ($_[0] =~ /:/) {
+ if (inet_pton(AF_INET6, $_[0])) {
+ return ($_[0] =~ /([:0-9a-f]+)/);
+ }
+ } else {
+ if (inet_pton(AF_INET, $_[0])) {
+ return ($_[0] =~ /([\.\d]+)/);
+ }
}
-# use re 'debug';
-# return ($1) if $_[0] =~ /^(\:?(?:\:?[0-9a-f]{1,4}){1,8}?)$/i;
-# no re 'debug';
} else {
- return ($_[0] =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
+ if ($_[0] =~ /:/) {
+ return ($_[0] =~ /^(:?:?(?:[0-9a-f]{1,4}\:)?(?:\:[0-9a-f]{1,4}(?:\:\:)?){1,8})$/i);
+ } else {
+ return ($_[0] =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
+ }
}
return undef;
}
sub difft
{
my $b = shift;
- my $adds = shift;
+ my $adds = shift // 0;
my $t;
if (ref $b eq 'ARRAY') {