Skip to content

Commit

Permalink
converted from Net::AddrIPv4 to the excellent NetAddr::IP module
Browse files Browse the repository at this point in the history
  • Loading branch information
mrash committed Feb 18, 2012
1 parent 7a7e465 commit 95a39ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Perl modules:
fwsnort requires two perl modules in order to run properly:

IPTables::Parse
Net-IPv4Addr
NetAddr::IP

These two modules are bundled with fwsnort within the deps/ directory, unless
you have downloaded the fwsnort-nodeps tarball, in which case these two
Expand Down
32 changes: 16 additions & 16 deletions fwsnort
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# Version: 1.6.1
#
# Copyright (C) 2003-2011 Michael Rash (mbr@cipherdyne.org)
# Copyright (C) 2003-2012 Michael Rash (mbr@cipherdyne.org)
#
# License - GNU Public License version 2 (GPLv2):
#
Expand Down Expand Up @@ -1385,6 +1385,9 @@ sub match_addr() {
my $ipt_mask = '32';
my $negate = 0;

my $s_obj = '';
my $ipt_obj = '';

$negate = 1 if $hdr_src =~ /\!/;

if ($rule_src =~ /\!/) {
Expand All @@ -1407,6 +1410,8 @@ sub match_addr() {
$ipt_ip = $1;
}

$ipt_obj = new NetAddr::IP($ipt_ip, $ipt_mask);

for my $addr (@{&expand_addresses($hdr_src)}) {
my $src_ip = '';
my $src_mask = '32';
Expand All @@ -1419,17 +1424,11 @@ sub match_addr() {
} elsif ($addr =~ m|($ip_re)|) {
$src_ip = $1;
}
# return 1 if ipv4_in_network(
# $ipt_ip, $ipt_mask,
# $src_ip, $src_mask);
$s_obj = new NetAddr::IP($src_ip, $src_mask);
if ($negate) {
return 1 unless ipv4_in_network(
$src_ip, $src_mask,
$ipt_ip, $ipt_mask);
return 1 unless $ipt_obj->within($s_obj);
} else {
return 1 if ipv4_in_network(
$src_ip, $src_mask,
$ipt_ip, $ipt_mask);
return 1 if $ipt_obj->within($s_obj);
}
}
return 0;
Expand Down Expand Up @@ -1690,6 +1689,7 @@ sub is_local() {

my $ip = '';
my $mask = '32';

if ($addr =~ m|($ip_re)/($ip_re)|) {
$ip = $1;
$mask = $2;
Expand All @@ -1700,13 +1700,15 @@ sub is_local() {
$ip = $1;
}

my $ip_obj = new NetAddr::IP($ip, $mask);

for my $local_ar (@local_addrs) {
my $local_ip = $local_ar->[0];
my $local_mask = $local_ar->[1];

return 1 if ipv4_in_network(
$local_ip, $local_mask,
$ip, $mask);
my $local_obj = new NetAddr::IP($local_ip, $local_mask);

return 1 if $ip_obj->within($local_obj);
}
return 0;
}
Expand Down Expand Up @@ -4141,9 +4143,7 @@ sub import_perl_modules() {
}

require IPTables::Parse;
require Net::IPv4Addr;

Net::IPv4Addr->import(qw/ipv4_in_network/);
require NetAddr::IP;

return;
}
Expand Down
4 changes: 2 additions & 2 deletions install.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@

### map perl modules to versions
my %required_perl_modules = (
'Net::IPv4Addr' => {
'NetAddr::IP' => {
'force-install' => 0,
'mod-dir' => 'Net-IPv4Addr'
'mod-dir' => 'NetAddr-IP'
},
'IPTables::Parse' => {
'force-install' => 1,
Expand Down

0 comments on commit 95a39ee

Please sign in to comment.