Commit 03e6be76 authored by Nick Morrott's avatar Nick Morrott

New upstream version 0.19

parent 66a2f4d6
# Net::CIDR
#
# Copyright 2001-2012 Sam Varshavchik.
# Copyright 2001-2018 Sam Varshavchik.
#
# with contributions from David Cantrell.
#
......@@ -50,7 +50,7 @@ use Carp;
);
$VERSION = "0.18";
$VERSION = "0.19";
1;
......@@ -68,13 +68,13 @@ Net::CIDR - Manipulate IPv4/IPv6 netblocks in CIDR notation
use Net::CIDR ':all';
print join("\n",
Net::CIDR::range2cidr("192.68.0.0-192.68.255.255",
Net::CIDR::range2cidr("192.168.0.0-192.168.255.255",
"10.0.0.0-10.3.255.255"))
. "\n";
#
# Output from above:
#
# 192.68.0.0/16
# 192.168.0.0/16
# 10.0.0.0/14
print join("\n",
......@@ -88,19 +88,19 @@ Net::CIDR - Manipulate IPv4/IPv6 netblocks in CIDR notation
# dead:beef::/32
print join("\n",
Net::CIDR::range2cidr("192.68.1.0-192.68.2.255"))
Net::CIDR::range2cidr("192.168.1.0-192.168.2.255"))
. "\n";
#
# Output from above:
#
# 192.68.1.0/24
# 192.68.2.0/24
# 192.168.1.0/24
# 192.168.2.0/24
print join("\n", Net::CIDR::cidr2range("192.68.0.0/16")) . "\n";
print join("\n", Net::CIDR::cidr2range("192.168.0.0/16")) . "\n";
#
# Output from above:
#
# 192.68.0.0-192.68.255.255
# 192.168.0.0-192.168.255.255
print join("\n", Net::CIDR::cidr2range("dead::beef::/46")) . "\n";
#
......@@ -108,23 +108,23 @@ Net::CIDR - Manipulate IPv4/IPv6 netblocks in CIDR notation
#
# dead:beef::-dead:beef:3:ffff:ffff:ffff:ffff:ffff
@list=("192.68.0.0/24");
@list=Net::CIDR::cidradd("192.68.1.0-192.68.1.255", @list);
@list=("192.168.0.0/24");
@list=Net::CIDR::cidradd("192.168.1.0-192.168.1.255", @list);
print join("\n", @list) . "\n";
#
# Output from above:
#
# 192.68.0.0/23
# 192.168.0.0/23
print join("\n", Net::CIDR::cidr2octets("192.68.0.0/22")) . "\n";
print join("\n", Net::CIDR::cidr2octets("192.168.0.0/22")) . "\n";
#
# Output from above:
#
# 192.68.0
# 192.68.1
# 192.68.2
# 192.68.3
# 192.168.0
# 192.168.1
# 192.168.2
# 192.168.3
print join("\n", Net::CIDR::cidr2octets("dead::beef::/46")) . "\n";
#
......@@ -135,28 +135,28 @@ Net::CIDR - Manipulate IPv4/IPv6 netblocks in CIDR notation
# dead:beef:0002
# dead:beef:0003
@list=("192.68.0.0/24");
print Net::CIDR::cidrlookup("192.68.0.12", @list);
@list=("192.168.0.0/24");
print Net::CIDR::cidrlookup("192.168.0.12", @list);
#
# Output from above:
#
# 1
@list = Net::CIDR::addr2cidr("192.68.0.31");
@list = Net::CIDR::addr2cidr("192.168.0.31");
print join("\n", @list);
#
# Output from above:
#
# 192.68.0.31/32
# 192.68.0.30/31
# 192.68.0.28/30
# 192.68.0.24/29
# 192.68.0.16/28
# 192.68.0.0/27
# 192.68.0.0/26
# 192.68.0.0/25
# 192.68.0.0/24
# 192.68.0.0/23
# 192.168.0.31/32
# 192.168.0.30/31
# 192.168.0.28/30
# 192.168.0.24/29
# 192.168.0.16/28
# 192.168.0.0/27
# 192.168.0.0/26
# 192.168.0.0/25
# 192.168.0.0/24
# 192.168.0.0/23
# [and so on]
print Net::CIDR::addrandmask2cidr("195.149.50.61", "255.255.255.248")."\n";
......@@ -181,23 +181,23 @@ only one parameter and is called in scalar context.
For example:
@a=Net::CIDR::range2cidr("192.68.0.0-192.68.255.255");
@a=Net::CIDR::range2cidr("192.168.0.0-192.168.255.255");
The result is a one-element array, with $a[0] being "192.68.0.0/16".
The result is a one-element array, with $a[0] being "192.168.0.0/16".
range2cidr() processes each "start-finish" element in @range_list separately.
But if invoked like so:
$a=Net::CIDR::range2cidr("192.68.0.0-192.68.255.255");
$a=Net::CIDR::range2cidr("192.168.0.0-192.168.255.255");
The result is a scalar "192.68.0.0/16".
The result is a scalar "192.168.0.0/16".
Where each element cannot be expressed as a single CIDR netblock
range2cidr() will generate as many CIDR netblocks as are necessary to cover
the full range of IP addresses. Example:
@a=Net::CIDR::range2cidr("192.68.1.0-192.68.2.255");
@a=Net::CIDR::range2cidr("192.168.1.0-192.168.2.255");
The result is a two element array: ("192.68.1.0/24","192.68.2.0/24");
The result is a two element array: ("192.168.1.0/24","192.168.2.0/24");
@a=Net::CIDR::range2cidr(
"d08c:43::-d08c:43:ffff:ffff:ffff:ffff:ffff:ffff");
......@@ -213,10 +213,10 @@ range2cidr() does not merge adjacent or overlapping netblocks in
The cidr2range() functions converts a netblock list in CIDR notation
to a list of "start-finish" IP address ranges:
@a=Net::CIDR::cidr2range("10.0.0.0/14", "192.68.0.0/24");
@a=Net::CIDR::cidr2range("10.0.0.0/14", "192.168.0.0/24");
The result is a two-element array:
("10.0.0.0-10.3.255.255", "192.68.0.0-192.68.0.255").
("10.0.0.0-10.3.255.255", "192.168.0.0-192.168.0.255").
@a=Net::CIDR::cidr2range("d08c:43::/32");
......@@ -231,10 +231,10 @@ cidr2range() does not merge adjacent or overlapping netblocks in
The addr2cidr function takes an IP address and returns a list of all
the CIDR netblocks it might belong to:
@a=Net::CIDR::addr2cidr('192.68.0.31');
@a=Net::CIDR::addr2cidr('192.168.0.31');
The result is a thirtythree-element array:
('192.68.0.31/32', '192.68.0.30/31', '192.68.0.28/30', '192.68.0.24/29',
('192.168.0.31/32', '192.168.0.30/31', '192.168.0.28/30', '192.168.0.24/29',
[and so on])
consisting of all the possible subnets containing this address from
0.0.0.0/0 to address/32.
......@@ -828,10 +828,10 @@ sub _ipcmp {
cidr2octets() takes @cidr_list and returns a list of leading octets
representing those netblocks. Example:
@octet_list=Net::CIDR::cidr2octets("10.0.0.0/14", "192.68.0.0/24");
@octet_list=Net::CIDR::cidr2octets("10.0.0.0/14", "192.168.0.0/24");
The result is the following five-element array:
("10.0", "10.1", "10.2", "10.3", "192.68.0").
("10.0", "10.1", "10.2", "10.3", "192.168.0").
For IPv6 addresses, the hexadecimal words in the resulting list are
zero-padded:
......@@ -973,11 +973,11 @@ $block is a single netblock, expressed as either "start-finish", or
"address/prefix".
Example:
@cidr_list=Net::CIDR::range2cidr("192.68.0.0-192.68.0.255");
@cidr_list=Net::CIDR::range2cidr("192.168.0.0-192.168.0.255");
@cidr_list=Net::CIDR::cidradd("10.0.0.0/8", @cidr_list);
@cidr_list=Net::CIDR::cidradd("192.68.1.0-192.68.1.255", @cidr_list);
@cidr_list=Net::CIDR::cidradd("192.168.1.0-192.168.1.255", @cidr_list);
The result is a two-element array: ("10.0.0.0/8", "192.68.0.0/23").
The result is a two-element array: ("10.0.0.0/8", "192.168.0.0/23").
IPv6 addresses are handled in an analogous fashion.
=cut
......@@ -1295,8 +1295,10 @@ sub _triml0 {
my ($a) = @_;
$a =~ s/^0+//g;
$a = "0" if $a eq '';
return $a
}
=pod
=head1 BUGS
......
0.19
2018-06-11 Sam Varshavchik <mrsam@courier-mta.com>
* Fix cidrvalidate() checking of IPv6 addresses with a 0 word.
2016-02-13 Sam Varshavchik <mrsam@courier-mta.com>
* Move test.pl to t/
Update documentation to use only reserved IP addresses.
Revision history for Perl extension Net::CIDR.
Pre-git revision history:
0.01 Mon Jun 25 01:37:53 2001
- original version; created by h2xs 1.20 with options
-X -n Net::CIDR
......
ChangeLog
CIDR.pm
Changes
MANIFEST
Makefile.PL
test.pl
COPYING
README
Net-CIDR.spec
Makefile.PL
MANIFEST This list of files
Net-CIDR.spec.PL
README
t/test.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
......@@ -4,13 +4,13 @@
"Sam Varshavchik <sam@email-scan.com>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060",
"generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
"version" : 2
},
"name" : "Net-CIDR",
"no_index" : {
......@@ -37,5 +37,6 @@
}
},
"release_status" : "stable",
"version" : "0.18"
"version" : "0.19",
"x_serialization_backend" : "JSON::PP version 2.97001"
}
......@@ -7,7 +7,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060'
generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
......@@ -19,4 +19,5 @@ no_index:
- inc
requires:
Carp: '0'
version: '0.18'
version: '0.19'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Summary: Net::CIDR Perl module
Name: perl-Net-CIDR
Version: 0.18
Release: 1%(%{__perl} -e 'my $v=$^V; $v =~ s/(.)/".".ord($1)/ge;print "$v\n";')
Source0: Net-CIDR-%{version}.tar.gz
License: Perl
Group: Development/Languages
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildArch: noarch
BuildPreReq: perl
%description
The Net::CIDR perl module manipulates IPv4/IPv6 netblocks in CIDR notation
%prep
%setup -q -n Net-CIDR-%{version}
%{__perl} Makefile.PL PREFIX=$RPM_BUILD_ROOT%{_prefix}
%build
%{__make}
%install
rm -rf $RPM_BUILD_ROOT
%{__make} install
find $RPM_BUILD_ROOT \( -name .packlist -o -name perllocal.pod \) -exec rm -f {} \;
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%{_prefix}/lib/perl5/site_perl/*/Net
%{_mandir}/man3/*
%changelog
* Wed Aug 13 2003 Mr. Sam <sam@email-scan.com>
- Use preferred BuildRoot
* Sun Mar 31 2002 Mr. Sam <sam@email-scan.com>
- Changed package name to perl-Net-CIDR
* Fri Nov 2 2001 Mr. Sam <mrsam@courier-mta.com>
- Changed package name to perl-net-cidr
* Tue Jun 26 2001 Mr. Sam <mrsam@courier-mta.com>
- Initial build.
#$Revision: 1.9 $
do 'CIDR.pm';
do './CIDR.pm';
open (X, ">Net-CIDR.spec") || die "$!\n";
......@@ -20,28 +20,37 @@ License: Perl
Group: Development/Languages
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildArch: noarch
BuildPreReq: perl
%define need_perl_generators %(if rpm -q fedora-release >/dev/null 2>/dev/null; then echo "1"; exit 0; fi; echo "1"; exit 1)
%if %need_perl_generators
BuildRequires: perl-interpreter
BuildRequires: perl-generators
%else
BuildRequires: perl
%endif
Requires: perl(:MODULE_COMPAT_%(eval "`perl -V:version`"; echo $version))
%description
The Net::CIDR perl module manipulates IPv4/IPv6 netblocks in CIDR notation
%prep
%setup -q -n Net-CIDR-%{version}
%{__perl} Makefile.PL PREFIX=$RPM_BUILD_ROOT%{_prefix}
%{__perl} Makefile.PL PREFIX=$RPM_BUILD_ROOT%{_prefix} INSTALLDIRS=vendor
%build
%{__make}
%install
rm -rf $RPM_BUILD_ROOT
%{__make} install
%{__make} pure_install
find $RPM_BUILD_ROOT \( -name .packlist -o -name perllocal.pod \) -exec rm -f {} \;
%{_fixperms} %{buildroot}/*
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%{_prefix}/lib/perl5/site_perl/*/Net
%{_prefix}/lib*/perl5/site_perl/*/Net
%{_mandir}/man3/*
%changelog
......@@ -56,4 +65,3 @@ rm -rf $RPM_BUILD_ROOT
* Tue Jun 26 2001 Mr. Sam <mrsam@courier-mta.com>
- Initial build.
......@@ -6,7 +6,7 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..10\n"; }
BEGIN { $| = 1; print "1..11\n"; }
END {print "not ok 1\n" unless $loaded;}
use Net::CIDR;
$loaded = 1;
......@@ -19,11 +19,11 @@ print "ok 1\n";
# of the test code):
{
my @octet_list=Net::CIDR::cidr2octets("10.0.0.0/14", "192.68.0.0/24");
my @octet_list=Net::CIDR::cidr2octets("10.0.0.0/14", "192.168.0.0/24");
push @octet_list, Net::CIDR::cidr2octets("::dead:beef:0:0/110");
my @res=("10.0", "10.1", "10.2", "10.3", "192.68.0",
my @res=("10.0", "10.1", "10.2", "10.3", "192.168.0",
"0000:0000:0000:0000:dead:beef:0000",
"0000:0000:0000:0000:dead:beef:0001",
"0000:0000:0000:0000:dead:beef:0002",
......@@ -39,18 +39,20 @@ print "ok 1\n";
}
}
if (join(" ", Net::CIDR::addr2cidr('192.68.0.31'))
eq "192.68.0.31/32 192.68.0.30/31 192.68.0.28/30 192.68.0.24/29 192.68.0.16/28 192.68.0.0/27 192.68.0.0/26 192.68.0.0/25 192.68.0.0/24 192.68.0.0/23 192.68.0.0/22 192.68.0.0/21 192.68.0.0/20 192.68.0.0/19 192.68.0.0/18 192.68.0.0/17 192.68.0.0/16 192.68.0.0/15 192.68.0.0/14 192.64.0.0/13 192.64.0.0/12 192.64.0.0/11 192.64.0.0/10 192.0.0.0/9 192.0.0.0/8 192.0.0.0/7 192.0.0.0/6 192.0.0.0/5 192.0.0.0/4 192.0.0.0/3 192.0.0.0/2 128.0.0.0/1 0.0.0.0/0")
if (join(" ", Net::CIDR::addr2cidr('192.168.0.31'))
eq "192.168.0.31/32 192.168.0.30/31 192.168.0.28/30 192.168.0.24/29 192.168.0.16/28 192.168.0.0/27 192.168.0.0/26 192.168.0.0/25 192.168.0.0/24 192.168.0.0/23 192.168.0.0/22 192.168.0.0/21 192.168.0.0/20 192.168.0.0/19 192.168.0.0/18 192.168.0.0/17 192.168.0.0/16 192.168.0.0/15 192.168.0.0/14 192.168.0.0/13 192.160.0.0/12 192.160.0.0/11 192.128.0.0/10 192.128.0.0/9 192.0.0.0/8 192.0.0.0/7 192.0.0.0/6 192.0.0.0/5 192.0.0.0/4 192.0.0.0/3 192.0.0.0/2 128.0.0.0/1 0.0.0.0/0")
{
print "ok 3\n";
}
else
{
print "not ok 3\n";
warn join(" ", Net::CIDR::addr2cidr('192.168.0.31'));
}
if (join("",
Net::CIDR::cidr2range("192.68.0.0/16")) eq "192.68.0.0-192.68.255.255"
Net::CIDR::cidr2range("192.168.0.0/16")) eq "192.168.0.0-192.168.255.255"
&& join("", Net::CIDR::cidr2range("dead::beef::/46"))
eq "dead:beef::-dead:beef:3:ffff:ffff:ffff:ffff:ffff")
{
......@@ -121,3 +123,12 @@ else
{
print "not ok 10\n";
}
if (Net::CIDR::cidrvalidate("fe80:0:120::/44"))
{
print "ok 11\n";
}
else
{
print "not ok 11\n";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment