r48978 - in /branches/upstream/libnet-subnets-perl/current: ./ examples/ lib/Net/ t/
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Sat Dec 19 00:29:21 UTC 2009
Author: jawnsy-guest
Date: Sat Dec 19 00:29:14 2009
New Revision: 48978
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=48978
Log:
[svn-upgrade] Integrating new upstream version, libnet-subnets-perl (1.0)
Added:
branches/upstream/libnet-subnets-perl/current/.perltidyrc
branches/upstream/libnet-subnets-perl/current/LICENSE
branches/upstream/libnet-subnets-perl/current/examples/
branches/upstream/libnet-subnets-perl/current/examples/matching.pl
branches/upstream/libnet-subnets-perl/current/t/01use.t
branches/upstream/libnet-subnets-perl/current/t/02pod.t
branches/upstream/libnet-subnets-perl/current/t/03podcoverage.t
branches/upstream/libnet-subnets-perl/current/t/04check.t
branches/upstream/libnet-subnets-perl/current/t/05range.t
branches/upstream/libnet-subnets-perl/current/t/06list.t
Removed:
branches/upstream/libnet-subnets-perl/current/t/1use.t
branches/upstream/libnet-subnets-perl/current/t/2check.t
branches/upstream/libnet-subnets-perl/current/t/3range.t
branches/upstream/libnet-subnets-perl/current/t/4list.t
Modified:
branches/upstream/libnet-subnets-perl/current/Changes
branches/upstream/libnet-subnets-perl/current/MANIFEST
branches/upstream/libnet-subnets-perl/current/META.yml
branches/upstream/libnet-subnets-perl/current/Makefile.PL
branches/upstream/libnet-subnets-perl/current/README
branches/upstream/libnet-subnets-perl/current/lib/Net/Subnets.pm
Added: branches/upstream/libnet-subnets-perl/current/.perltidyrc
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/.perltidyrc?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/.perltidyrc (added)
+++ branches/upstream/libnet-subnets-perl/current/.perltidyrc Sat Dec 19 00:29:14 2009
@@ -1,0 +1,35 @@
+# Perl Best Practices (plus errata) .perltidyrc file
+
+-l=98 # Max line width is 98 cols
+-i=4 # Indent level is 4 cols
+-ci=4 # Continuation indent is 4 cols
+#-st # Output to STDOUT
+-se # Errors to STDERR
+-vt=2 # Maximal vertical tightness
+-cti=0 # No extra indentation for closing brackets
+-pt=1 # Medium parenthesis tightness
+-bt=1 # Medium brace tightness
+-sbt=1 # Medium square bracket tightness
+-bbt=1 # Medium block brace tightness
+-nsfs # No space before semicolons
+-nolq # Don't outdent long quoted strings
+-wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
+ # Break before all operators
+
+# extras/overrides/deviations from PBP
+
+--maximum-line-length=78 # be less generous
+--warning-output # Show warnings
+--maximum-consecutive-blank-lines=2 # default is 1
+--nohanging-side-comments # troublesome for commented out code
+
+-isbc # block comments may only be indented if they have some space characters before the #
+-ci=2 # Continuation indent is 2 cols
+
+# we use version control, so just rewrite the file
+-b
+
+# for the up-tight folk :)
+-pt=2 # High parenthesis tightness
+-bt=2 # High brace tightness
+-sbt=2 # High square bracket tightness
Modified: branches/upstream/libnet-subnets-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/Changes?rev=48978&op=diff
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/Changes (original)
+++ branches/upstream/libnet-subnets-perl/current/Changes Sat Dec 19 00:29:14 2009
@@ -1,52 +1,43 @@
Revision history for Perl extension Net::Subnets.
-0.21 Sat Feb 19 21:00:00 2005
- - fixed pod (Jan Harders)
+1.0 2009-12-10 00:00:00
+ - Fixed everything.
-0.20 Sun Nov 16 16:00:00 2003
+0.21 2009-02-19 00:00:00
+ - Fixed pod. (Jan Harders)
- - added list() function
- - better documentation
+0.20 2003-11-16 00:00:00
+ - Added list() function.
+ - Better documentation.
-0.19 Wed Nov 12 11:00:00 2003
+0.19 2003-11-12 00:00:00
+ - Fixed a bug in subnets() and check() which produced false matches.
+ (Eric Johanson)
+ - Fixed the changelog.
- - fixed a bug in subnets() and check() which produced
- false matches, reported by Eric Johanson
+0.18 2003-10-13 00:00:00
+ - Fixed some typos
- - fixed the changelog
+0.17 2003-09-30 00:00:00
+ - Made the constructor inheritable. (Markus Thielmann)
-0.18 Tue Sep 30 21:30:00 2003
+0.16 2003-09-28 00:00:00
+ - Added range() function.
- - fixed some typos
+0.15 2003-09-15 00:00:00
+ - New test.
-0.17 Tue Sep 30 21:00:00 2003
+0.14 2003-09-13 00:00:00
+ - Better documentation.
- - made the constructor inheritable, reported by Markus Thielmann
+0.13 2003-09-12 00:00:00
+ - Added example.
-0.16 Sun Sep 28 22:00:00 2003
+0.12 2003-09-11 00:00:00
+ - Fixed even more typos.
- - added range() function
+0.11 2003-09-10 00:00:00
+ - Fixed some typos.
-0.15 Mon Sep 15 21:00:00 2003
-
- - new test
-
-0.14 Fri Sep 12 23:30:00 2003
-
- - better documentation
-
-0.13 Fri Sep 12 22:55:00 2003
-
- - added example
-
-0.12 Fri Sep 12 01:00:00 2003
-
- - fixed even more typos
-
-0.11 Thu Sep 12 00:00:00 2003
-
- - fixed some typos
-
-0.10 Wed Aug 27 22:00:00 2003
-
- - first public release
+0.10 2009-08-28 00:00:00
+ - first public release
Added: branches/upstream/libnet-subnets-perl/current/LICENSE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/LICENSE?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/LICENSE (added)
+++ branches/upstream/libnet-subnets-perl/current/LICENSE Sat Dec 19 00:29:14 2009
@@ -1,0 +1,201 @@
+ The Artistic License 2.0
+
+ Copyright (c) 2000-2006, The Perl Foundation.
+
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+Preamble
+
+This license establishes the terms under which a given free software
+Package may be copied, modified, distributed, and/or redistributed.
+The intent is that the Copyright Holder maintains some artistic
+control over the development of that Package while still keeping the
+Package available as open source and free software.
+
+You are always permitted to make arrangements wholly outside of this
+license directly with the Copyright Holder of a given Package. If the
+terms of this license do not permit the full use that you propose to
+make of the Package, you should contact the Copyright Holder and seek
+a different licensing arrangement.
+
+Definitions
+
+ "Copyright Holder" means the individual(s) or organization(s)
+ named in the copyright notice for the entire Package.
+
+ "Contributor" means any party that has contributed code or other
+ material to the Package, in accordance with the Copyright Holder's
+ procedures.
+
+ "You" and "your" means any person who would like to copy,
+ distribute, or modify the Package.
+
+ "Package" means the collection of files distributed by the
+ Copyright Holder, and derivatives of that collection and/or of
+ those files. A given Package may consist of either the Standard
+ Version, or a Modified Version.
+
+ "Distribute" means providing a copy of the Package or making it
+ accessible to anyone else, or in the case of a company or
+ organization, to others outside of your company or organization.
+
+ "Distributor Fee" means any fee that you charge for Distributing
+ this Package or providing support for this Package to another
+ party. It does not mean licensing fees.
+
+ "Standard Version" refers to the Package if it has not been
+ modified, or has been modified only in ways explicitly requested
+ by the Copyright Holder.
+
+ "Modified Version" means the Package, if it has been changed, and
+ such changes were not explicitly requested by the Copyright
+ Holder.
+
+ "Original License" means this Artistic License as Distributed with
+ the Standard Version of the Package, in its current version or as
+ it may be modified by The Perl Foundation in the future.
+
+ "Source" form means the source code, documentation source, and
+ configuration files for the Package.
+
+ "Compiled" form means the compiled bytecode, object code, binary,
+ or any other form resulting from mechanical transformation or
+ translation of the Source form.
+
+
+Permission for Use and Modification Without Distribution
+
+(1) You are permitted to use the Standard Version and create and use
+Modified Versions for any purpose without restriction, provided that
+you do not Distribute the Modified Version.
+
+
+Permissions for Redistribution of the Standard Version
+
+(2) You may Distribute verbatim copies of the Source form of the
+Standard Version of this Package in any medium without restriction,
+either gratis or for a Distributor Fee, provided that you duplicate
+all of the original copyright notices and associated disclaimers. At
+your discretion, such verbatim copies may or may not include a
+Compiled form of the Package.
+
+(3) You may apply any bug fixes, portability changes, and other
+modifications made available from the Copyright Holder. The resulting
+Package will still be considered the Standard Version, and as such
+will be subject to the Original License.
+
+
+Distribution of Modified Versions of the Package as Source
+
+(4) You may Distribute your Modified Version as Source (either gratis
+or for a Distributor Fee, and with or without a Compiled form of the
+Modified Version) provided that you clearly document how it differs
+from the Standard Version, including, but not limited to, documenting
+any non-standard features, executables, or modules, and provided that
+you do at least ONE of the following:
+
+ (a) make the Modified Version available to the Copyright Holder
+ of the Standard Version, under the Original License, so that the
+ Copyright Holder may include your modifications in the Standard
+ Version.
+
+ (b) ensure that installation of your Modified Version does not
+ prevent the user installing or running the Standard Version. In
+ addition, the Modified Version must bear a name that is different
+ from the name of the Standard Version.
+
+ (c) allow anyone who receives a copy of the Modified Version to
+ make the Source form of the Modified Version available to others
+ under
+
+ (i) the Original License or
+
+ (ii) a license that permits the licensee to freely copy,
+ modify and redistribute the Modified Version using the same
+ licensing terms that apply to the copy that the licensee
+ received, and requires that the Source form of the Modified
+ Version, and of any works derived from it, be made freely
+ available in that license fees are prohibited but Distributor
+ Fees are allowed.
+
+
+Distribution of Compiled Forms of the Standard Version
+or Modified Versions without the Source
+
+(5) You may Distribute Compiled forms of the Standard Version without
+the Source, provided that you include complete instructions on how to
+get the Source of the Standard Version. Such instructions must be
+valid at the time of your distribution. If these instructions, at any
+time while you are carrying out such distribution, become invalid, you
+must provide new instructions on demand or cease further distribution.
+If you provide valid instructions or cease distribution within thirty
+days after you become aware that the instructions are invalid, then
+you do not forfeit any of your rights under this license.
+
+(6) You may Distribute a Modified Version in Compiled form without
+the Source, provided that you comply with Section 4 with respect to
+the Source of the Modified Version.
+
+
+Aggregating or Linking the Package
+
+(7) You may aggregate the Package (either the Standard Version or
+Modified Version) with other packages and Distribute the resulting
+aggregation provided that you do not charge a licensing fee for the
+Package. Distributor Fees are permitted, and licensing fees for other
+components in the aggregation are permitted. The terms of this license
+apply to the use and Distribution of the Standard or Modified Versions
+as included in the aggregation.
+
+(8) You are permitted to link Modified and Standard Versions with
+other works, to embed the Package in a larger work of your own, or to
+build stand-alone binary or bytecode versions of applications that
+include the Package, and Distribute the result without restriction,
+provided the result does not expose a direct interface to the Package.
+
+
+Items That are Not Considered Part of a Modified Version
+
+(9) Works (including, but not limited to, modules and scripts) that
+merely extend or make use of the Package, do not, by themselves, cause
+the Package to be a Modified Version. In addition, such works are not
+considered parts of the Package itself, and are not subject to the
+terms of this license.
+
+
+General Provisions
+
+(10) Any use, modification, and distribution of the Standard or
+Modified Versions is governed by this Artistic License. By using,
+modifying or distributing the Package, you accept this license. Do not
+use, modify, or distribute the Package, if you do not accept this
+license.
+
+(11) If your Modified Version has been derived from a Modified
+Version made by someone other than you, you are nevertheless required
+to ensure that your Modified Version complies with the requirements of
+this license.
+
+(12) This license does not grant you the right to use any trademark,
+service mark, tradename, or logo of the Copyright Holder.
+
+(13) This license includes the non-exclusive, worldwide,
+free-of-charge patent license to make, have made, use, offer to sell,
+sell, import and otherwise transfer the Package with respect to any
+patent claims licensable by the Copyright Holder that are necessarily
+infringed by the Package. If you institute patent litigation
+(including a cross-claim or counterclaim) against any party alleging
+that the Package constitutes direct or contributory patent
+infringement, then this Artistic License to you shall terminate on the
+date that such litigation is filed.
+
+(14) Disclaimer of Warranty:
+THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
+IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
+LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Modified: branches/upstream/libnet-subnets-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/MANIFEST?rev=48978&op=diff
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/MANIFEST (original)
+++ branches/upstream/libnet-subnets-perl/current/MANIFEST Sat Dec 19 00:29:14 2009
@@ -1,10 +1,15 @@
+.perltidyrc
Changes
+examples/matching.pl
lib/Net/Subnets.pm
+LICENSE
Makefile.PL
MANIFEST This list of files
-META.yml
README
-t/1use.t
-t/2check.t
-t/3range.t
-t/4list.t
+t/01use.t
+t/02pod.t
+t/03podcoverage.t
+t/04check.t
+t/05range.t
+t/06list.t
+META.yml Module meta-data (added by MakeMaker)
Modified: branches/upstream/libnet-subnets-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/META.yml?rev=48978&op=diff
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/META.yml (original)
+++ branches/upstream/libnet-subnets-perl/current/META.yml Sat Dec 19 00:29:14 2009
@@ -1,10 +1,26 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
-name: Net-Subnets
-version: 0.21
-version_from: lib/Net/Subnets.pm
-installdirs: site
+--- #YAML:1.0
+name: Net-Subnets
+version: 1.0
+abstract: ~
+author:
+ - Sebastian Riedel (sri at cpan.org)
+license: artistic_2
+distribution_type: module
+configure_requires: {}
+build_requires: {}
requires:
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+ ExtUtils::MakeMaker: 0
+ perl: 5.008001
+ Test::More: 0
+resources:
+ license: http://dev.perl.org/licenses/
+ repository: http://github.com/kraih/net-subnets/tree/master
+no_index:
+ directory:
+ - t
+ - inc
+ - t
+generated_by: ExtUtils::MakeMaker version 6.55_02
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Modified: branches/upstream/libnet-subnets-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/Makefile.PL?rev=48978&op=diff
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/Makefile.PL (original)
+++ branches/upstream/libnet-subnets-perl/current/Makefile.PL Sat Dec 19 00:29:14 2009
@@ -1,7 +1,40 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
use ExtUtils::MakeMaker;
+my $mm = $ExtUtils::MakeMaker::VERSION;
+
+# Son, when you participate in sporting events,
+# it's not whether you win or lose, it's how drunk you get.
WriteMakefile(
NAME => 'Net::Subnets',
- AUTHOR => 'Sebastian Riedel (sri at oook.de)',
+ AUTHOR => 'Sebastian Riedel (sri at cpan.org)',
VERSION_FROM => 'lib/Net/Subnets.pm',
+
+ ($mm < 6.3002 ? () : ('LICENSE' => 'artistic_2')),
+
+ ( $mm < 6.46
+ ? ()
+ : ( META_MERGE => {
+ requires => {perl => '5.008001'},
+ resources => {
+ license => 'http://dev.perl.org/licenses/',
+ repository =>
+ 'http://github.com/kraih/net-subnets/tree/master'
+ },
+ no_index => {directory => [qw/t/]}
+ },
+ META_ADD => {
+ build_requires => {},
+ configure_requires => {}
+ },
+ )
+ ),
+
+ PREREQ_PM => {'ExtUtils::MakeMaker' => 0, 'Test::More' => 0}
);
Modified: branches/upstream/libnet-subnets-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/README?rev=48978&op=diff
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/README (original)
+++ branches/upstream/libnet-subnets-perl/current/README Sat Dec 19 00:29:14 2009
@@ -1,21 +1,8 @@
-Net/Subnets version 0.20
-========================
-
-Very fast matches large lists of IP addresses against many CIDR subnets,
-calculates IP address ranges and provides a simple object oriented interface.
-
-INSTALLATION
+Computing Subnets In Large Scale Networks.
To install this module type the following:
- perl Makefile.PL
- make
- make test
- make install
-
-COPYRIGHT AND LICENCE
-
-Copyright (C) 2003 Sebastian Riedel & Juergen Peters. All rights reserved.
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+ perl Makefile.PL
+ make
+ make test
+ make install
Added: branches/upstream/libnet-subnets-perl/current/examples/matching.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/examples/matching.pl?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/examples/matching.pl (added)
+++ branches/upstream/libnet-subnets-perl/current/examples/matching.pl Sat Dec 19 00:29:14 2009
@@ -1,0 +1,21 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
+use Net::Subnets;
+
+my @subnets = qw(10.0.0.0/24 10.0.1.0/24);
+my @addresses = qw/10.0.0.1 10.0.1.2 10.0.3.1/;
+
+my $sn = Net::Subnets->new;
+$sn->subnets(\@subnets);
+my $results;
+foreach my $address (@addresses) {
+ if (my $subnetref = $sn->check(\$address)) {
+ $results .= "$address: $$subnetref\n";
+ }
+ else {
+ $results .= "$address: not found\n";
+ }
+}
+print($results);
Modified: branches/upstream/libnet-subnets-perl/current/lib/Net/Subnets.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/lib/Net/Subnets.pm?rev=48978&op=diff
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/lib/Net/Subnets.pm (original)
+++ branches/upstream/libnet-subnets-perl/current/lib/Net/Subnets.pm Sat Dec 19 00:29:14 2009
@@ -1,68 +1,64 @@
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
package Net::Subnets;
use strict;
-use vars qw($VERSION);
+use vars qw/$VERSION/;
-$VERSION = '0.21';
+$VERSION = '1.0';
sub new {
my $self = shift;
- return bless( {}, ( ref($self) || $self ) );
+ return bless({}, (ref($self) || $self));
}
sub subnets {
- my ( $self, $subnets ) = @_;
+ my ($self, $subnets) = @_;
my %masks;
foreach (@$subnets) {
/^(.+?)\/(.+)$/o;
- my $revmask = 32 - ( $2 || 32 );
+ my $revmask = 32 - ($2 || 32);
$self->{subnets}{$revmask}
- { unpack( "N", pack( "C4", split( /\./, $1 ) ) ) >> $revmask } = $_;
+ {unpack("N", pack("C4", split(/\./, $1))) >> $revmask} = $_;
$masks{$revmask}++;
}
- @{ $self->{masks} } =
- sort( { $masks{$a} <=> $masks{$b} } keys(%masks) );
+ @{$self->{masks}} =
+ sort({$masks{$a} <=> $masks{$b}} keys(%masks));
}
sub check {
- my ( $self, $address ) = @_;
- foreach ( @{ $self->{masks} } ) {
- my $option =
- unpack( "N", pack( "C4", split( /\./, $$address ) ) ) >> $_;
- if ( $self->{subnets}{$_}{$option} ) {
- return \( $self->{subnets}{$_}{$option} );
+ my ($self, $address) = @_;
+ foreach (@{$self->{masks}}) {
+ my $option = unpack("N", pack("C4", split(/\./, $$address))) >> $_;
+ if ($self->{subnets}{$_}{$option}) {
+ return \($self->{subnets}{$_}{$option});
}
}
return 0;
}
sub range {
- my ( $self, $subnet ) = @_;
+ my ($self, $subnet) = @_;
$$subnet =~ /^(.+?)\/(.+)$/o;
my $net =
- pack( 'C4', split( /\./, $1 ) ) &
- pack( 'B*', ( 1 x $2 ) . ( 0 x ( 32 - ( $2 || 32 ) ) ) );
- my $lowip =
- join( '.', unpack( 'C4', pack( 'B*', ( 0 x 31 ) . 1 ) | $net ) );
- my $highip = join(
- '.',
- unpack(
- 'C4', pack( 'B*', ( 0 x $2 ) . ( 1 x ( 31 - $2 ) ) . 0 ) | $net
- )
- );
- if ( $2 == 32 ) {
- return ( \$highip, \$highip );
+ pack('C4', split(/\./, $1))
+ & pack('B*', (1 x $2) . (0 x (32 - ($2 || 32))));
+ my $lowip = join('.', unpack('C4', pack('B*', (0 x 31) . 1) | $net));
+ my $highip = join('.',
+ unpack('C4', pack('B*', (0 x $2) . (1 x (31 - $2)) . 0) | $net));
+ if ($2 == 32) {
+ return (\$highip, \$highip);
}
- return ( \$lowip, \$highip );
+ return (\$lowip, \$highip);
}
sub list {
- my ( $self, $lowip, $highip ) = @_;
- my $lowint = unpack( "N", pack( "C4", split( /\./, $$lowip ) ) );
- my $highint = unpack( "N", pack( "C4", split( /\./, $$highip ) ) );
- my @list = ( join( '.', unpack( 'C4', pack( 'N', $lowint ) ) ) );
- while ( $lowint lt $highint ) {
- push( @list, join( '.', unpack( 'C4', pack( 'N', ++$lowint ) ) ) );
+ my ($self, $lowip, $highip) = @_;
+ my $lowint = unpack("N", pack("C4", split(/\./, $$lowip)));
+ my $highint = unpack("N", pack("C4", split(/\./, $$highip)));
+ my @list = (join('.', unpack('C4', pack('N', $lowint))));
+ while ($lowint lt $highint) {
+ push(@list, join('.', unpack('C4', pack('N', ++$lowint))));
}
return \@list;
}
@@ -72,71 +68,43 @@
=head1 NAME
-Net::Subnets - Computing subnets in large scale networks
+Net::Subnets - Computing Subnets In Large Scale Networks
=head1 SYNOPSIS
use Net::Subnets;
my $sn = Net::Subnets->new;
- $sn->subnets( \@subnets );
- if ( my $subnetref = $sn->check( \$address ) ) {
+ $sn->subnets(\@subnets);
+ if (my $subnetref = $sn->check(\$address)) {
...
}
- my ( $lowipref, highipref ) = $sn->range( \$subnet );
- my $listref = $sn->list( \( $lowipref, $highipref ) );
+ my ($lowipref, highipref) = $sn->range(\$subnet);
+ my $listref = $sn->list(\($lowipref, $highipref));
=head1 DESCRIPTION
Very fast matches large lists of IP addresses against many CIDR subnets and
calculates IP address ranges.
-The following functions are provided by this module:
-
- new()
- Creates an "Net::Subnets" object.
- It takes no arguments.
-
- subnets( \@subnets )
- The subnets() function lets you prepare a list of CIDR subnets.
- It takes an array reference.
-
- check( \$address )
- The check() function lets you check an IP address against the
- previously prepared subnets.
- It takes a scalar reference and returns a scalar reference to
- the first matching CIDR subnet.
-
- range( \$subnet )
- The range() function lets you calculate the IP address range
- of a subnet.
- It takes a scalar reference and returns two scalar references to
- the lowest and highest IP address.
-
- list( \$lowip, \$highip )
- The list() function lets you calculate a list containing all IP
- addresses in a given range.
- It takes two scalar references and returns a reference to a list
- containing the IP addresses.
-
This is a simple and efficient example for subnet matching:
use Net::Subnets;
my @subnets = qw(10.0.0.0/24 10.0.1.0/24);
- my @addresses = qw(10.0.0.1 10.0.1.2 10.0.3.1);
+ my @addresses = qw/10.0.0.1 10.0.1.2 10.0.3.1/;
my $sn = Net::Subnets->new;
- $sn->subnets( \@subnets );
+ $sn->subnets(\@subnets);
my $results;
- foreach my $address ( @addresses ) {
- if ( my $subnetref = $sn->check( \$address ) ) {
+ foreach my $address (@addresses) {
+ if (my $subnetref = $sn->check(\$address)) {
$results .= "$address: $$subnetref\n";
}
else {
$results .= "$address: not found\n";
}
}
- print( $results );
+ print($results);
This is a simple example for range calculation:
@@ -146,8 +114,8 @@
my $sn = Net::Subnets->new;
my $results;
- foreach my $subnet ( @subnets ) {
- my ( $lowipref, $highipref ) = $sn->range( \$subnet );
+ foreach my $subnet (@subnets) {
+ my ($lowipref, $highipref) = $sn->range(\$subnet);
$results .= "$subnet: $$lowipref - $$highipref\n";
}
print( $results );
@@ -160,23 +128,55 @@
my $highip = '192.168.0.100';
my $sn = Net::Subnets->new;
- my $listref = $sn->list( \( $lowip, $highip ) );
- foreach my $address ( @{ $listref } ) {
+ my $listref = $sn->list(\($lowip, $highip));
+ foreach my $address (@$listref) {
# do something cool
}
+=head1 METHODS
+
+=head2 C<new>
+
+ my $subnets = Net::Subnets->new;
+
+ Creates an "Net::Subnets" object.
+
+=head2 C<subnets>
+
+ $subnets->subnets([qw(10.0.0.0/24 10.0.1.0/24)]);
+
+ The C<subnets> method lets you prepare a list of CIDR subnets.
+
+=head2 C<check>
+
+ my $match = $subnets->check(\$address);
+
+ The C<check> method lets you check an IP address against the previously
+ prepared subnets.
+
+=head2 C<range>
+
+ my ($lowest, $highest) = $subnets->range(\$subnet)
+
+ The C<range> method lets you calculate the IP address range of a subnet.
+
+=head2 C<list>
+
+ my $list = $subnets->list(\$lowest, $highest);
+
+ The C<list> method lets you calculate a list containing all IP addresses
+ in a given range.
=head1 AUTHOR
Sebastian Riedel (sri at cpan.org),
Juergen Peters (juergen.peters at taulmarill.de)
-=head1 COPYRIGHT
+=head1 COPYRIGHT AND LICENSE
-Copyright 2003 Sebastian Riedel & Juergen Peters. All rights reserved.
+Copyright (C) 2003-2009, Sebastian Riedel.
-This library is free software. You can redistribute it and/or
-modify it under the same terms
-as perl itself.
+This program is free software, you can redistribute it and/or modify it under
+the terms of the Artistic License version 2.0.
=cut
Added: branches/upstream/libnet-subnets-perl/current/t/01use.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/t/01use.t?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/t/01use.t (added)
+++ branches/upstream/libnet-subnets-perl/current/t/01use.t Sat Dec 19 00:29:14 2009
@@ -1,0 +1,10 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+BEGIN { use_ok('Net::Subnets') }
Added: branches/upstream/libnet-subnets-perl/current/t/02pod.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/t/02pod.t?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/t/02pod.t (added)
+++ branches/upstream/libnet-subnets-perl/current/t/02pod.t Sat Dec 19 00:29:14 2009
@@ -1,0 +1,16 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2005-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => 'Test::Pod 1.14 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test (developer only!)'
+ unless $ENV{TEST_POD};
+
+# Marge, it takes two to lie. One to lie and one to listen.
+all_pod_files_ok();
Added: branches/upstream/libnet-subnets-perl/current/t/03podcoverage.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/t/03podcoverage.t?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/t/03podcoverage.t (added)
+++ branches/upstream/libnet-subnets-perl/current/t/03podcoverage.t Sat Dec 19 00:29:14 2009
@@ -1,0 +1,17 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2005-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test (developer only!)'
+ unless $ENV{TEST_POD};
+
+# Marge, I'm going to miss you so much. And it's not just the sex.
+# It's also the food preparation.
+all_pod_coverage_ok();
Added: branches/upstream/libnet-subnets-perl/current/t/04check.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/t/04check.t?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/t/04check.t (added)
+++ branches/upstream/libnet-subnets-perl/current/t/04check.t Sat Dec 19 00:29:14 2009
@@ -1,0 +1,25 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
+use Test::Simple tests => 4;
+
+use Net::Subnets;
+
+my @subnets = qw(10.0.0.0/24 10.0.1.0/24);
+my @good_addr = qw(10.0.0.1 10.0.1.2);
+my @bad_addr = qw(10.0.3.4 20.0.0.1);
+
+my $sn = Net::Subnets->new;
+$sn->subnets(\@subnets);
+
+foreach my $addr (@good_addr) {
+ ok($sn->check(\$addr));
+}
+
+foreach my $addr (@bad_addr) {
+ ok(!$sn->check(\$addr));
+}
Added: branches/upstream/libnet-subnets-perl/current/t/05range.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/t/05range.t?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/t/05range.t (added)
+++ branches/upstream/libnet-subnets-perl/current/t/05range.t Sat Dec 19 00:29:14 2009
@@ -1,0 +1,20 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
+use Test::Simple tests => 2;
+
+use Net::Subnets;
+
+my @subnets = qw(10.0.0.0/24 10.0.1.4/32);
+my @lowips = qw(10.0.0.1 10.0.1.4);
+my @highips = qw(10.0.0.254 10.0.1.4);
+
+my $sn = Net::Subnets->new;
+for (my $i = 0; $i <= $#subnets; $i++) {
+ my ($lowip, $highip) = $sn->range(\$subnets[$i]);
+ ok((($lowips[$i] eq $$lowip) && ($highips[$i] eq $$highip)));
+}
Added: branches/upstream/libnet-subnets-perl/current/t/06list.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnet-subnets-perl/current/t/06list.t?rev=48978&op=file
==============================================================================
--- branches/upstream/libnet-subnets-perl/current/t/06list.t (added)
+++ branches/upstream/libnet-subnets-perl/current/t/06list.t Sat Dec 19 00:29:14 2009
@@ -1,0 +1,532 @@
+#!/usr/bin/env perl
+
+# Copyright (C) 2003-2009, Sebastian Riedel.
+
+use strict;
+use warnings;
+
+use Test::Simple tests => 510;
+
+use Net::Subnets;
+
+my $subnet = '10.0.0.0/23';
+
+my $sn = Net::Subnets->new;
+my $list = $sn->list($sn->range(\$subnet));
+
+while (<DATA>) {
+ chomp;
+ ok(($_ eq $$list[$. - 1]));
+}
+
+__DATA__
+10.0.0.1
+10.0.0.2
+10.0.0.3
+10.0.0.4
+10.0.0.5
+10.0.0.6
+10.0.0.7
+10.0.0.8
+10.0.0.9
+10.0.0.10
+10.0.0.11
+10.0.0.12
+10.0.0.13
+10.0.0.14
+10.0.0.15
+10.0.0.16
+10.0.0.17
+10.0.0.18
+10.0.0.19
+10.0.0.20
+10.0.0.21
+10.0.0.22
+10.0.0.23
+10.0.0.24
+10.0.0.25
+10.0.0.26
+10.0.0.27
+10.0.0.28
+10.0.0.29
+10.0.0.30
+10.0.0.31
+10.0.0.32
+10.0.0.33
+10.0.0.34
+10.0.0.35
+10.0.0.36
+10.0.0.37
+10.0.0.38
+10.0.0.39
+10.0.0.40
+10.0.0.41
+10.0.0.42
+10.0.0.43
+10.0.0.44
+10.0.0.45
+10.0.0.46
+10.0.0.47
+10.0.0.48
+10.0.0.49
+10.0.0.50
+10.0.0.51
+10.0.0.52
+10.0.0.53
+10.0.0.54
+10.0.0.55
+10.0.0.56
+10.0.0.57
+10.0.0.58
+10.0.0.59
+10.0.0.60
+10.0.0.61
+10.0.0.62
+10.0.0.63
+10.0.0.64
+10.0.0.65
+10.0.0.66
+10.0.0.67
+10.0.0.68
+10.0.0.69
+10.0.0.70
+10.0.0.71
+10.0.0.72
+10.0.0.73
+10.0.0.74
+10.0.0.75
+10.0.0.76
+10.0.0.77
+10.0.0.78
+10.0.0.79
+10.0.0.80
+10.0.0.81
+10.0.0.82
+10.0.0.83
+10.0.0.84
+10.0.0.85
+10.0.0.86
+10.0.0.87
+10.0.0.88
+10.0.0.89
+10.0.0.90
+10.0.0.91
+10.0.0.92
+10.0.0.93
+10.0.0.94
+10.0.0.95
+10.0.0.96
+10.0.0.97
+10.0.0.98
+10.0.0.99
+10.0.0.100
+10.0.0.101
+10.0.0.102
+10.0.0.103
+10.0.0.104
+10.0.0.105
+10.0.0.106
+10.0.0.107
+10.0.0.108
+10.0.0.109
+10.0.0.110
+10.0.0.111
+10.0.0.112
+10.0.0.113
+10.0.0.114
+10.0.0.115
+10.0.0.116
+10.0.0.117
+10.0.0.118
+10.0.0.119
+10.0.0.120
+10.0.0.121
+10.0.0.122
+10.0.0.123
+10.0.0.124
+10.0.0.125
+10.0.0.126
+10.0.0.127
+10.0.0.128
+10.0.0.129
+10.0.0.130
+10.0.0.131
+10.0.0.132
+10.0.0.133
+10.0.0.134
+10.0.0.135
+10.0.0.136
+10.0.0.137
+10.0.0.138
+10.0.0.139
+10.0.0.140
+10.0.0.141
+10.0.0.142
+10.0.0.143
+10.0.0.144
+10.0.0.145
+10.0.0.146
+10.0.0.147
+10.0.0.148
+10.0.0.149
+10.0.0.150
+10.0.0.151
+10.0.0.152
+10.0.0.153
+10.0.0.154
+10.0.0.155
+10.0.0.156
+10.0.0.157
+10.0.0.158
+10.0.0.159
+10.0.0.160
+10.0.0.161
+10.0.0.162
+10.0.0.163
+10.0.0.164
+10.0.0.165
+10.0.0.166
+10.0.0.167
+10.0.0.168
+10.0.0.169
+10.0.0.170
+10.0.0.171
+10.0.0.172
+10.0.0.173
+10.0.0.174
+10.0.0.175
+10.0.0.176
+10.0.0.177
+10.0.0.178
+10.0.0.179
+10.0.0.180
+10.0.0.181
+10.0.0.182
+10.0.0.183
+10.0.0.184
+10.0.0.185
+10.0.0.186
+10.0.0.187
+10.0.0.188
+10.0.0.189
+10.0.0.190
+10.0.0.191
+10.0.0.192
+10.0.0.193
+10.0.0.194
+10.0.0.195
+10.0.0.196
+10.0.0.197
+10.0.0.198
+10.0.0.199
+10.0.0.200
+10.0.0.201
+10.0.0.202
+10.0.0.203
+10.0.0.204
+10.0.0.205
+10.0.0.206
+10.0.0.207
+10.0.0.208
+10.0.0.209
+10.0.0.210
+10.0.0.211
+10.0.0.212
+10.0.0.213
+10.0.0.214
+10.0.0.215
+10.0.0.216
+10.0.0.217
+10.0.0.218
+10.0.0.219
+10.0.0.220
+10.0.0.221
+10.0.0.222
+10.0.0.223
+10.0.0.224
+10.0.0.225
+10.0.0.226
+10.0.0.227
+10.0.0.228
+10.0.0.229
+10.0.0.230
+10.0.0.231
+10.0.0.232
+10.0.0.233
+10.0.0.234
+10.0.0.235
+10.0.0.236
+10.0.0.237
+10.0.0.238
+10.0.0.239
+10.0.0.240
+10.0.0.241
+10.0.0.242
+10.0.0.243
+10.0.0.244
+10.0.0.245
+10.0.0.246
+10.0.0.247
+10.0.0.248
+10.0.0.249
+10.0.0.250
+10.0.0.251
+10.0.0.252
+10.0.0.253
+10.0.0.254
+10.0.0.255
+10.0.1.0
+10.0.1.1
+10.0.1.2
+10.0.1.3
+10.0.1.4
+10.0.1.5
+10.0.1.6
+10.0.1.7
+10.0.1.8
+10.0.1.9
+10.0.1.10
+10.0.1.11
+10.0.1.12
+10.0.1.13
+10.0.1.14
+10.0.1.15
+10.0.1.16
+10.0.1.17
+10.0.1.18
+10.0.1.19
+10.0.1.20
+10.0.1.21
+10.0.1.22
+10.0.1.23
+10.0.1.24
+10.0.1.25
+10.0.1.26
+10.0.1.27
+10.0.1.28
+10.0.1.29
+10.0.1.30
+10.0.1.31
+10.0.1.32
+10.0.1.33
+10.0.1.34
+10.0.1.35
+10.0.1.36
+10.0.1.37
+10.0.1.38
+10.0.1.39
+10.0.1.40
+10.0.1.41
+10.0.1.42
+10.0.1.43
+10.0.1.44
+10.0.1.45
+10.0.1.46
+10.0.1.47
+10.0.1.48
+10.0.1.49
+10.0.1.50
+10.0.1.51
+10.0.1.52
+10.0.1.53
+10.0.1.54
+10.0.1.55
+10.0.1.56
+10.0.1.57
+10.0.1.58
+10.0.1.59
+10.0.1.60
+10.0.1.61
+10.0.1.62
+10.0.1.63
+10.0.1.64
+10.0.1.65
+10.0.1.66
+10.0.1.67
+10.0.1.68
+10.0.1.69
+10.0.1.70
+10.0.1.71
+10.0.1.72
+10.0.1.73
+10.0.1.74
+10.0.1.75
+10.0.1.76
+10.0.1.77
+10.0.1.78
+10.0.1.79
+10.0.1.80
+10.0.1.81
+10.0.1.82
+10.0.1.83
+10.0.1.84
+10.0.1.85
+10.0.1.86
+10.0.1.87
+10.0.1.88
+10.0.1.89
+10.0.1.90
+10.0.1.91
+10.0.1.92
+10.0.1.93
+10.0.1.94
+10.0.1.95
+10.0.1.96
+10.0.1.97
+10.0.1.98
+10.0.1.99
+10.0.1.100
+10.0.1.101
+10.0.1.102
+10.0.1.103
+10.0.1.104
+10.0.1.105
+10.0.1.106
+10.0.1.107
+10.0.1.108
+10.0.1.109
+10.0.1.110
+10.0.1.111
+10.0.1.112
+10.0.1.113
+10.0.1.114
+10.0.1.115
+10.0.1.116
+10.0.1.117
+10.0.1.118
+10.0.1.119
+10.0.1.120
+10.0.1.121
+10.0.1.122
+10.0.1.123
+10.0.1.124
+10.0.1.125
+10.0.1.126
+10.0.1.127
+10.0.1.128
+10.0.1.129
+10.0.1.130
+10.0.1.131
+10.0.1.132
+10.0.1.133
+10.0.1.134
+10.0.1.135
+10.0.1.136
+10.0.1.137
+10.0.1.138
+10.0.1.139
+10.0.1.140
+10.0.1.141
+10.0.1.142
+10.0.1.143
+10.0.1.144
+10.0.1.145
+10.0.1.146
+10.0.1.147
+10.0.1.148
+10.0.1.149
+10.0.1.150
+10.0.1.151
+10.0.1.152
+10.0.1.153
+10.0.1.154
+10.0.1.155
+10.0.1.156
+10.0.1.157
+10.0.1.158
+10.0.1.159
+10.0.1.160
+10.0.1.161
+10.0.1.162
+10.0.1.163
+10.0.1.164
+10.0.1.165
+10.0.1.166
+10.0.1.167
+10.0.1.168
+10.0.1.169
+10.0.1.170
+10.0.1.171
+10.0.1.172
+10.0.1.173
+10.0.1.174
+10.0.1.175
+10.0.1.176
+10.0.1.177
+10.0.1.178
+10.0.1.179
+10.0.1.180
+10.0.1.181
+10.0.1.182
+10.0.1.183
+10.0.1.184
+10.0.1.185
+10.0.1.186
+10.0.1.187
+10.0.1.188
+10.0.1.189
+10.0.1.190
+10.0.1.191
+10.0.1.192
+10.0.1.193
+10.0.1.194
+10.0.1.195
+10.0.1.196
+10.0.1.197
+10.0.1.198
+10.0.1.199
+10.0.1.200
+10.0.1.201
+10.0.1.202
+10.0.1.203
+10.0.1.204
+10.0.1.205
+10.0.1.206
+10.0.1.207
+10.0.1.208
+10.0.1.209
+10.0.1.210
+10.0.1.211
+10.0.1.212
+10.0.1.213
+10.0.1.214
+10.0.1.215
+10.0.1.216
+10.0.1.217
+10.0.1.218
+10.0.1.219
+10.0.1.220
+10.0.1.221
+10.0.1.222
+10.0.1.223
+10.0.1.224
+10.0.1.225
+10.0.1.226
+10.0.1.227
+10.0.1.228
+10.0.1.229
+10.0.1.230
+10.0.1.231
+10.0.1.232
+10.0.1.233
+10.0.1.234
+10.0.1.235
+10.0.1.236
+10.0.1.237
+10.0.1.238
+10.0.1.239
+10.0.1.240
+10.0.1.241
+10.0.1.242
+10.0.1.243
+10.0.1.244
+10.0.1.245
+10.0.1.246
+10.0.1.247
+10.0.1.248
+10.0.1.249
+10.0.1.250
+10.0.1.251
+10.0.1.252
+10.0.1.253
+10.0.1.254
More information about the Pkg-perl-cvs-commits
mailing list