3 # $Id: cidrexpand,v 8.4.2.1 2006/08/07 17:22:10 ca Exp $
7 # 17 July 2000 Derek J. Balling (dredd@megacity.org)
9 # Acts as a preparser on /etc/mail/access_db to allow you to use address/bit
12 # If you have two overlapping CIDR blocks with conflicting actions
13 # e.g. 10.2.3.128/25 REJECT and 10.2.3.143 ACCEPT
14 # make sure that the exceptions to the more general block are specified
15 # later in the access_db.
17 # the -r flag to makemap will make it "do the right thing"
21 # 26 Jul 2001 Derek Balling (dredd@megacity.org)
22 # Now uses Net::CIDR because it makes life a lot easier.
24 # 5 Nov 2002 Richard Rognlie (richard@sendmail.com)
25 # Added code to deal with the prefix tags that may now be included in
28 # Added clarification in the notes for what to do if you have
29 # exceptions to a larger CIDR block.
33 # Corrected a bug to have it handle the special case of "0.0.0.0/0"
34 # since Net::CIDR doesn't handle it properly.
37 # cidrexpand < /etc/mail/access | makemap -r hash /etc/mail/access
40 # Report bugs to: <dredd@megacity.org>
47 my $spaceregex = '\s+';
49 while (my $arg = shift @ARGV)
63 my ($prefix,$left,$right,$space);
65 if (! /^(|\S\S*:)(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
71 ($prefix,$left,$space,$right) = /^(|\S\S*:)((?:\d+\.){3}\d+\/\d\d?)($spaceregex)(.*)$/;
73 my @new_lefts = expand_network($left);
74 foreach my $nl (@new_lefts)
76 print "$prefix$nl$space$right\n";
83 my $left_input = shift;
84 my @rc = ($left_input);
85 my ($network,$mask) = split /\//, $left_input;
88 return (0..255) if $mask == 0;
90 my @parts = split /\./, $network;
95 my $clean_input = join '.', @parts;
96 $clean_input .= "/$mask";
97 my @octets = Net::CIDR::cidr2octets($clean_input);