dependencies/validate.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 56 CC 7 SCAR 31.5
CC
7
Cov
0%
isIpv6
30.0
isIpv4
12.0
CRAP 23.2
1 # Copyright 1997 - 2019 by IXIA Keysight
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"),
5 # to deal in the Software without restriction, including without limitation
6 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 # and/or sell copies of the Software, and to permit persons to whom the
8 # Software is furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 # THE SOFTWARE.
20 package validate;
21 my $LEVEL = 1;
22
23 #------------------------------------------------------------------------------
24 # Verify if a address is IPv6
25 #------------------------------------------------------------------------------
26 sub isIpv6 {
27 my $address = @_[0];
28 my @addressBytes = split(':', $address);
29 my $isIpv6Addr = 0;
30 my $len = @addressBytes;
31 if ($len <= 8) {
32 foreach $bytes (@addressBytes) {
33 if (length($bytes) <= 4) {
34 if ($bytes ne '') {
35 if (($bytes =~ /[a-f,A-F]|[0-9]/) &&
36 !($bytes =~ /[g-z,G-Z]/)) {
37 $isIpv6Addr = 1;
38 } else {
39 $isIpv6Addr = 0;
40 return $isIpv6Addr;
41 }
42 }
43 } else {
44 $isIpv6 = 0;
45 return $isIpv6Addr
46 }
47 }
48 }
49 return $isIpv6Addr;
50 }
51
52 #------------------------------------------------------------------------------
53 # Verify if a address is IPv4
54 #------------------------------------------------------------------------------
55 sub isIpv4 {
56 $DB::single=1;
57 my $address = @_[0];
58 my @addressBytes = split('\.', $address);
59 my $isIpv4Addr = 0;
60
61 my $len = @addressBytes;
62 if ($len == 4) {
63 foreach $bytes (@addressBytes) {
64 if ((int($bytes) >= 0) && (int($bytes) <= 255)) {
65 $isIpv4Addr = 1;
66 } else {
67 $isIpv4Addr = 0;
68 return $isIpv4Addr
69 }
70 }
71 }
72 return $isIpv4Addr;
73 }
74
75 1;