summaryrefslogtreecommitdiffstats
path: root/perl-install/network.pm
diff options
context:
space:
mode:
authorpad <pad@mandriva.com>1999-09-06 20:33:18 +0000
committerpad <pad@mandriva.com>1999-09-06 20:33:18 +0000
commit115b4b1145f86d90f20c0404a54fa907f06c30b0 (patch)
tree046cd13affb85df1028bcc687e1c8853fc576cd7 /perl-install/network.pm
parenta6096f902a2df839b7e89c084d629840bf52a3a1 (diff)
downloaddrakx-115b4b1145f86d90f20c0404a54fa907f06c30b0.tar
drakx-115b4b1145f86d90f20c0404a54fa907f06c30b0.tar.gz
drakx-115b4b1145f86d90f20c0404a54fa907f06c30b0.tar.bz2
drakx-115b4b1145f86d90f20c0404a54fa907f06c30b0.tar.xz
drakx-115b4b1145f86d90f20c0404a54fa907f06c30b0.zip
bugfix
Diffstat (limited to 'perl-install/network.pm')
-rw-r--r--perl-install/network.pm67
1 files changed, 62 insertions, 5 deletions
diff --git a/perl-install/network.pm b/perl-install/network.pm
index 1234dcce2..cc5c74fa6 100644
--- a/perl-install/network.pm
+++ b/perl-install/network.pm
@@ -3,15 +3,18 @@ package network;
use diagnostics;
use strict;
+#-######################################################################################
+#- misc imports
+#-######################################################################################
use Socket;
use common qw(:common :file :system :functional);
use detect_devices;
use log;
-1;
-
-
+#-######################################################################################
+#- Functions
+#-######################################################################################
sub read_conf {
my ($file) = @_;
my %netc = getVarsFromSh($file);
@@ -138,7 +141,61 @@ sub findIntf {
push @$intf, $l = { DEVICE => $device } unless $l;
$l;
}
-
+#PAD \s* a la fin
+my $ip_regexp = qr/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
sub is_ip {
- $_[0] =~ /^(\d{1,3}\.){3}\d{1,3}$/;
+ my ($ip) = @_;
+ return 0 unless $ip =~ $ip_regexp;
+ my @fields = ($1, $2, $3, $4);
+ foreach (@fields) {
+ return 0 if $_ < 0 || $_ > 255;
+ }
+ return 1;
+}
+
+sub netmask {
+ my ($ip) = @_;
+ 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
+ } elsif ($1 >= 128 && $1 <= 191 ){
+ return "255.255.0.0"; #128.0.0.0 to 191.255.0.0
+ } elsif ($1 >= 192 && $1 <= 223) {
+ return "255.255.255.0";
+ } else {
+ return "255.255.255.255"; #experimental classes
+ }
}
+
+sub masked_ip {
+ my ($ip) = @_;
+ return "" unless is_ip($ip);
+ my @mask = netmask($ip) =~ $ip_regexp;
+ my @ip = $ip =~ $ip_regexp;
+ for (my $i = 0; $i < @ip; $i++) {
+ $ip[$i] &= int $mask[$i];
+ }
+ join(".", @ip);
+}
+
+sub dns {
+ my ($ip) = @_;
+ my $mask = masked_ip($ip);
+ my @masked = masked_ip($ip) =~ $ip_regexp;
+ $masked[3] = 12;
+ join (".", @masked);
+
+}
+sub gateway {
+ my ($ip) = @_;
+ my @masked = masked_ip($ip) =~ $ip_regexp;
+ $masked[3] = 1;
+ join (".", @masked);
+
+}
+
+#-######################################################################################
+#- Wonderful perl :(
+#-######################################################################################
+1; #