File: bisIPv4.t

package info (click to toggle)
libnetaddr-ip-perl 4.079%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 1,580 kB
  • ctags: 251
  • sloc: perl: 1,417; cpp: 67; sh: 51; makefile: 9
file content (186 lines) | stat: -rw-r--r-- 2,957 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)

BEGIN { $| = 1; print "1..421\n"; }
END {print "not ok 1\n" unless $loaded;}

use NetAddr::IP::InetBase qw(
	:upper
	ipv6_aton
	ipv6_n2x
	isIPv4
	isNewIPv4
	isAnyIPv4
);

$loaded = 1;
print "ok 1\n";
######################### End of black magic.

# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):

$test = 2;

sub ok {
  print "ok $test\n";
  ++$test;
}

my @num = qw	# input
(
	::
	8000::
	4000::
	2000::
	1000::
	800::
	400::
	200::
	100::
	80::
	40::
	20::
	10::
	1::
	0:8000::
	0:4000::
	0:2000::
	0:1000::
	0:800::
	0:400::
	0:200::
	0:100::
	0:80::
	0:40::
	0:20::
	0:10::
	0:1::
	0:0:8000::
	0:0:4000::
	0:0:2000::
	0:0:1000::
	0:0:800::
	0:0:400::
	0:0:200::
	0:0:100::
	0:0:80::
	0:0:40::
	0:0:20::
	0:0:10::
	0:0:1::
	0:0:0:8000::
	0:0:0:4000::
	0:0:0:2000::
	0:0:0:1000::
	0:0:0:800::
	0:0:0:400::
	0:0:0:200::
	0:0:0:100::
	0:0:0:80::
	0:0:0:40::
	0:0:0:20::
	0:0:0:10::
	0:0:0:1::
	0:0:0:0:8000::
	0:0:0:0:4000::
	0:0:0:0:2000::
	0:0:0:0:1000::
	0:0:0:0:800::
	0:0:0:0:400::
	0:0:0:0:200::
	0:0:0:0:100::
	0:0:0:0:80::
	0:0:0:0:40::
	0:0:0:0:20::
	0:0:0:0:10::
	0:0:0:0:1::
	0:0:0:0:0:8000::
	0:0:0:0:0:4000::
	0:0:0:0:0:2000::
	0:0:0:0:0:1000::
	0:0:0:0:0:800::
	0:0:0:0:0:400::
	0:0:0:0:0:200::
	0:0:0:0:0:100::
	0:0:0:0:0:80::
	0:0:0:0:0:40::
	0:0:0:0:0:20::
	0:0:0:0:0:10::
	0:0:0:0:0:1::
	::8000:0
	::4000:0
	::2000:0
	::1000:0
	::800:0
	::400:0
	::200:0
	::100:0
	::80:0
	::40:0
	::20:0
	::10:0
	::1:0
	::8000
	::4000
	::2000
	::1000
	::800
	::400
	::200
	::100
	::80
	::40
	::20
	::10
	::1
);

# check isIPv4

foreach (@num) {
  my $bstr = ipv6_aton($_);
  my $rv = isIPv4($bstr);
  my $exp = ($_ =~ /\d::$/) ? 0:1;
  print "got: $rv, exp: $exp for ", ipv6_n2x($bstr), "\nnot "
	 unless $rv eq $exp;
  &ok;
}

# check isAnyIPv4
foreach (@num) {
  my $bstr = ipv6_aton($_);
  my $rv = isAnyIPv4($bstr);
  my $exp = ($_ =~ /\d::$/) ? 0:1;
  print "got: $rv, exp: $exp for ", ipv6_n2x($bstr), "\nnot "
	 unless $rv eq $exp;
  &ok;
}

my $compat = ipv6_aton('::FFFF:0:0');

# check isAnyIPv4	with compatible high bits
foreach (@num) {
  my $bstr = ipv6_aton($_);
  $bstr ^= $compat;
  my $rv = isAnyIPv4($bstr);
  my $exp = ($_ =~ /\d::$/) ? 0:1;
  print "got: $rv, exp: $exp for ", ipv6_n2x($bstr), "\nnot "
	 unless $rv eq $exp;
  &ok;
}
# check isNewIPv4	with compatible high bits
foreach (@num) {
  my $bstr = ipv6_aton($_);
  $bstr ^= $compat;
  my $rv = isNewIPv4($bstr);
  my $exp = ($_ =~ /\d::$/) ? 0:1;
  print "got: $rv, exp: $exp for ", ipv6_n2x($bstr), "\nnot "
	 unless $rv eq $exp;
  &ok;
}