| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # $Id: IP.pm,v 1.15 2003/06/06 18:45:02 unimlo Exp $ | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package Net::ACL::Match::IP; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 6 |  |  | 6 |  | 24747 | use strict; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 235 |  | 
| 8 | 6 |  |  | 6 |  | 32 | use vars qw( $VERSION @ISA ); | 
|  | 6 |  |  |  |  | 10 |  | 
|  | 6 |  |  |  |  | 485 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | ## Inheritance and Versioning ## | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | @ISA     = qw( Net::ACL::Match ); | 
| 13 |  |  |  |  |  |  | $VERSION = '0.07'; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | ## Module Imports ## | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 6 |  |  | 6 |  | 34 | use Carp; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 429 |  | 
| 18 | 6 |  |  | 6 |  | 3086 | use Net::ACL::Match; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 265 |  | 
| 19 | 6 |  |  | 6 |  | 35 | use Net::ACL::Rule qw( :rc ); | 
|  | 6 |  |  |  |  | 30 |  | 
|  | 6 |  |  |  |  | 1866 |  | 
| 20 | 6 |  |  | 6 |  | 3934 | use Net::Netmask; | 
|  | 6 |  |  |  |  | 70755 |  | 
|  | 6 |  |  |  |  | 2950 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | ## Public Class Methods ## | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub new | 
| 25 |  |  |  |  |  |  | { | 
| 26 | 32 |  |  | 32 | 1 | 2710 | my $proto = shift; | 
| 27 | 32 |  | 33 |  |  | 156 | my $class = ref $proto || $proto; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 32 | 100 | 66 |  |  | 154 | @_ = @{$_[0]} if (scalar @_ == 1) && (ref $_[0] eq 'ARRAY'); | 
|  | 4 |  |  |  |  | 11 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 32 |  |  |  |  | 187 | my $this = bless( { | 
| 32 |  |  |  |  |  |  | _index => undef, | 
| 33 |  |  |  |  |  |  | _net => undef | 
| 34 |  |  |  |  |  |  | }, $class); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 32 |  |  |  |  | 129 | $this->{_index} = shift; | 
| 37 | 32 | 50 |  |  |  | 164 | croak "Index not a number ($this->{_index})" unless $this->{_index} =~ /^[0-9]+$/; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 32 | 50 |  |  |  | 93 | croak "Missing network data" unless scalar @_ > 0; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 32 |  |  |  |  | 126 | $this->{_net} = new Net::Netmask(@_); | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 32 | 50 |  |  |  | 2048 | croak $this->{_net}->{'ERROR'} if defined $this->{_net}->{'ERROR'}; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 32 |  |  |  |  | 155 | return $this; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | ## Public Object Methods ## | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub match | 
| 51 |  |  |  |  |  |  | { | 
| 52 | 65 |  |  | 65 | 1 | 1047 | my $this = shift; | 
| 53 | 65 | 100 |  |  |  | 263 | return $this->{_net}->match($_[$this->{_index}]) ? ACL_MATCH : ACL_NOMATCH; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub net | 
| 57 |  |  |  |  |  |  | { | 
| 58 | 20 |  |  | 20 | 1 | 25 | my $this = shift; | 
| 59 | 20 | 0 |  |  |  | 51 | $this->{_net} = @_ ? ((ref $_[0] eq 'Net::Netmask') ? $_[0] : new Net::Netmask(@_)) : $this->{_net}; | 
|  |  | 50 |  |  |  |  |  | 
| 60 | 20 |  |  |  |  | 54 | return $this->{_net}; | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | ## POD ## | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =pod | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =head1 NAME | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | Net::ACL::Match::IP - Class matching IP addresses against an IP or network | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | use Net::ACL::Match::IP; | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | # Constructor | 
| 76 |  |  |  |  |  |  | $match = new Net::ACL::Match::IP(1,'10.0.0.0/8'); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # Accessor Methods | 
| 79 |  |  |  |  |  |  | $netmaskobj = $match->net($netmaskobj); | 
| 80 |  |  |  |  |  |  | $netmaskobj = $match->net($net); | 
| 81 |  |  |  |  |  |  | $index = $match->index($index); | 
| 82 |  |  |  |  |  |  | $rc = $match->match($ip); | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | This module is just a wrapper of the Net::Netmask module to allow it to | 
| 87 |  |  |  |  |  |  | operate automatically with L. | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 CONSTRUCTOR | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =over 4 | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =item new() - create a new Net::ACL::Match::IP object | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | $match = new Net::ACL::Match::IP(1,'10.0.0.0/8'); | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | This is the constructor for Net::ACL::Match::IP objects. It returns a | 
| 98 |  |  |  |  |  |  | reference to the newly created object. The first argument is the argument | 
| 99 |  |  |  |  |  |  | number of the match method that should be matched. The remaining arguments | 
| 100 |  |  |  |  |  |  | is parsed directly to the constructor of Net::Netmask. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =back | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head1 ACCESSOR METHODS | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =over 4 | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =item net() | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | The net method returns the Net::Netmask object representing the network | 
| 111 |  |  |  |  |  |  | matched. If called with a Net::Netmask object, the net used for matching is | 
| 112 |  |  |  |  |  |  | changed to that object. If called with a anything else, the Net::Netmask | 
| 113 |  |  |  |  |  |  | constructor will be used to convert it to a Net::Netmask object. | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =item index() | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | The index method returns the index of the argument that will be matched. | 
| 118 |  |  |  |  |  |  | If called with an argument, the index is changed to that argument. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =item match() | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | The match method invoke the match() method of the Net::Netmask object constructed | 
| 123 |  |  |  |  |  |  | by new(). The index value defines which argument is passed on to new(). | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =back | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | Net::Netmask, Net::ACL, | 
| 130 |  |  |  |  |  |  | Net::ACL::Rule, Net::ACL::Match | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head1 AUTHOR | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | Martin Lorensen | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =cut | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | ## End Package Net::ACL::Match::IP ## | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | 1; |