line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl
|
2
|
|
|
|
|
|
|
package FTN::Addr;
|
3
|
|
|
|
|
|
|
our $VERSION = '20090704';
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
86106
|
use strict;
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
163
|
|
6
|
4
|
|
|
4
|
|
23
|
use warnings;
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
136
|
|
7
|
|
|
|
|
|
|
#use base = qw(Exporter);
|
8
|
|
|
|
|
|
|
#our @EXPORT = ();
|
9
|
|
|
|
|
|
|
#our @EXPORT_OK = ();
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
24
|
use Carp qw(croak);
|
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
478
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use overload
|
14
|
4
|
|
|
|
|
33
|
"eq" => \&eq_,
|
15
|
|
|
|
|
|
|
"cmp" => \&cmp_,
|
16
|
4
|
|
|
4
|
|
6738
|
fallback => 1;
|
|
4
|
|
|
|
|
4241
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $default_domain = "fidonet";
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub set_results($) {
|
21
|
30
|
|
|
30
|
0
|
45
|
my $t = shift;
|
22
|
30
|
|
|
|
|
132
|
$t -> {full4d} = "$t->{zone}:$t->{net}/$t->{node}.$t->{point}";
|
23
|
30
|
|
|
|
|
91
|
$t -> {full5d} = $t -> {full4d} . "\@$t->{domain}";
|
24
|
30
|
100
|
|
|
|
159
|
$t -> {short4d} = "$t->{zone}:$t->{net}/$t->{node}" . ($t -> {point}? ".$t->{point}" : '');
|
25
|
30
|
|
|
|
|
84
|
$t -> {short5d} = $t -> {short4d} . "\@$t->{domain}";
|
26
|
30
|
|
|
|
|
103
|
$t -> {fqfa} = "$t->{domain}#$t->{zone}:$t->{net}/$t->{node}.$t->{point}";
|
27
|
30
|
|
|
|
|
126
|
$t -> {brake_style} = "$t->{domain}.$t->{zone}.$t->{net}.$t->{node}.$t->{point}";
|
28
|
|
|
|
|
|
|
}
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new($$;$) {
|
31
|
29
|
|
|
29
|
1
|
4870
|
my $either = shift;
|
32
|
29
|
|
66
|
|
|
137
|
my $class = ref($either) || $either;
|
33
|
29
|
|
|
|
|
45
|
my $addr = shift;
|
34
|
29
|
|
|
|
|
36
|
my $base_addr = shift;
|
35
|
29
|
50
|
66
|
|
|
213
|
$base_addr = undef unless defined($base_addr) && ref($base_addr) && $base_addr -> isa('FTN::Addr');
|
|
|
|
66
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
29
|
100
|
|
|
|
71
|
if (ref $either) {
|
38
|
9
|
|
|
|
|
40
|
%$either = ();
|
39
|
|
|
|
|
|
|
} else {
|
40
|
20
|
|
|
|
|
38
|
$either = {};
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# let's figure domain
|
44
|
29
|
50
|
|
|
|
155
|
if ($addr =~ m!(\w+)#([\d:/.]+)!) { # fidonet#2:451/31.0
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
$either -> {domain} = $1;
|
46
|
0
|
|
|
|
|
0
|
$addr = $2;
|
47
|
|
|
|
|
|
|
} elsif ($addr =~ m!([\d:/.]+)@(\w+)!) { # 2:451/31.0@fidonet
|
48
|
6
|
|
|
|
|
21
|
$either -> {domain} = $2;
|
49
|
6
|
|
|
|
|
12
|
$addr = $1;
|
50
|
|
|
|
|
|
|
} elsif ($addr =~ m!(\w+)\.(\d+\.\d+\.\d+\.\d+)!) { # fidonet.2.451.31.0
|
51
|
0
|
|
|
|
|
0
|
$either -> {domain} = $1;
|
52
|
0
|
|
|
|
|
0
|
$addr = $2;
|
53
|
|
|
|
|
|
|
} else {
|
54
|
23
|
100
|
|
|
|
110
|
$either -> {domain} = $base_addr? $base_addr -> {domain} : $default_domain;
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# and the rest of the address
|
58
|
29
|
100
|
|
|
|
201
|
if ($addr =~ m!^(\d+):(\d+)/(\d+)\.?(\d*)$!) { # 2:451/31.0 or 2:451/31
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
59
|
17
|
|
|
|
|
60
|
$either -> {zone} = $1;
|
60
|
17
|
|
|
|
|
46
|
$either -> {net} = $2;
|
61
|
17
|
|
|
|
|
52
|
$either -> {node} = $3;
|
62
|
17
|
|
100
|
|
|
90
|
$either -> {point} = $4 || 0;
|
63
|
|
|
|
|
|
|
} elsif ($addr =~ m!^\.(\d+)$!) { # addr as .4
|
64
|
1
|
50
|
|
|
|
3
|
if ($base_addr) {
|
65
|
1
|
|
|
|
|
4
|
$either -> {zone} = $base_addr -> zone;
|
66
|
1
|
|
|
|
|
4
|
$either -> {net} = $base_addr -> net;
|
67
|
1
|
|
|
|
|
3
|
$either -> {node} = $base_addr -> node;
|
68
|
1
|
|
|
|
|
3
|
$either -> {point} = $1;
|
69
|
|
|
|
|
|
|
} else { # no base addr - no way to get full addr...
|
70
|
0
|
|
|
|
|
0
|
return undef;
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
} elsif ($addr =~ m!^(\d+)\.?(\d*)$!) { # addr as 31 or 31.6
|
73
|
7
|
50
|
|
|
|
15
|
if ($base_addr) {
|
74
|
7
|
|
|
|
|
18
|
$either -> {zone} = $base_addr -> zone;
|
75
|
7
|
|
|
|
|
16
|
$either -> {net} = $base_addr -> net;
|
76
|
7
|
|
|
|
|
19
|
$either -> {node} = $1;
|
77
|
7
|
|
100
|
|
|
37
|
$either -> {point} = $2 || 0;
|
78
|
|
|
|
|
|
|
} else { # no base addr - no way to get full addr...
|
79
|
0
|
|
|
|
|
0
|
return undef;
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
} elsif ($addr =~ m!^(\d+)/(\d+)\.?(\d*)$!) { # addr as 451/31 or 451/31.6
|
82
|
4
|
50
|
|
|
|
10
|
if ($base_addr) {
|
83
|
4
|
|
|
|
|
12
|
$either -> {zone} = $base_addr -> zone;
|
84
|
4
|
|
|
|
|
13
|
$either -> {net} = $1;
|
85
|
4
|
|
|
|
|
12
|
$either -> {node} = $2;
|
86
|
4
|
|
50
|
|
|
26
|
$either -> {point} = $3 || 0;
|
87
|
|
|
|
|
|
|
} else { # no base addr - no way to get full addr...
|
88
|
0
|
|
|
|
|
0
|
return undef;
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
} elsif ($addr =~ m!^(\d+)\.(\d+)\.(\d+)\.(\d+)$!) { # addr as 2.451.31.0 - brake style
|
91
|
0
|
|
|
|
|
0
|
$either -> {zone} = $1;
|
92
|
0
|
|
|
|
|
0
|
$either -> {net} = $2;
|
93
|
0
|
|
|
|
|
0
|
$either -> {node} = $3;
|
94
|
0
|
|
|
|
|
0
|
$either -> {point} = $4;
|
95
|
|
|
|
|
|
|
} else {
|
96
|
0
|
|
|
|
|
0
|
return undef;
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# some checking for correctness...
|
100
|
29
|
50
|
33
|
|
|
766
|
unless (1 <= $either -> {zone} && $either -> {zone} <= 32767 # FRL-1002.001
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
101
|
|
|
|
|
|
|
&& 1 <= $either -> {net} && $either -> {net} <= 32767 # FRL-1002.001
|
102
|
|
|
|
|
|
|
&& -1 <= $either -> {node} && $either -> {node} <= 32767 # FRL-1002.001
|
103
|
|
|
|
|
|
|
&& 0 <= $either -> {point} && $either -> {point} <= 32767 # FRL-1002.001
|
104
|
|
|
|
|
|
|
&& length($either -> {domain}) <= 8 # FRL-1002.001
|
105
|
|
|
|
|
|
|
&& index($either -> {domain}, '.') == -1) { # FRL-1002.001
|
106
|
0
|
|
|
|
|
0
|
%$either = ();
|
107
|
0
|
|
|
|
|
0
|
return undef;
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
|
110
|
29
|
|
|
|
|
81
|
set_results($either);
|
111
|
29
|
|
|
|
|
110
|
bless $either, $class;
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub domain($) {
|
115
|
29
|
50
|
|
29
|
1
|
19069
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
116
|
29
|
|
|
|
|
247
|
$inst -> {domain};
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub set_domain($$) {
|
120
|
1
|
50
|
|
1
|
1
|
6
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
121
|
1
|
|
|
|
|
2
|
my $d = shift;
|
122
|
1
|
|
33
|
|
|
5
|
$inst -> {domain} = $d || $default_domain;
|
123
|
1
|
|
|
|
|
20
|
set_results($inst);
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub zone($) {
|
127
|
39
|
50
|
|
39
|
1
|
113
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
128
|
39
|
|
|
|
|
190
|
$inst -> {zone};
|
129
|
|
|
|
|
|
|
}
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub set_zone($$) {
|
132
|
0
|
0
|
|
0
|
1
|
0
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
133
|
0
|
|
|
|
|
0
|
$inst -> {zone} = shift;
|
134
|
0
|
|
|
|
|
0
|
set_results($inst);
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub net($) {
|
138
|
35
|
50
|
|
35
|
1
|
106
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
139
|
35
|
|
|
|
|
439
|
$inst -> {net};
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub set_net($$) {
|
143
|
0
|
0
|
|
0
|
1
|
0
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
144
|
0
|
|
|
|
|
0
|
$inst -> {net} = shift;
|
145
|
0
|
|
|
|
|
0
|
set_results($inst);
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub node($) {
|
149
|
28
|
50
|
|
28
|
1
|
89
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
150
|
28
|
|
|
|
|
149
|
$inst -> {node};
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub set_node($$) {
|
154
|
0
|
0
|
|
0
|
1
|
0
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
155
|
0
|
|
|
|
|
0
|
$inst -> {node} = shift;
|
156
|
0
|
|
|
|
|
0
|
set_results($inst);
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub point($) {
|
160
|
27
|
50
|
|
27
|
1
|
91
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
161
|
27
|
|
|
|
|
151
|
$inst -> {point};
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub set_point($$) {
|
165
|
0
|
0
|
|
0
|
1
|
0
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
166
|
0
|
|
|
|
|
0
|
$inst -> {point} = shift;
|
167
|
0
|
|
|
|
|
0
|
set_results($inst);
|
168
|
|
|
|
|
|
|
}
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub f4 {
|
171
|
22
|
50
|
|
22
|
1
|
69
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
172
|
22
|
|
|
|
|
662
|
$inst -> {full4d};
|
173
|
|
|
|
|
|
|
}
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub s4 {
|
176
|
22
|
50
|
|
22
|
1
|
573
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
177
|
22
|
|
|
|
|
118
|
$inst -> {short4d};
|
178
|
|
|
|
|
|
|
}
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub f5 {
|
181
|
22
|
50
|
|
22
|
1
|
78
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
182
|
22
|
|
|
|
|
111
|
$inst -> {full5d};
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub s5 {
|
186
|
22
|
50
|
|
22
|
1
|
67
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
187
|
22
|
|
|
|
|
116
|
$inst -> {short5d};
|
188
|
|
|
|
|
|
|
}
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub fqfa {
|
191
|
1
|
50
|
|
1
|
1
|
425
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
192
|
1
|
|
|
|
|
4
|
$inst -> {fqfa};
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub bs {
|
196
|
9
|
50
|
|
9
|
1
|
30
|
ref(my $inst = shift) or croak "I'm only instance method!";
|
197
|
9
|
|
|
|
|
42
|
$inst -> {brake_style};
|
198
|
|
|
|
|
|
|
}
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub eq_ { # eq operator
|
201
|
3
|
50
|
|
3
|
0
|
454
|
return undef unless $_[1] -> isa('FTN::Addr');
|
202
|
3
|
|
33
|
|
|
11
|
return lc($_[0] -> domain) eq lc($_[1] -> domain)
|
203
|
|
|
|
|
|
|
&& $_[0] -> zone == $_[1] -> zone && $_[0] -> net == $_[1] -> net
|
204
|
|
|
|
|
|
|
&& $_[0] -> node == $_[1] -> node && $_[0] -> point == $_[1] -> point;
|
205
|
|
|
|
|
|
|
}
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub cmp_ { # cmp operator
|
208
|
1
|
50
|
|
1
|
0
|
6
|
return undef unless $_[1] -> isa('FTN::Addr');
|
209
|
1
|
50
|
|
|
|
4
|
if ($_[2]) { # arguments were swapped
|
210
|
0
|
0
|
0
|
|
|
0
|
lc($_[1] -> domain) cmp lc($_[0] -> domain) || $_[1] -> zone <=> $_[0] -> zone
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
211
|
|
|
|
|
|
|
|| $_[1] -> net <=> $_[0] -> net || $_[1] -> node <=> $_[0] -> node || $_[1] -> point <=> $_[0] -> point;
|
212
|
|
|
|
|
|
|
} else {
|
213
|
1
|
0
|
33
|
|
|
5
|
lc($_[0] -> domain) cmp lc($_[1] -> domain) || $_[0] -> zone <=> $_[1] -> zone
|
|
|
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
214
|
|
|
|
|
|
|
|| $_[0] -> net <=> $_[1] -> net || $_[0] -> node <=> $_[1] -> node || $_[0] -> point <=> $_[1] -> point;
|
215
|
|
|
|
|
|
|
}
|
216
|
|
|
|
|
|
|
}
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub equal($$$) {
|
219
|
1
|
50
|
|
1
|
1
|
12
|
ref(my $class = shift) and croak "I'm only class method!";
|
220
|
1
|
50
|
|
|
|
8
|
return undef unless $_[0] -> isa('FTN::Addr');
|
221
|
1
|
|
|
|
|
3
|
eq_(@_);
|
222
|
|
|
|
|
|
|
}
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
1;
|
225
|
|
|
|
|
|
|
__END__
|