#! /usr/bin/perl -w
#
#===============================================================================
#
#         FILE:  perl_pmask.pm
#
#  DESCRIPTION: TEST program using net::interface
#
#        FILES:  ---
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:  DW
#      COMPANY:  ACTIRIS
#      VERSION:  1.0
#      CREATED:  28/12/11 12:08:09
#     REVISION:  ---
#===============================================================================

use strict;
use warnings;
use diagnostics;
use FindBin;
use Net::Interface qw(	:inet
						AF_INET
						AF_INET6
						inet_ntoa
						net_symbols
					);
use Net::Netmask;
use Term::ReadKey;

=item comment

=cut

my @all_ifs = Net::Interface->interfaces();
my @ifnames     = "@all_ifs";
my $family4 = 0 + AF_INET();
my $family6 = 0 + AF_INET6();
	foreach my $if (@all_ifs) {
		my $info = $if->info();
		if (defined($info->{$family4}) ) {
			my $if_name =$if->name();
			next if ($if_name eq "lo");
			my $address =  inet_ntoa($if->address($family4));
			my $netmask =  inet_ntoa($if->netmask($family4));
			
			#	print " $if_name $address / $netmask \n " ;
			#vient de configurator.pm:467 #%ref = ( 'device' => $int, 'ip' => $1, 'mask' => $2 );
			#if (( $address =~ /((?:\d{1,3}\.){3}\d{1,3})/) && () ) {
			if (( $address =~ m/((?:\d{1,3}\.){3}\d{1,3})/) && ($netmask =~ m/((?:\d{1,3}\.){3}\d{1,3})/ ))  {
			print "device => $if_name, ip => $address, mask => $netmask \n";
		}
		}	
}
#
#my $symbolptr= net_symbols();
#	foreach my $i (sort keys %$symbolptr) {
#		print ("$i : $symbolptr->{$i} \n");
#	}
