Changeset 350


Ignore:
Timestamp:
Sep 13, 2018, 5:49:24 PM (6 years ago)
Author:
g7moreau
Message:
  • First support for ip range in sector
Location:
trunk/ddt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ddt/ddt

    r348 r350  
    44# License GNU GPL version 2 or later and Perl equivalent
    55#
    6 # apt-get install perl-base perl-modules libyaml-syck-perl libnet-netmask-perl libreadonly-perl libfile-touch-perl libtext-table-perl
     6# apt-get install perl-base perl-modules libyaml-syck-perl libnet-netmask-perl libreadonly-perl libfile-touch-perl libtext-table-perl libnetaddr-ip-perl
    77
    88package DDT::RE;
     
    2121use strict;
    2222#use warnings;
    23 use version; our $VERSION = version->declare('0.11.3');
     23use version; our $VERSION = version->declare('0.11.4');
    2424
    2525use Getopt::Long qw(GetOptions);
     
    3131use Socket;
    3232use Text::Table;
     33use NetAddr::IP;
    3334
    3435my $command = shift @ARGV || 'help';
     
    261262   }
    262263
     264#-------------------------------------------------------------------------------
     265
     266sub control_ip_in_range {
     267   my ($computer_db, $sector, $ip) = @_;
     268
     269   return 1 if not exists $computer_db->{'dset'}{$sector}{'ip'}; # No IP range defined for this sector
     270
     271   my $ip_addr = NetAddr::IP->new($ip);
     272
     273   LOOP_ON_IP_RANGE:
     274   for my $ip_range_current (@{$computer_db->{'dset'}{$sector}{'ip'}}) {
     275      my $range = NetAddr::IP->new($ip_range_current);
     276      return 1 if $range->contains($ip_addr);
     277      }
     278
     279   return 0;
     280   }
     281
    263282#-------------------------------------------------------------------------------------
    264283#Nom: control_syntaxe_mac
     
    487506   control_syntax_ip($ip)                             or exit;
    488507   control_exist_ip($computer_db, $ip)                or die "Error: IP address already exist in sector $sector: $ip.\n";
     508   control_ip_in_range($computer_db, $sector, $ip)    or die "Error: IP $ip is not in sector $sector IP range.\n";
    489509   control_syntax_comment($comment)                   or exit;
    490510
  • trunk/ddt/make-package-debian

    r335 r350  
    4343Tag: implemented-in::perl, interface::commandline, role::program
    4444Priority: optional
    45 Depends: perl, perl-base, perl-modules, libyaml-syck-perl, libnet-netmask-perl, libreadonly-perl, libfile-touch-perl, libtext-table-perl
     45Depends: perl, perl-base, perl-modules, libyaml-syck-perl, libnet-netmask-perl, libreadonly-perl, libfile-touch-perl, libtext-table-perl, libnetaddr-ip-perl
    4646Suggests: libyaml-shell-perl | yamllint, perl-doc, isc-dhcp-server, bind9
    4747Architecture: all
Note: See TracChangeset for help on using the changeset viewer.