Email-Abuse-Investigator
view release on metacpan or search on metacpan
lib/Email/Abuse/Investigator.pm view on Meta::CPAN
# Entry criteria:
# $ip -- a defined dotted-quad IPv4 address string.
# $cidr -- a CIDR string like '10.0.0.0/8' or an exact IP.
#
# Exit status:
# Returns 1 (true) if the IP is within the CIDR block, 0 otherwise.
sub _ip_in_cidr :Private {
my ($self, $ip, $cidr) = @_;
return $ip eq $cidr unless $cidr =~ m{/};
my ($net_addr, $prefix) = split m{/}, $cidr;
return 0 if !defined($prefix) || $prefix !~ /^\d+$/ || $prefix > 32;
# Compute the network mask and compare masked network addresses
my $mask = ~0 << (32 - $prefix);
my $net_n = unpack 'N', (inet_aton($net_addr) // return 0);
my $ip_n = unpack 'N', (inet_aton($ip) // return 0);
return ($ip_n & $mask) == ($net_n & $mask);
}
# _decode_mime_words( $str ) -> decoded_string
( run in 2.262 seconds using v1.01-cache-2.11-cpan-71847e10f99 )