r53708 - in /trunk/libnet-patricia-perl: META.yml Makefile.PL Patricia.pm debian/changelog libpatricia/patricia.c libpatricia/patricia.h test.pl
gregoa at users.alioth.debian.org
gregoa at users.alioth.debian.org
Sat Mar 6 16:50:56 UTC 2010
Author: gregoa
Date: Sat Mar 6 16:50:31 2010
New Revision: 53708
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=53708
Log:
New upstream release.
Modified:
trunk/libnet-patricia-perl/META.yml
trunk/libnet-patricia-perl/Makefile.PL
trunk/libnet-patricia-perl/Patricia.pm
trunk/libnet-patricia-perl/debian/changelog
trunk/libnet-patricia-perl/libpatricia/patricia.c
trunk/libnet-patricia-perl/libpatricia/patricia.h
trunk/libnet-patricia-perl/test.pl
Modified: trunk/libnet-patricia-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/META.yml?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/META.yml (original)
+++ trunk/libnet-patricia-perl/META.yml Sat Mar 6 16:50:31 2010
@@ -1,12 +1,13 @@
--- #YAML:1.0
name: Net-Patricia
-version: 1.15
+version: 1.16
abstract: ~
license: ~
author: ~
generated_by: ExtUtils::MakeMaker version 6.42
distribution_type: module
requires:
+ Socket6: 0
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html
version: 1.3
Modified: trunk/libnet-patricia-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/Makefile.PL?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/Makefile.PL (original)
+++ trunk/libnet-patricia-perl/Makefile.PL Sat Mar 6 16:50:31 2010
@@ -9,6 +9,7 @@
'INC' => '', # e.g., '-I/usr/include/other'
'MYEXTLIB' => 'libpatricia/libpatricia$(LIB_EXT)', # e.g., '-I/usr/include/other'
'dist' => {'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz'},
+ 'PREREQ_PM' => {'Socket6' => 0},
);
sub MY::postamble {
Modified: trunk/libnet-patricia-perl/Patricia.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/Patricia.pm?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/Patricia.pm (original)
+++ trunk/libnet-patricia-perl/Patricia.pm Sat Mar 6 16:50:31 2010
@@ -21,28 +21,41 @@
package Net::Patricia;
+use strict;
+use warnings;
+
+require 5.006_000;
+
use version;
-use strict;
use Carp;
-use vars qw($VERSION @ISA);
-use Socket qw(AF_INET inet_aton inet_ntoa);
-
-require DynaLoader;
-require 5.6.0;
-
- at ISA = qw(DynaLoader);
-'$Revision: 1.15 $' =~ m/(\d+)\.(\d+)(\.\d+)?/ && ( $VERSION = "$1.$2$3");
+use vars qw($VERSION @ISA @EXPORT);
+use Socket qw(AF_INET AF_INET6 inet_aton inet_ntoa);
+use Socket6 qw(inet_pton inet_ntop);
+
+BEGIN {
+ require Exporter;
+ require DynaLoader;
+ @ISA = qw(Exporter DynaLoader);
+ @EXPORT = qw(AF_INET AF_INET6);
+}
+
+'$Revision: 1.16 $' =~ m/(\d+)\.(\d+)(_\d+|)/ && ( $VERSION = "$1.$2$3");
bootstrap Net::Patricia $VERSION;
sub new {
my ($class, $type) = @_;
+
$type ||= AF_INET;
if ($type == AF_INET) {
return bless _new(32), 'Net::Patricia::AF_INET';
}
+ if ($type == AF_INET6) {
+ return bless _new(128), 'Net::Patricia::AF_INET6';
+ }
+
undef;
}
@@ -51,25 +64,31 @@
##
sub _ip_bits {
- my $str = shift;
- my $bits = ($str =~ s,/(\d+)$,,) ? $1 : 32;
+ my ($self, $str) = @_;
+ my $bits;
+
+ if (ref ($self) eq 'Net::Patricia::AF_INET6') {
+ $bits = ($str =~ s,/(\d+)$,,) ? $1 : 128;
+ } else {
+ $bits = ($str =~ s,/(\d+)$,,) ? $1 : 32;
+ }
($str,$bits);
}
sub add_string {
my ($self,$str,$data) = @_;
$data = $str unless @_ > 2;
- $self->add(_ip_bits($str),$data);
+ $self->add($self->_ip_bits($str),$data);
}
sub match_string {
my ($self,$str) = @_;
- $self->match(_ip_bits($str))
+ $self->match($self->_ip_bits($str))
}
sub match_exact_string {
my ($self,$str) = @_;
- $self->exact(_ip_bits($str))
+ $self->exact($self->_ip_bits($str))
}
sub match_exact_integer {
@@ -78,7 +97,7 @@
sub remove_string {
my ($self,$str) = @_;
- $self->remove(_ip_bits($str))
+ $self->remove($self->_ip_bits($str))
}
##
@@ -133,6 +152,60 @@
sub Net::Patricia::AF_INET::remove_integer {
my ($self, $num, $bits) = @_;
_remove($self,AF_INET,pack("N",$num),(defined $bits ? $bits : 32));
+}
+
+##
+## AF_INET6
+##
+
+ at Net::Patricia::AF_INET6::ISA = qw(Net::Patricia);
+
+sub Net::Patricia::AF_INET6::add {
+ my ($self, $ip, $bits, $data) = @_;
+ $data ||= $bits ? "$ip/$bits" : $ip;
+ my $packed = inet_pton(AF_INET6, $ip) || croak("invalid key");
+ _add($self,AF_INET6,$packed,(defined $bits ? $bits : 128), $data);
+}
+
+sub Net::Patricia::AF_INET6::add_integer {
+ my ($self, $num, $bits, $data) = @_;
+ my $packed = pack("N", $num);
+ my $ip = inet_ntop(AF_INET6, $packed) || croak("invalid address");
+ $data ||= defined $bits ? "$ip/$bits" : $ip;
+ _add($self,AF_INET6,$packed,(defined $bits ? $bits : 128), $data);
+}
+
+sub Net::Patricia::AF_INET6::match_integer {
+ my ($self, $num, $bits) = @_;
+ _match($self,AF_INET6,pack("N",$num),(defined $bits ? $bits : 128));
+}
+
+sub Net::Patricia::AF_INET6::exact_integer {
+ my ($self, $num, $bits) = @_;
+ _exact($self,AF_INET6,pack("N",$num),(defined $bits ? $bits : 128));
+}
+
+sub Net::Patricia::AF_INET6::match {
+ my ($self, $ip, $bits) = @_;
+ my $packed = inet_pton(AF_INET6, $ip) || croak("invalid key");
+ _match($self,AF_INET6,$packed,(defined $bits ? $bits : 128));
+}
+
+sub Net::Patricia::AF_INET6::exact {
+ my ($self, $ip, $bits) = @_;
+ my $packed = inet_pton(AF_INET6, $ip) || croak("invalid key");
+ _exact($self,AF_INET6,$packed,(defined $bits ? $bits : 128));
+}
+
+sub Net::Patricia::AF_INET6::remove {
+ my ($self, $ip, $bits) = @_;
+ my $packed = inet_pton(AF_INET6, $ip) || return undef;
+ _remove($self,AF_INET6,$packed,(defined $bits ? $bits : 128));
+}
+
+sub Net::Patricia::AF_INET6::remove_integer {
+ my ($self, $num, $bits) = @_;
+ _remove($self,AF_INET6,pack("N",$num),(defined $bits ? $bits : 128));
}
1;
Modified: trunk/libnet-patricia-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/debian/changelog?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/debian/changelog (original)
+++ trunk/libnet-patricia-perl/debian/changelog Sat Mar 6 16:50:31 2010
@@ -1,4 +1,4 @@
-libnet-patricia-perl (1.15-2) UNRELEASED; urgency=low
+libnet-patricia-perl (1.16-1) UNRELEASED; urgency=low
[ Nathan Handler ]
* debian/watch: Update to ignore development releases.
@@ -9,7 +9,10 @@
[ Ryan Niebur ]
* Update ryan52's email address
- -- Ryan Niebur <ryan at debian.org> Fri, 25 Sep 2009 00:25:47 -0700
+ [ gregor herrmann ]
+ * New upstream release.
+
+ -- gregor herrmann <gregoa at debian.org> Sat, 06 Mar 2010 17:49:40 +0100
libnet-patricia-perl (1.15-1) unstable; urgency=low
Modified: trunk/libnet-patricia-perl/libpatricia/patricia.c
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/libpatricia/patricia.c?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/libpatricia/patricia.c (original)
+++ trunk/libnet-patricia-perl/libpatricia/patricia.c Sat Mar 6 16:50:31 2010
@@ -77,16 +77,16 @@
if (result == -1)
return 0;
else {
- memcpy (dst, &result, 4);
+ memcpy (dst, &result, sizeof(struct in_addr));
return 1;
- }
- }
+ }
+ }
#ifdef NT
#ifdef HAVE_IPV6
- else if (af == AF_INET6) {
- struct in6_addr Address;
- return (inet6_addr(src, &Address));
- }
+ else if (af == AF_INET6) {
+ struct in6_addr Address;
+ return (inet6_addr(src, &Address));
+ }
#endif /* HAVE_IPV6 */
#endif /* NT */
#ifndef NT
@@ -104,7 +104,7 @@
{
if (af == AF_INET) {
int i, c, val;
- u_char xp[4] = {0, 0, 0, 0};
+ u_char xp[sizeof(struct in_addr)] = {0, 0, 0, 0};
for (i = 0; ; i++) {
c = *src++;
@@ -125,7 +125,7 @@
if (i >= 3)
return (0);
}
- memcpy (dst, xp, 4);
+ memcpy (dst, xp, sizeof(struct in_addr));
return (1);
#ifdef HAVE_IPV6
} else if (af == AF_INET6) {
@@ -139,6 +139,8 @@
}
}
+#define PATRICIA_MAX_THREADS 16
+
/*
* convert prefix information to ascii string with length
* thread safe and (almost) re-entrant implementation
@@ -152,7 +154,7 @@
if (buff == NULL) {
struct buffer {
- char buffs[16][48+5];
+ char buffs[PATRICIA_MAX_THREADS][48+5];
u_int i;
} *buffp;
@@ -169,11 +171,11 @@
return (NULL);
}
- buff = buffp->buffs[buffp->i++%16];
+ buff = buffp->buffs[buffp->i++%PATRICIA_MAX_THREADS];
}
if (prefix->family == AF_INET) {
u_char *a;
- assert (prefix->bitlen <= 32);
+ assert (prefix->bitlen <= sizeof(struct in_addr) * 8);
a = prefix_touchar (prefix);
if (with_len) {
sprintf (buff, "%d.%d.%d.%d/%d", a[0], a[1], a[2], a[3],
@@ -189,7 +191,7 @@
char *r;
r = (char *) inet_ntop (AF_INET6, &prefix->add.sin6, buff, 48 /* a guess value */ );
if (r && with_len) {
- assert (prefix->bitlen <= 128);
+ assert (prefix->bitlen <= sizeof(struct in6_addr) * 8);
sprintf (buff + strlen (buff), "/%d", prefix->bitlen);
}
return (buff);
@@ -220,32 +222,32 @@
New_Prefix2 (int family, void *dest, int bitlen, prefix_t *prefix)
{
int dynamic_allocated = 0;
- int default_bitlen = 32;
+ int default_bitlen = sizeof(struct in_addr) * 8;
#ifdef HAVE_IPV6
if (family == AF_INET6) {
- default_bitlen = 128;
+ default_bitlen = sizeof(struct in6_addr) * 8;
if (prefix == NULL) {
- prefix = calloc(1, sizeof (prefix6_t));
+ prefix = calloc(1, sizeof (prefix_t));
dynamic_allocated++;
}
- memcpy (&prefix->add.sin6, dest, 16);
+ memcpy (&prefix->add.sin6, dest, sizeof(struct in6_addr));
}
else
#endif /* HAVE_IPV6 */
if (family == AF_INET) {
- if (prefix == NULL) {
+ if (prefix == NULL) {
#ifndef NT
prefix = calloc(1, sizeof (prefix4_t));
#else
- //for some reason, compiler is getting
- //prefix4_t size incorrect on NT
- prefix = calloc(1, sizeof (prefix_t));
+ //for some reason, compiler is getting
+ //prefix4_t size incorrect on NT
+ prefix = calloc(1, sizeof (prefix_t));
#endif /* NT */
- dynamic_allocated++;
- }
- memcpy (&prefix->add.sin, dest, 4);
+ dynamic_allocated++;
+ }
+ memcpy (&prefix->add.sin, dest, sizeof(struct in_addr));
}
else {
return (NULL);
@@ -282,7 +284,7 @@
char save[MAXLINE];
if (string == NULL)
- return (NULL);
+ return (NULL);
/* easy way to handle both families */
if (family == 0) {
@@ -293,50 +295,50 @@
}
if (family == AF_INET) {
- maxbitlen = 32;
+ maxbitlen = sizeof(struct in_addr) * 8;
}
#ifdef HAVE_IPV6
else if (family == AF_INET6) {
- maxbitlen = 128;
+ maxbitlen = sizeof(struct in6_addr) * 8;
}
#endif /* HAVE_IPV6 */
if ((cp = strchr (string, '/')) != NULL) {
- bitlen = atol (cp + 1);
- /* *cp = '\0'; */
- /* copy the string to save. Avoid destroying the string */
- assert (cp - string < MAXLINE);
- memcpy (save, string, cp - string);
- save[cp - string] = '\0';
- string = save;
- if (bitlen < 0 || bitlen > maxbitlen)
- bitlen = maxbitlen;
- }
- else {
- bitlen = maxbitlen;
- }
-
- if (family == AF_INET) {
- if ((result = my_inet_pton (AF_INET, string, &sin)) <= 0)
- return (NULL);
- return (New_Prefix (AF_INET, &sin, bitlen));
- }
+ bitlen = atol (cp + 1);
+ /* *cp = '\0'; */
+ /* copy the string to save. Avoid destroying the string */
+ assert (cp - string < MAXLINE);
+ memcpy (save, string, cp - string);
+ save[cp - string] = '\0';
+ string = save;
+ if (bitlen < 0 || bitlen > maxbitlen)
+ bitlen = maxbitlen;
+ }
+ else {
+ bitlen = maxbitlen;
+ }
+
+ if (family == AF_INET) {
+ if ((result = my_inet_pton (AF_INET, string, &sin)) <= 0)
+ return (NULL);
+ return (New_Prefix (AF_INET, &sin, bitlen));
+ }
#ifdef HAVE_IPV6
- else if (family == AF_INET6) {
+ else if (family == AF_INET6) {
// Get rid of this with next IPv6 upgrade
#if defined(NT) && !defined(HAVE_INET_NTOP)
- inet6_addr(string, &sin6);
- return (New_Prefix (AF_INET6, &sin6, bitlen));
+ inet6_addr(string, &sin6);
+ return (New_Prefix (AF_INET6, &sin6, bitlen));
#else
- if ((result = inet_pton (AF_INET6, string, &sin6)) <= 0)
- return (NULL);
+ if ((result = inet_pton (AF_INET6, string, &sin6)) <= 0)
+ return (NULL);
#endif /* NT */
- return (New_Prefix (AF_INET6, &sin6, bitlen));
- }
+ return (New_Prefix (AF_INET6, &sin6, bitlen));
+ }
#endif /* HAVE_IPV6 */
- else
- return (NULL);
+ else
+ return (NULL);
}
prefix_t *
@@ -431,7 +433,7 @@
} else if (Xsp != Xstack) {
Xrn = *(--Xsp);
} else {
- Xrn = (patricia_node_t *) 0;
+ Xrn = NULL;
}
}
}
@@ -513,7 +515,7 @@
fprintf (stderr, "patricia_search_exact: take right %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_search_exact: take right at %d\n",
+ fprintf (stderr, "patricia_search_exact: take right at %u\n",
node->bit);
#endif /* PATRICIA_DEBUG */
node = node->r;
@@ -524,7 +526,7 @@
fprintf (stderr, "patricia_search_exact: take left %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_search_exact: take left at %d\n",
+ fprintf (stderr, "patricia_search_exact: take left at %u\n",
node->bit);
#endif /* PATRICIA_DEBUG */
node = node->l;
@@ -539,7 +541,7 @@
fprintf (stderr, "patricia_search_exact: stop at %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_search_exact: stop at %d\n", node->bit);
+ fprintf (stderr, "patricia_search_exact: stop at %u\n", node->bit);
#endif /* PATRICIA_DEBUG */
if (node->bit > bitlen || node->prefix == NULL)
return (NULL);
@@ -594,7 +596,7 @@
fprintf (stderr, "patricia_search_best: take right %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_search_best: take right at %d\n",
+ fprintf (stderr, "patricia_search_best: take right at %u\n",
node->bit);
#endif /* PATRICIA_DEBUG */
node = node->r;
@@ -605,7 +607,7 @@
fprintf (stderr, "patricia_search_best: take left %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_search_best: take left at %d\n",
+ fprintf (stderr, "patricia_search_best: take left at %u\n",
node->bit);
#endif /* PATRICIA_DEBUG */
node = node->l;
@@ -625,7 +627,7 @@
fprintf (stderr, "patricia_search_best: stop at %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_search_best: stop at %d\n", node->bit);
+ fprintf (stderr, "patricia_search_best: stop at %u\n", node->bit);
#endif /* PATRICIA_DEBUG */
if (cnt <= 0)
@@ -701,7 +703,7 @@
fprintf (stderr, "patricia_lookup: take right %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_lookup: take right at %d\n", node->bit);
+ fprintf (stderr, "patricia_lookup: take right at %u\n", node->bit);
#endif /* PATRICIA_DEBUG */
node = node->r;
}
@@ -713,7 +715,7 @@
fprintf (stderr, "patricia_lookup: take left %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_lookup: take left at %d\n", node->bit);
+ fprintf (stderr, "patricia_lookup: take left at %u\n", node->bit);
#endif /* PATRICIA_DEBUG */
node = node->l;
}
@@ -761,7 +763,7 @@
fprintf (stderr, "patricia_lookup: up to %s/%d\n",
prefix_toa (node->prefix), node->prefix->bitlen);
else
- fprintf (stderr, "patricia_lookup: up to %d\n", node->bit);
+ fprintf (stderr, "patricia_lookup: up to %u\n", node->bit);
#endif /* PATRICIA_DEBUG */
}
@@ -1033,6 +1035,7 @@
printf ("try_search_best: %s/%d found\n",
prefix_toa (node->prefix), node->prefix->bitlen);
Deref_Prefix (prefix);
+ return (prefix);
}
/* } */
Modified: trunk/libnet-patricia-perl/libpatricia/patricia.h
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/libpatricia/patricia.h?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/libpatricia/patricia.h (original)
+++ trunk/libnet-patricia-perl/libpatricia/patricia.h Sat Mar 6 16:50:31 2010
@@ -14,6 +14,8 @@
#ifndef _PATRICIA_H
#define _PATRICIA_H
+
+#define HAVE_IPV6
/* typedef unsigned int u_int; */
typedef void (*void_fn_t)();
@@ -97,7 +99,7 @@
/* } */
-#define PATRICIA_MAXBITS 128
+#define PATRICIA_MAXBITS (sizeof(struct in6_addr) * 8)
#define PATRICIA_NBIT(x) (0x80 >> ((x) & 0x7f))
#define PATRICIA_NBYTE(x) ((x) >> 3)
Modified: trunk/libnet-patricia-perl/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnet-patricia-perl/test.pl?rev=53708&op=diff
==============================================================================
--- trunk/libnet-patricia-perl/test.pl (original)
+++ trunk/libnet-patricia-perl/test.pl Sat Mar 6 16:50:31 2010
@@ -1,15 +1,17 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
+
+use strict qw(vars);
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
-BEGIN { $| = 1; $debug = 1; print "1..19\n"; }
-END {print "not ok 1\n" unless $loaded;}
+BEGIN { $| = 1; $::debug = 1; print "1..22\n"; }
+END {print "not ok 1\n" unless $::loaded;}
use Net::Patricia;
-$loaded = 1;
+$::loaded = 1;
print "ok 1\n";
######################### End of black magic.
@@ -18,7 +20,9 @@
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
-print ref($t = new Net::Patricia)? "ok 2\n" : "not ok 2\n";
+my $t = new Net::Patricia;
+
+print ref($t)? "ok 2\n" : "not ok 2\n";
print $t->add_string('127.0.0.0/8')? "ok 3\n" : "not ok 3\n";
@@ -52,7 +56,7 @@
print $t->add_string('10.0.0.0/8', $ten)? "ok 8\n" : "not ok 8\n";
}
-print("Destructor 10 should *not* have run yet.\n") if $debug;
+print("Destructor 10 should *not* have run yet.\n") if $::debug;
foreach my $subnet (qw(10.42.42.0/31 10.42.42.0/26 10.42.42.0/24 10.42.42.0/32 10.42.69.0/24)) {
$t->add_string($subnet) || die
@@ -102,7 +106,7 @@
print "not ok 15\n"
}
-print("Destructor 10 should have just run.\n") if $debug;
+print("Destructor 10 should have just run.\n") if $::debug;
if (!$t->match_exact_integer(167772160, 8)) { # 10.0.0.0
print "ok 16\n"
@@ -134,6 +138,30 @@
undef $t;
+# $t = new Net::Patricia::AF_INET6;
+
+$t = new Net::Patricia(AF_INET6);
+
+print ref($t)? "ok 20\n" : "not ok 20\n";
+
+$t->add_string('2001:220::/35', 'hello, world');
+
+if ('hello, world' eq $t->match_string('2001:220::/128')) {
+ print "ok 21\n";
+} else {
+ print "not ok 21\n";
+}
+
+undef $t;
+
+# $t = new Net::Patricia::AF_INET6;
+
+$t = new Net::Patricia(AF_INET);
+
+print ref($t)? "ok 22\n" : "not ok 22\n";
+
+undef $t;
+
exit;
package Thingy;
More information about the Pkg-perl-cvs-commits
mailing list