summaryrefslogtreecommitdiffstats
path: root/perl-install
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-07-31 14:48:14 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-07-31 14:48:14 +0000
commit1411411493fdf1aa3ed98bce89e42abd454d6ada (patch)
tree87eacfa3fca162a19e5979267d4043b53d2f3cd3 /perl-install
parentc6dde53bebf7318ee441af8b19acc46917394c24 (diff)
downloaddrakx-1411411493fdf1aa3ed98bce89e42abd454d6ada.tar
drakx-1411411493fdf1aa3ed98bce89e42abd454d6ada.tar.gz
drakx-1411411493fdf1aa3ed98bce89e42abd454d6ada.tar.bz2
drakx-1411411493fdf1aa3ed98bce89e42abd454d6ada.tar.xz
drakx-1411411493fdf1aa3ed98bce89e42abd454d6ada.zip
- have is_ip return the 4 parts of the ip address
- cleanup
Diffstat (limited to 'perl-install')
-rw-r--r--perl-install/network/network.pm20
1 files changed, 8 insertions, 12 deletions
diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm
index 57c08784e..9ae4e3f24 100644
--- a/perl-install/network/network.pm
+++ b/perl-install/network/network.pm
@@ -214,12 +214,9 @@ sub findIntf {
my $ip_regexp = qr/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
sub is_ip {
my ($ip) = @_;
- return 0 unless $ip =~ $ip_regexp;
- my @fields = ($1, $2, $3, $4);
- foreach (@fields) {
- return 0 if $_ < 0 || $_ > 255;
- }
- return 1;
+ my @fields = $ip =~ $ip_regexp or return;
+ return if grep { $_ < 0 || $_ > 255 } @fields;
+ @fields;
}
sub netmask {
@@ -227,21 +224,20 @@ sub netmask {
return "255.255.255.0" unless is_ip($ip);
$ip =~ $ip_regexp;
if ($1 >= 1 && $1 < 127) {
- return "255.0.0.0"; #-1.0.0.0 to 127.0.0.0
+ "255.0.0.0"; #-1.0.0.0 to 127.0.0.0
} elsif ($1 >= 128 && $1 <= 191){
- return "255.255.0.0"; #-128.0.0.0 to 191.255.0.0
+ "255.255.0.0"; #-128.0.0.0 to 191.255.0.0
} elsif ($1 >= 192 && $1 <= 223) {
- return "255.255.255.0";
+ "255.255.255.0";
} else {
- return "255.255.255.255"; #-experimental classes
+ "255.255.255.255"; #-experimental classes
}
}
sub masked_ip {
my ($ip) = @_;
- return "" unless is_ip($ip);
+ my @ip = is_ip($ip) or return '';
my @mask = netmask($ip) =~ $ip_regexp;
- my @ip = $ip =~ $ip_regexp;
for (my $i = 0; $i < @ip; $i++) {
$ip[$i] &= int $mask[$i];
}