libnetwork-ipv4addr-perl-0.10.ds.orig/0000755000175000017500000000000011027271114017117 5ustar gregoagregoalibnetwork-ipv4addr-perl-0.10.ds.orig/test.pl0000644000175000017500000000513307141661304020443 0ustar gregoagregoa# 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; use Test; # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { plan tests => 37 } use Net::IPv4Addr qw(/^ipv4/); # ipv4_parse ok( scalar ipv4_parse( "127.0.0.1" ), "127.0.0.1" ); ok( scalar ipv4_parse( "192.168.100.1 / 24" ), "192.168.100.1/24" ); ok( scalar ipv4_parse( "130.10.2.10", "255.255.255.0"), "130.10.2.10/24"); ok( scalar ipv4_parse( "130.10.2.10", "255.255.255.240"), "130.10.2.10/28"); ok( scalar ipv4_parse( "130.10.2.10/28"), "130.10.2.10/28"); # ipv4_dftl_netmask ok( ipv4_dflt_netmask( "127.0.0.1" ), "255.0.0.0" ); ok( ipv4_dflt_netmask( "172.0.0.01" ), "255.255.0.0" ); ok( ipv4_dflt_netmask( "198.0.0.20" ), "255.255.255.0" ); # ipv4_network ok( scalar ipv4_network( "127.0.0.1"), "127.0.0.0/8" ); ok( scalar ipv4_network( "192.168.100.10" ), "192.168.100.0/24" ); ok( scalar ipv4_network( "192.168.100.100/255.255.255.192"), "192.168.100.64/26" ); # ipv4_broadcast ok( ipv4_broadcast( "127.0.0.1"), "127.255.255.255" ); ok( ipv4_broadcast( "192.168.100.10/24" ), "192.168.100.255" ); ok( ipv4_broadcast( "192.168.100.100/255.255.255.192"), "192.168.100.127" ); # ipv4_in_network ok( ipv4_in_network( "127.0.0.1", "127.0.0.1" ) ); ok( not ipv4_in_network( "127.0.0.0/8", "192.168.30.1" )); ok( not ipv4_in_network( "192.168.100.10", "192.168.100.30")); ok( ipv4_in_network( "192.168.100.10/24", "192.168.100.255")); ok( ipv4_in_network( "192.168.100.0/24", "192.168.100.0")); ok( not ipv4_in_network( "192.16.100.63/26", "192.168.100.65")); ok( ipv4_in_network( "192.168.100.0/24", "0.0.0.0" ) ); ok( ipv4_in_network( "192.168.100.0/24", "255.255.255.255" ) ); ok( ipv4_in_network( "0.0.0.0", "192.168.1.1" ) ); ok( ipv4_in_network( "255.255.255.255", "192.176.1.8" ) ); ok( ipv4_in_network( "192.168.199.0/30", "192.168.199.1" ) ); ok( ipv4_in_network( "212.117.64.0/19", "212.117.65.42/28" ) ); ok( !ipv4_in_network( "21.10.0.4/24", "0.0.0.0/0" ) ); # ipv4_cidr2msk ok( ipv4_cidr2msk( 24 ), "255.255.255.0" ); ok( ipv4_cidr2msk( 16 ), "255.255.0.0" ); ok( ipv4_cidr2msk( 8 ), "255.0.0.0" ); ok( ipv4_cidr2msk( 26 ), "255.255.255.192" ); ok( ipv4_cidr2msk( 0 ), "0.0.0.0" ); ok( ipv4_cidr2msk( 32 ), "255.255.255.255" ); # ipv4_msk2cidr ok( ipv4_msk2cidr( "255.255.255.0" ), 24); ok( ipv4_msk2cidr( "255.255.0.0" ), 16 ); ok( ipv4_msk2cidr( "255.0.0.0" ), 8 ); ok( ipv4_msk2cidr( "255.255.255.192" ), 26 ); ok( ipv4_msk2cidr( "0.0.0.0" ), 0 ); ok( ipv4_msk2cidr( "255.255.255.255" ), 32 ); libnetwork-ipv4addr-perl-0.10.ds.orig/Makefile.PL0000644000175000017500000000042207003126166021074 0ustar gregoagregoause ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Net::IPv4Addr', 'VERSION_FROM' => 'IPv4Addr.pm', # finds $VERSION 'EXE_FILES' => [ ipv4calc ], ); libnetwork-ipv4addr-perl-0.10.ds.orig/ipv4calc0000644000175000017500000000342407141661111020554 0ustar gregoagregoa#!/usr/bin/perl use strict; use Net::IPv4Addr qw (:all); use Getopt::Long; my %opts = (); sub usage() { die < calculates the requested element from the address and prints it on stdout. If multiple options are specified, only the first one is printed. If no options are specified, the program prints the host part of the address, the network and the broadcast address as deduced from the given address. If address doesn't contains a netmask or mask length, the default one is assumed. =head1 AUTHOR Francis J. Lacoste =head1 COPYRIGHT Copyright (c) 1999,2000 iNsu Innovations Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms as perl itself. =head1 SEE ALSO Network::IPv4Addr(3). =cut libnetwork-ipv4addr-perl-0.10.ds.orig/IPv4Addr.spec0000644000175000017500000000430207141661216021357 0ustar gregoagregoaSummary: Perl modules to manipulates Ipv4 addresses. Name: Net-IPv4Addr Version: 0.10 Release: 1i Source: http://iNDev.iNsu.COM/sources/%{name}-%{version}.tar.gz Copyright: GPL or Artistic License Group: Development/Libraries Prefix: /usr URL: http://iNDev.iNsu.COM/IPv4Addr/ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildArchitectures: noarch Obsoletes: Network-IPv4Addr %description Net::IPv4Addr provides methods for parsing IPv4 addresses both in traditional address/netmask format and in the new CIDR format. There are also methods for calculating the network and broadcast address and also to see check if a given address is in a specific network. %prep %setup -q %fix_perl_path %build perl Makefile.PL make OPTIMIZE="$RPM_OPT_FLAGS" make test %install rm -fr $RPM_BUILD_ROOT %perl_make_install BuildDirList > %pkg_file_list BuildFileList >> %pkg_file_list %clean rm -fr $RPM_BUILD_ROOT %files -f %{name}-file-list %defattr(-,root,root) %doc README ChangeLog %changelog * Tue Aug 01 2000 Francis J. Lacoste [0.10-1i] - Updated to version 0.10. - Updated spec file to use new macros. * Wed May 03 2000 Francis J. Lacoste [0.09-1i] - Updated to version 0.09. - Updated automatic file list generation. - Changed group. * Wed Dec 15 1999 Francis J. Lacoste [0.08-1i] - Updated to version 0.08. - Added perl(Net::IPv4Addr) to list of Provides. - Fixed Source URL. * Tue Oct 19 1999 Francis J. Lacoste [0.07-1i] - Updated to version 0.07 * Tue Oct 19 1999 Francis J. Lacoste [0.06-1i] - Updated to version 0.06. - Renamed package to Net-IPv4Addr. * Wed Sep 15 1999 Francis J. Lacoste [0.05-1i] - Updated to version 0.05. * Sun Aug 15 1999 Francis J. Lacoste [0.04-1i] - Updated to version 0.04. * Mon Jul 05 1999 Francis J. Lacoste [0.03-1i] - Updated to version 0.03. * Sat May 15 1999 Francis J. Lacoste [0.02-2i] - Updated to version 0.02. * Sat May 15 1999 Francis J. Lacoste [0.01-1i] - First RPM release. libnetwork-ipv4addr-perl-0.10.ds.orig/NEWS0000644000175000017500000000142507141662115017627 0ustar gregoagregoaNet::IPv4Addr NEWS -- History of User-Visible Changes. May 03 2000 * Changes in IPv4Addr 0.10 - Fixed important errors which occurs when using a /0 CIDR. Thanks to Bernd Eckenfels from Debian for the fix. - Fixed : ipv4_in_network( anything, 0.0.0.0/0) was returning true. Thanks to Bernd Eckenfels from Debian for the fix. - ipv4_chkip wasn't exported with the all tag. * Changes in IPv4Addr 0.09 - Fixed an important bug in ipv4_in_network which caused comparison between networks that where in different class to fail. * Changes in IPv4Addr 0.07 - Debian packaging done by Bernd Eckenfels . * Change in IPv4Addr 0.06 - Module was renamed to Net::IPv4Addr to better fit into CPAN hierarchy. libnetwork-ipv4addr-perl-0.10.ds.orig/ChangeLog0000644000175000017500000000451207141663320020701 0ustar gregoagregoa2000-08-01 Francis J. Lacoste * Tag: IPV4ADDR_0_10 * IPv4Addr.spec: Updated for version 0.10. Updated spec file to use new macros. * IPv4Addr.pm (ipv4_network): Bad network for 0.0.0.0/0. (ipv4_broadcast): Bad broadcast for 0.0.0.0/0. (ipv4_in_network): 0.0.0.0/0 was included in any nets. (VERSION): Updated version number to 0.10. * NEWS: News for 0.10. * README: Updated version number to 0.10. * test.pl: Added test for ipv4_in_network( anything, 0.0.0.0/0). * debian/rules: Merged changes from Bernd . * debian/changelog: Merged changes from Bernd. * debian/control: Merged changes from Bernd. * IPv4Addr.pm: Copyright mods. 2000-07-27 Francis J. Lacoste * IPv4Addr (%EXPORT_TAGS): ipv4_chkip was exported under the wrong name. 2000-05-03 Francis J. Lacoste * Tag: IPV4ADDR_0_09 * test.pl: Added test for different class networks. * IPv4Addr.pm (ipv4_in_network) Fixed bug where comparison between network that differ by more than an octet failed. (version) Incremented version number to 0.09. 1999-12-15 Francis J. Lacoste * Tag: IPV4ADDR_0_08 * IPv4Addr.pm: Moved require statement inside BEGIN to fix problems with ipv4calc. Incremented version number to 0.08. 1999-10-19 Francis J. Lacoste TAG: IPV4ADDR_0_07 * debian/: Added debian packaging by Bernd Eckenfels TAG: IPV4ADDR_0_06 * IPv4Addr.pm: Renamed module to Net::IPv4Addr. 1999-09-15 Francis J. Lacoste * IPv4Addr.pm: Corrected errors in the documentation. TAG: IPV4ADDR_0_05. 1999-08-15 Francis J. Lacoste * IPv4Addr.pm (ipv4_in_netwrok): Fixed broken logic of ipv4_in_network. It didn't handle correctly network which weren't of the same size. TAG: IPV4ADDR_0_04. 1999-07-05 Francis J. Lacoste * IPv4Addr.pm (ipv4_in_network): Added check for universal broadcast address (255.255.255.255) and no address (0.0.0.0). TAG: IPV4ADDR_0_03. 1999-05-27 Francis J. Lacoste * IPv4Addr.pm: (ipv4_parse) removed some undefined warnings. Updated version to 0.02. libnetwork-ipv4addr-perl-0.10.ds.orig/README0000644000175000017500000000137207141660553020015 0ustar gregoagregoaNet::IPv4Addr ================= Version: 0.10 Description ----------- Net::IPv4Addr provides functions for parsing IPv4 addresses both in traditional address/netmask format and in the new CIDR format. There are also methods for calculating the network and broadcast address and also to see check if a given address is in a specific network. Installing ---------- The usual: perl Makefile.PL make make install Documentation ------------- Documentation is included in pod format. Bugs ---- Send bug reports and suggestions to bugs@iNsu.COM. Copyright --------- Copyright (c) 1999,2000 iNsu Innovations Inc . All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. libnetwork-ipv4addr-perl-0.10.ds.orig/MANIFEST0000644000175000017500000000012611027271114020247 0ustar gregoagregoaNEWS README ChangeLog IPv4Addr.pm MANIFEST Makefile.PL test.pl IPv4Addr.spec ipv4calc libnetwork-ipv4addr-perl-0.10.ds.orig/IPv4Addr.pm0000644000175000017500000002324707141662150021050 0ustar gregoagregoa# IPv4Addr.pm - Perl module to manipulate IPv4 addresses. # # Author: Francis J. Lacoste # # Copyright (C) 1999, 2000 iNsu Innovations Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms as perl itself. # package Net::IPv4Addr; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); BEGIN { require Exporter; require AutoLoader; @ISA = qw(Exporter AutoLoader); @EXPORT = qw(); %EXPORT_TAGS = ( all => [qw{ ipv4_parse ipv4_chkip ipv4_network ipv4_broadcast ipv4_cidr2msk ipv4_msk2cidr ipv4_in_network ipv4_dflt_netmask } ], ); @EXPORT_OK = qw(); Exporter::export_ok_tags('all'); $VERSION = '0.10'; } # Preloaded methods go here. use Carp; # Functions to manipulate IPV4 address my $ip_rgx = "\\d+\\.\\d+\\.\\d+\\.\\d+"; # Given an IPv4 address in host, ip/netmask or cidr format # returns a ip / cidr pair. sub ipv4_parse($;$) { my ($ip,$msk); # Called with 2 args, assume first is IP address if ( defined $_[1] ) { $ip = $_[0]; $msk= $_[1]; } else { ($ip) = $_[0] =~ /($ip_rgx)/o; ($msk) = $_[0] =~ m!/(.+)!o; } # Remove white spaces $ip = ipv4_chkip( $ip ) or croak __PACKAGE__, ": invalid IPv4 address: ", $ip, "\n"; $msk =~ s/\s//g if defined $msk; # Check Netmask to see if it is a CIDR or Network if (defined $msk ) { if ($msk =~ /^\d{1,2}$/) { # Check cidr croak __PACKAGE__, ": invalid cidr: ", $msk, "\n" if $msk < 0 or $msk > 32; } elsif ($msk =~ /^$ip_rgx$/o ) { $msk = ipv4_msk2cidr($msk); } else { croak __PACKAGE__, ": invalid netmask specification: ", $msk, "\n"; } } else { # Host return $ip; } wantarray ? ($ip,$msk) : "$ip/$msk"; } sub ipv4_dflt_netmask($) { my ($ip) = ipv4_parse($_[0]); my ($b1) = split /\./, $ip; return "255.0.0.0" if $b1 <= 127; return "255.255.0.0" if $b1 <= 191; return "255.255.255.0"; } # Check form a valid IPv4 address. sub ipv4_chkip($) { my ($ip) = $_[0] =~ /($ip_rgx)/o; return undef unless $ip; # Check that bytes are in range for (split /\./, $ip ) { return undef if $_ < 0 or $_ > 255; } return $ip; } # Transform a netmask in a CIDR mask length sub ipv4_msk2cidr($) { my $msk = ipv4_chkip( $_[0] ) or croak __PACKAGE__, ": invalid netmask: ", $_[0], "\n"; my @bytes = split /\./, $msk; my $cidr = 0; for (@bytes) { my $bits = unpack( "B*", pack( "C", $_ ) ); $cidr += $bits =~ tr /1/1/; } return $cidr; } # Transform a CIDR mask length in a netmask sub ipv4_cidr2msk($) { my $cidr = shift; croak __PACKAGE__, ": invalid cidr: ", $cidr, "\n" if $cidr < 0 or $cidr > 32; my $bits = "1" x $cidr . "0" x (32 - $cidr); return join ".", (unpack 'CCCC', pack("B*", $bits )); } # Return the network address of # an IPv4 address sub ipv4_network($;$) { my ($ip,$cidr) = ipv4_parse( $_[0], $_[1] ); # If only an host is given, use the default netmask unless (defined $cidr) { $cidr = ipv4_msk2cidr( ipv4_dflt_netmask($ip) ); } my $u32 = unpack "N", pack "CCCC", split /\./, $ip; my $bits = "1" x $cidr . "0" x (32 - $cidr ); my $msk = unpack "N", pack "B*", $bits; my $net = join ".", unpack "CCCC", pack "N", $u32 & $msk; wantarray ? ( $net, $cidr) : "$net/$cidr"; } sub ipv4_broadcast($;$) { my ($ip,$cidr) = ipv4_parse( $_[0], $_[1] ); # If only an host is given, use the default netmask unless (defined $cidr) { $cidr = ipv4_msk2cidr( ipv4_dflt_netmask($ip) ); } my $u32 = unpack "N", pack "CCCC", split /\./, $ip; my $bits = "1" x $cidr . "0" x (32 - $cidr ); my $msk = unpack "N", pack "B*", $bits; my $broadcast = join ".", unpack "CCCC", pack "N", $u32 | ~$msk; $broadcast; } sub ipv4_in_network($$;$$) { my ($ip1,$cidr1,$ip2,$cidr2); if ( @_ >= 3) { ($ip1,$cidr1) = ipv4_parse( $_[0], $_[1] ); ($ip2,$cidr2) = ipv4_parse( $_[2], $_[3] ); } else { ($ip1,$cidr1) = ipv4_parse( $_[0]); ($ip2,$cidr2) = ipv4_parse( $_[1]); } # Check for magic addresses. return 1 if ($ip1 eq "255.255.255.255" or $ip1 eq "0.0.0.0") and !defined $cidr1; return 1 if ($ip2 eq "255.255.255.255" or $ip2 eq "0.0.0.0") and !defined $cidr2; # Case where first argument is really an host return $ip1 eq $ip2 unless (defined $cidr1); # Case where second argument is an host if ( not defined $cidr2) { return ipv4_network( $ip1, $cidr1) eq ipv4_network( $ip2, $cidr1 ); } elsif ( $cidr2 >= $cidr1 ) { # Network 2 is smaller or equal than network 1 return ipv4_network( $ip1, $cidr1 ) eq ipv4_network( $ip2, $cidr1 ); } else { # Network 2 is bigger, so can't be wholly contained. return 0; } } # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ # Below is the stub of documentation for your module. You better edit it! =pod =head1 NAME Net::IPv4Addr - Perl extension for manipulating IPv4 addresses. =head1 SYNOPSIS use Net::IPv4Addr qw( :all ); my ($ip,$cidr) = ipv4_parse( "127.0.0.1/24" ); my ($ip,$cidr) = ipv4_parse( "192.168.100.10 / 255.255.255.0" ); my ($net,$msk) = ipv4_network( "192.168.100.30" ); my $broadcast = ipv4_broadcast( "192.168.100.30/26" ); if ( ipv4_in_network( "192.168.100.0", $her_ip ) ) { print "Welcome !"; } etc. =head1 DESCRIPTION Net::IPv4Addr provides functions for parsing IPv4 addresses both in traditional address/netmask format and in the new CIDR format. There are also methods for calculating the network and broadcast address and also to see check if a given address is in a specific network. =head1 ADDRESSES All of Net::IPv4Addr functions accepts addresses in many format. The parsing is very liberal. All these addresses would be accepted: 127.0.0.1 192.168.001.010/24 192.168.10.10/255.255.255.0 192.168.30.10 / 21 10.0.0.0 / 255.0.0.0 255.255.0.0 Those wouldn't though: 272.135.234.0 192.168/16 Most functions accepts the address and netmask or masklength in the same scalar value or as separate values. That is either my($ip,$masklength) = ipv4_parse($cidr_str); my($ip,$masklength) = ipv4_parse($ip_str,$msk_str); =head1 USING No functions are exported by default. Either use the C<:all> tag to import them all or explicitly import those you need. =head1 FUNCTIONS =over =item ipv4_parse my ($ip,$msklen) = ipv4_parse($cidr_str); my $cidr = ipv4_parse($ip_str,$msk_str); my ($ip) = ipv4_parse($ip_str,$msk_str); Parse an IPv4 address and in scalar context the address in CIDR format and in an array context the address and the mask length. If the parameters doesn't contains a netmask or a mask length, in scalar context only the IPv4 address is returned and in an array context the mask length is undefined. If the function cannot parse its input, it croaks. Trap it using C if don't like that. =item ipv4_network my $cidr = ipv4_network($ip_str); my $cidr = ipv4_network($cidr_str); my ($net,$msk) = ipv4_network( $net_str, $msk_str); In scalar context, this function returns the network in CIDR format in which the address is. In array context, it returns the network address and its mask length as a two elements array. If the input is an host without a netmask of mask length, the default netmask is assumed. Again, the function croak if the input is invalid. =item ipv4_broadcast my ($broadcast) = ipv4_broadcast($ip_str); my $broadcast = ipv4_broadcast($ip_str,$msk_str); This function returns the broadcast address. If the input doesn't contains a netmask or mask length, the default netmask is assumed. This function croaks if the input is invalid. =item ipv4_network my $cidr = ipv4_network($net_str); my $cidr = ipv4_network($cidr_sstr); my ($net,$msk) = ipv4_network( $ip_str, $mask_str); In scalar context, this function returns the network in CIDR format in which the address is. In array context, it returns the network address and its mask length as a two elements array. If the input is an host without a netmask or mask length, the default netmask is assumed. Again, the function croak if the input is invalid. =item ipv4_in_network print "Yes" if ipv4_in_network( $cidr_str1, $cidr_str2); print "Yes" if ipv4_in_network( $ip_str1, $mask_str1, $cidr_str2 ); print "Yes" if ipv4_in_network( $ip1, $mask1, $ip2, $msk2 ); This function checks if the second network is contained in the first one and it implements the following semantics : If net1 or net2 is a magic address (0.0.0.0 or 255.255.255.255) than this function returns true. If net1 is an host, net2 will be in the same net only if it is the same host. If net2 is an host, it will be contained in net1 only if it is part of net1. If net2 is only part of net1 if it is entirely contained in net1. Trap bad input with C or else. =item ipv4_checkip if ($ip = ipv4_checkip($str) ) { # Do something } Return the IPv4 address in the string or undef if the input doesn't contains a valid IPv4 address. =item ipv4_cidr2msk my $netmask = ipv4_cidr2msk( $cidr ); Returns the netmask corresponding to the mask length given in input. As usual, croaks if it doesn't like your input (in this case a number between 0 and 32). =item ipv4_msk2cidr my $masklen = ipv4_msk2cidr( $msk ); Returns the mask length of the netmask in input. As usual, croaks if it doesn't like your input. =back =head1 AUTHOR Francis J. Lacoste =head1 COPYRIGHT Copyright (c) 1999, 2000 iNsu Innovations Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms as perl itself. =head1 SEE ALSO perl(1) ipv4calc(1). =cut