Skip to content
Snippets Groups Projects
Commit b725a9da authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Merge branch 'netipfix-0.0.x' into 'v0.0.x'

Fixed warning for v0.0.x usage of Socket* modules

See merge request !16
parents fd19a8ca 8c2944a7
No related branches found
No related tags found
1 merge request!16Fixed warning for v0.0.x usage of Socket* modules
...@@ -29,16 +29,8 @@ package awitpt::netip; ...@@ -29,16 +29,8 @@ package awitpt::netip;
use strict; use strict;
use warnings; use warnings;
use Socket; use Socket qw(inet_aton);
BEGIN { use Socket6 qw(inet_pton AF_INET6);
if (defined &Socket::inet_pton) {
Socket->import(qw(inet_pton AF_INET6));
} else {
require Socket6;
Socket6->import(qw(inet_pton AF_INET6));
}
};
# Our current error message # Our current error message
my $error = ""; my $error = "";
...@@ -197,7 +189,7 @@ sub to_network ...@@ -197,7 +189,7 @@ sub to_network
sub _cidr2mask_v4 { sub _cidr2mask_v4 {
my $self = shift; my $self = shift;
return pack "N", 0xffffffff << (32 - $self->{'cidr'}); return pack "N", 0xffffffff << (32 - $self->{'cidr'});
} }
...@@ -205,27 +197,29 @@ sub _cidr2mask_v4 { ...@@ -205,27 +197,29 @@ sub _cidr2mask_v4 {
sub _cidr2mask_v6 { sub _cidr2mask_v6 {
my $self = shift; my $self = shift;
return pack('B128', '1' x $self->{'cidr'}); return pack('B128', '1' x $self->{'cidr'});
} }
# Function to match an v4 address # Function to match an v4 address
sub _ipv4_matcher { sub _ipv4_matcher {
no locale;
my ($self,$test) = @_; my ($self,$test) = @_;
my $mask = $test->_cidr2mask_v4(); my $mask = $test->_cidr2mask_v4();
return ((inet_aton($test->{'ip'}) & $mask) eq (inet_aton($self->{'ip'}) & $mask)); return ((inet_aton($test->{'ip'}) & $mask) eq (inet_aton($self->{'ip'}) & $mask)) ? 1 : 0;
} }
# Function to match an v6 address # Function to match an v6 address
sub _ipv6_matcher { sub _ipv6_matcher {
no locale;
my ($self,$test) = @_; my ($self,$test) = @_;
my $mask = $test->_cidr2mask_v6(); my $mask = $test->_cidr2mask_v6();
return ((inet_pton(AF_INET6,$test->{'ip'}) & $mask) eq (inet_pton(AF_INET6, $self->{'ip'}) & $mask)); return ((inet_pton(AF_INET6,$test->{'ip'}) & $mask) eq (inet_pton(AF_INET6, $self->{'ip'}) & $mask)) ? 1 : 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment