diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-01-12 15:01:19 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-01-12 15:01:19 -0800 |
commit | e12098cc7b7d44636a78e4d69983590a528438b5 (patch) | |
tree | cd23fb8fea644d5fe4a19db8753d87e58d9bf6f9 /lib/Vyatta/Misc.pm | |
parent | a964870f5c71a1c11fa5cb34ef7d98076a70c91b (diff) | |
download | vyatta-cfg-e12098cc7b7d44636a78e4d69983590a528438b5.tar.gz vyatta-cfg-e12098cc7b7d44636a78e4d69983590a528438b5.zip |
Simplfy and cleanup misc interfaces
Use regex to identify legal IPV4 address, and get rid of perlcrtic
warnings.
Diffstat (limited to 'lib/Vyatta/Misc.pm')
-rwxr-xr-x | lib/Vyatta/Misc.pm | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 22b41db..19257be 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -103,7 +103,7 @@ sub getInterfacesIPadresses { my $interface_type = shift; if (!($interface_type =~ m/broadcast|pointopoint|multicast|all/)) { print STDERR "Invalid interface type specified to retrive IP addresses for\n"; - return undef; + return; # undef } my @interfaces_on_system = `ifconfig -a | awk '\$2 ~ /Link/ {print \$1}'`; chomp @interfaces_on_system; @@ -141,7 +141,7 @@ sub getNetAddrIP { if ($interface eq '') { print STDERR "Error: No interface specified.\n"; - return undef; + return; # undef } my $ifconfig_out = `ifconfig $interface`; @@ -149,14 +149,14 @@ sub getNetAddrIP { my $ip = $1; if ($ip eq '') { print STDERR "Error: Unable to determine IP address for interface \'$interface\'.\n"; - return undef; + return; # undef } $ifconfig_out =~ /Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; my $netmask = $1; if ($netmask eq '') { print STDERR "Error: Unable to determine netmask for interface \'$interface\'.\n"; - return undef; + return; # undef } use NetAddr::IP; # This library is available via libnetaddr-ip-perl.deb @@ -174,9 +174,7 @@ sub is_ip_v4_or_v6 { # it to be 1.1.0.0, so add a check to force all # 4 octets to be defined # - if ($addr !~ /\d+\.\d+\.\d+\.\d+/) { - return undef; - } + return if ($addr !~ /\d+\.\d+\.\d+\.\d+/); # unndef return 4; } $ip = NetAddr::IP->new6($addr); @@ -184,28 +182,18 @@ sub is_ip_v4_or_v6 { return 6; } - return undef; + return; # undef } sub isIpAddress { my $ip = shift; - $_ = $ip; - if ( ! /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { - return 0; - } - else { - my @ips = split /\./, $ip; - my $octet = 0; - my $counter = 0; - - foreach $octet (@ips) { - if (($octet < 0) || ($octet > 255)) { return 0; } - if (($counter == 0) && ($octet < 1)) { return 0; } - $counter++; - } - } - + return unless $ip =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/; + + return unless ($1 > 0 && $1 < 256); + return unless ($2 >= 0 && $2 < 256); + return unless ($3 >= 0 && $3 < 256); + return unless ($4 >= 0 && $4 < 256); return 1; } |