Filename | /usr/local/lib/perl5/site_perl/mach/5.24/NetAddr/IP/Util.pm |
Statements | Executed 75 statements in 3.51ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 335µs | 458µs | BEGIN@10 | NetAddr::IP::Util::
2 | 2 | 2 | 181µs | 2.18ms | import | NetAddr::IP::Util::
23 | 2 | 1 | 82µs | 82µs | notcontiguous (xsub) | NetAddr::IP::Util::
1 | 1 | 1 | 78µs | 78µs | bootstrap (xsub) | NetAddr::IP::Util::
10 | 3 | 1 | 62µs | 62µs | shiftleft (xsub) | NetAddr::IP::Util::
1 | 1 | 1 | 60µs | 6.04ms | BEGIN@198 | NetAddr::IP::UtilPolluted::
1 | 1 | 1 | 53µs | 67µs | BEGIN@4 | NetAddr::IP::Util::
8 | 2 | 1 | 47µs | 47µs | ipv4to6 (xsub) | NetAddr::IP::Util::
1 | 1 | 1 | 25µs | 318µs | BEGIN@8 | NetAddr::IP::Util::
1 | 1 | 1 | 23µs | 336µs | BEGIN@9 | NetAddr::IP::Util::
1 | 1 | 1 | 22µs | 31µs | BEGIN@197 | NetAddr::IP::UtilPolluted::
2 | 1 | 1 | 22µs | 22µs | hasbits (xsub) | NetAddr::IP::Util::
1 | 1 | 1 | 19µs | 1.30ms | BEGIN@11 | NetAddr::IP::Util::
1 | 1 | 1 | 17µs | 17µs | CORE:match (opcode) | NetAddr::IP::Util::
1 | 1 | 1 | 12µs | 12µs | mask4to6 (xsub) | NetAddr::IP::Util::
2 | 1 | 1 | 7µs | 7µs | sub128 (xsub) | NetAddr::IP::Util::
0 | 0 | 0 | 0s | 0s | DESTROY | NetAddr::IP::Util::
0 | 0 | 0 | 0s | 0s | havegethostbyname2 | NetAddr::IP::Util::
0 | 0 | 0 | 0s | 0s | inet_4map6 | NetAddr::IP::Util::
0 | 0 | 0 | 0s | 0s | mode | NetAddr::IP::Util::
0 | 0 | 0 | 0s | 0s | naip_gethostbyname | NetAddr::IP::Util::
0 | 0 | 0 | 0s | 0s | __ANON__[:237] | NetAddr::IP::UtilPolluted::
0 | 0 | 0 | 0s | 0s | __ANON__[:245] | NetAddr::IP::UtilPolluted::
0 | 0 | 0 | 0s | 0s | __ANON__[:255] | NetAddr::IP::UtilPolluted::
0 | 0 | 0 | 0s | 0s | _end_gethostbyname | NetAddr::IP::UtilPolluted::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | #!/usr/bin/perl | ||||
2 | package NetAddr::IP::Util; | ||||
3 | |||||
4 | 2 | 97µs | 2 | 81µs | # spent 67µs (53+14) within NetAddr::IP::Util::BEGIN@4 which was called:
# once (53µs+14µs) by NetAddr::IP::Lite::BEGIN@18 at line 4 # spent 67µs making 1 call to NetAddr::IP::Util::BEGIN@4
# spent 14µs making 1 call to strict::import |
5 | #use diagnostics; | ||||
6 | #use lib qw(blib/lib); | ||||
7 | |||||
8 | 2 | 74µs | 2 | 611µs | # spent 318µs (25+293) within NetAddr::IP::Util::BEGIN@8 which was called:
# once (25µs+293µs) by NetAddr::IP::Lite::BEGIN@18 at line 8 # spent 318µs making 1 call to NetAddr::IP::Util::BEGIN@8
# spent 293µs making 1 call to vars::import |
9 | 2 | 79µs | 2 | 650µs | # spent 336µs (23+313) within NetAddr::IP::Util::BEGIN@9 which was called:
# once (23µs+313µs) by NetAddr::IP::Lite::BEGIN@18 at line 9 # spent 336µs making 1 call to NetAddr::IP::Util::BEGIN@9
# spent 313µs making 1 call to AutoLoader::import |
10 | 2 | 297µs | 1 | 458µs | # spent 458µs (335+123) within NetAddr::IP::Util::BEGIN@10 which was called:
# once (335µs+123µs) by NetAddr::IP::Lite::BEGIN@18 at line 10 # spent 458µs making 1 call to NetAddr::IP::Util::BEGIN@10 |
11 | 1 | 2µs | # spent 1.30ms (19µs+1.28) within NetAddr::IP::Util::BEGIN@11 which was called:
# once (19µs+1.28ms) by NetAddr::IP::Lite::BEGIN@18 at line 14 | ||
12 | :upper | ||||
13 | :all | ||||
14 | 1 | 1.08ms | 2 | 2.58ms | ); # spent 1.30ms making 1 call to NetAddr::IP::Util::BEGIN@11
# spent 1.28ms making 1 call to NetAddr::IP::InetBase::import |
15 | |||||
16 | 1 | 3µs | *NetAddr::IP::Util::upper = \&NetAddr::IP::InetBase::upper; | ||
17 | 1 | 2µs | *NetAddr::IP::Util::lower = \&NetAddr::IP::InetBase::lower; | ||
18 | |||||
19 | 1 | 2µs | require DynaLoader; | ||
20 | 1 | 2µs | require Exporter; | ||
21 | |||||
22 | 1 | 25µs | @ISA = qw(Exporter DynaLoader); | ||
23 | |||||
24 | 3 | 50µs | 1 | 17µs | $VERSION = do { my @r = (q$Revision: 1.53 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # spent 17µs making 1 call to NetAddr::IP::Util::CORE:match |
25 | |||||
26 | 1 | 32µs | @EXPORT_OK = qw( | ||
27 | inet_aton | ||||
28 | inet_ntoa | ||||
29 | ipv6_aton | ||||
30 | ipv6_ntoa | ||||
31 | ipv6_n2x | ||||
32 | ipv6_n2d | ||||
33 | inet_any2n | ||||
34 | hasbits | ||||
35 | isIPv4 | ||||
36 | isNewIPv4 | ||||
37 | isAnyIPv4 | ||||
38 | inet_n2dx | ||||
39 | inet_n2ad | ||||
40 | inet_pton | ||||
41 | inet_ntop | ||||
42 | inet_4map6 | ||||
43 | shiftleft | ||||
44 | addconst | ||||
45 | add128 | ||||
46 | sub128 | ||||
47 | notcontiguous | ||||
48 | bin2bcd | ||||
49 | bcd2bin | ||||
50 | mode | ||||
51 | ipv4to6 | ||||
52 | mask4to6 | ||||
53 | ipanyto6 | ||||
54 | maskanyto6 | ||||
55 | ipv6to4 | ||||
56 | bin2bcdn | ||||
57 | bcdn2txt | ||||
58 | bcdn2bin | ||||
59 | simple_pack | ||||
60 | comp128 | ||||
61 | packzeros | ||||
62 | AF_INET | ||||
63 | AF_INET6 | ||||
64 | naip_gethostbyname | ||||
65 | havegethostbyname2 | ||||
66 | ); | ||||
67 | |||||
68 | 1 | 28µs | %EXPORT_TAGS = ( | ||
69 | all => [@EXPORT_OK], | ||||
70 | inet => [qw( | ||||
71 | inet_aton | ||||
72 | inet_ntoa | ||||
73 | ipv6_aton | ||||
74 | ipv6_ntoa | ||||
75 | ipv6_n2x | ||||
76 | ipv6_n2d | ||||
77 | inet_any2n | ||||
78 | inet_n2dx | ||||
79 | inet_n2ad | ||||
80 | inet_pton | ||||
81 | inet_ntop | ||||
82 | inet_4map6 | ||||
83 | ipv4to6 | ||||
84 | mask4to6 | ||||
85 | ipanyto6 | ||||
86 | maskanyto6 | ||||
87 | ipv6to4 | ||||
88 | packzeros | ||||
89 | naip_gethostbyname | ||||
90 | )], | ||||
91 | math => [qw( | ||||
92 | shiftleft | ||||
93 | hasbits | ||||
94 | isIPv4 | ||||
95 | isNewIPv4 | ||||
96 | isAnyIPv4 | ||||
97 | addconst | ||||
98 | add128 | ||||
99 | sub128 | ||||
100 | notcontiguous | ||||
101 | bin2bcd | ||||
102 | bcd2bin | ||||
103 | )], | ||||
104 | ipv4 => [qw( | ||||
105 | inet_aton | ||||
106 | inet_ntoa | ||||
107 | )], | ||||
108 | ipv6 => [qw( | ||||
109 | ipv6_aton | ||||
110 | ipv6_ntoa | ||||
111 | ipv6_n2x | ||||
112 | ipv6_n2d | ||||
113 | inet_any2n | ||||
114 | inet_n2dx | ||||
115 | inet_n2ad | ||||
116 | inet_pton | ||||
117 | inet_ntop | ||||
118 | inet_4map6 | ||||
119 | ipv4to6 | ||||
120 | mask4to6 | ||||
121 | ipanyto6 | ||||
122 | maskanyto6 | ||||
123 | ipv6to4 | ||||
124 | packzeros | ||||
125 | naip_gethostbyname | ||||
126 | )], | ||||
127 | ); | ||||
128 | |||||
129 | 1 | 14µs | 1 | 5µs | if (NetAddr::IP::Util_IS->not_pure) { # spent 5µs making 1 call to NetAddr::IP::Util_IS::not_pure |
130 | 1 | 3µs | eval { ## attempt to load 'C' version of utilities | ||
131 | 1 | 21µs | 1 | 609µs | bootstrap NetAddr::IP::Util $VERSION; # spent 609µs making 1 call to DynaLoader::bootstrap |
132 | }; | ||||
133 | } | ||||
134 | 1 | 8µs | 1 | 11µs | if (NetAddr::IP::Util_IS->pure || $@) { ## load the pure perl version if 'C' lib missing # spent 11µs making 1 call to NetAddr::IP::Util_IS::pure |
135 | require NetAddr::IP::UtilPP; | ||||
136 | import NetAddr::IP::UtilPP qw( :all ); | ||||
137 | # require Socket; | ||||
138 | # import Socket qw(inet_ntoa); | ||||
139 | # *yinet_aton = \&Socket::inet_aton; | ||||
140 | $Mode = 'Pure Perl'; | ||||
141 | } | ||||
142 | else { | ||||
143 | 1 | 2µs | $Mode = 'CC XS'; | ||
144 | } | ||||
145 | |||||
146 | # if Socket lib is broken in some way, check for overange values | ||||
147 | # | ||||
148 | #my $overange = yinet_aton('256.1') ? 1:0; | ||||
149 | #my $overange = gethostbyname('256.1') ? 1:0; | ||||
150 | |||||
151 | sub mode() { $Mode }; | ||||
152 | |||||
153 | 1 | 2µs | 1 | 8µs | my $_newV4compat = pack('N4',0,0,0xffff,0); # spent 8µs making 1 call to main::CORE:pack |
154 | |||||
155 | sub inet_4map6 { | ||||
156 | my $naddr = shift; | ||||
157 | if (length($naddr) == 4) { | ||||
158 | $naddr = ipv4to6($naddr); | ||||
159 | } | ||||
160 | elsif (length($naddr) == 16) { | ||||
161 | ; # is OK | ||||
162 | return undef unless isAnyIPv4($naddr); | ||||
163 | } else { | ||||
164 | return undef; | ||||
165 | } | ||||
166 | $naddr |= $_newV4compat; | ||||
167 | return $naddr; | ||||
168 | } | ||||
169 | |||||
170 | sub DESTROY {}; | ||||
171 | |||||
172 | 1 | 2µs | my $havegethostbyname2 = 0; | ||
173 | |||||
174 | 1 | 1µs | my $mygethostbyname; | ||
175 | |||||
176 | 1 | 2µs | my $_Sock6ok = 1; # for testing gethostbyname | ||
177 | |||||
178 | sub havegethostbyname2 { | ||||
179 | return $_Sock6ok | ||||
180 | ? $havegethostbyname2 | ||||
181 | : 0; | ||||
182 | } | ||||
183 | |||||
184 | # spent 2.18ms (181µs+2.00) within NetAddr::IP::Util::import which was called 2 times, avg 1.09ms/call:
# once (81µs+1.15ms) by NetAddr::IP::Lite::BEGIN@18 at line 31 of NetAddr/IP/Lite.pm
# once (99µs+858µs) by NetAddr::IP::BEGIN@9 at line 21 of NetAddr/IP.pm | ||||
185 | 27 | 123µs | if (grep { $_ eq ':noSock6' } @_) { | ||
186 | $_Sock6ok = 0; | ||||
187 | @_ = grep { $_ ne ':noSock6' } @_; | ||||
188 | } | ||||
189 | 2 | 39µs | 2 | 141µs | NetAddr::IP::Util->export_to_level(1,@_); # spent 141µs making 2 calls to Exporter::export_to_level, avg 70µs/call |
190 | } | ||||
191 | |||||
192 | package NetAddr::IP::UtilPolluted; | ||||
193 | |||||
194 | # Socket pollutes the name space with all of its symbols. Since | ||||
195 | # we don't want them all, confine them to this name space. | ||||
196 | |||||
197 | 2 | 97µs | 2 | 40µs | # spent 31µs (22+9) within NetAddr::IP::UtilPolluted::BEGIN@197 which was called:
# once (22µs+9µs) by NetAddr::IP::Lite::BEGIN@18 at line 197 # spent 31µs making 1 call to NetAddr::IP::UtilPolluted::BEGIN@197
# spent 9µs making 1 call to strict::import |
198 | 2 | 992µs | 2 | 12.0ms | # spent 6.04ms (60µs+5.98) within NetAddr::IP::UtilPolluted::BEGIN@198 which was called:
# once (60µs+5.98ms) by NetAddr::IP::Lite::BEGIN@18 at line 198 # spent 6.04ms making 1 call to NetAddr::IP::UtilPolluted::BEGIN@198
# spent 5.98ms making 1 call to Exporter::import |
199 | |||||
200 | 1 | 2µs | 1 | 9µs | my $_v4zero = pack('L',0); # spent 9µs making 1 call to main::CORE:pack |
201 | 1 | 2µs | 1 | 3µs | my $_zero = pack('L4',0,0,0,0); # spent 3µs making 1 call to main::CORE:pack |
202 | |||||
203 | # invoke replacement subroutine for Perl's "gethostbyname" | ||||
204 | # if Socket6 is available. | ||||
205 | # | ||||
206 | # NOTE: in certain BSD implementations, Perl's gethostbyname is broken | ||||
207 | # we will use our own InetBase::inet_aton instead | ||||
208 | |||||
209 | sub _end_gethostbyname { | ||||
210 | # my ($name,$aliases,$addrtype,$length,@addrs) = @_; | ||||
211 | my @rv = @_; | ||||
212 | # first ip address = rv[4] | ||||
213 | my $tip = $rv[4]; | ||||
214 | unless ($tip && $tip ne $_v4zero && $tip ne $_zero) { | ||||
215 | @rv = (); | ||||
216 | } | ||||
217 | # length = rv[3] | ||||
218 | elsif ($rv[3] && $rv[3] == 4) { | ||||
219 | foreach (4..$#rv) { | ||||
220 | $rv[$_] = NetAddr::IP::Util::inet_4map6(NetAddr::IP::Util::ipv4to6($rv[$_])); | ||||
221 | } | ||||
222 | $rv[3] = 16; # unconditionally set length to 16 | ||||
223 | } | ||||
224 | elsif ($rv[3] == 16) { | ||||
225 | ; # is ok | ||||
226 | } else { | ||||
227 | @rv = (); | ||||
228 | } | ||||
229 | return @rv; | ||||
230 | } | ||||
231 | |||||
232 | 2 | 19µs | unless ( eval { require Socket6 }) { | ||
233 | $mygethostbyname = sub { | ||||
234 | # SEE NOTE above about broken BSD | ||||
235 | my @tip = gethostbyname(NetAddr::IP::InetBase::fillIPv4($_[0])); | ||||
236 | return &_end_gethostbyname(@tip); | ||||
237 | }; | ||||
238 | } else { | ||||
239 | 1 | 8µs | 1 | 218µs | import Socket6 qw( gethostbyname2 getipnodebyname ); # spent 218µs making 1 call to Exporter::import |
240 | 3 | 289µs | 1 | 261µs | my $try = eval { my @try = gethostbyname2('127.0.0.1',NetAddr::IP::Util::AF_INET()); $try[4] }; # spent 261µs making 1 call to Socket6::gethostbyname2 |
241 | 1 | 4µs | if (! $@ && $try && $try eq INADDR_LOOPBACK()) { | ||
242 | 1 | 3µs | *_ghbn2 = \&Socket6::gethostbyname2; | ||
243 | 1 | 2µs | $havegethostbyname2 = 1; | ||
244 | } else { | ||||
245 | *_ghbn2 = sub { return () }; # use failure branch below | ||||
246 | } | ||||
247 | |||||
248 | $mygethostbyname = sub { | ||||
249 | my @tip; | ||||
250 | unless ($_Sock6ok && (@tip = _ghbn2($_[0],NetAddr::IP::Util::AF_INET6())) && @tip > 1) { | ||||
251 | # SEE NOTE above about broken BSD | ||||
252 | @tip = gethostbyname(NetAddr::IP::InetBase::fillIPv4($_[0])); | ||||
253 | } | ||||
254 | return &_end_gethostbyname(@tip); | ||||
255 | 1 | 18µs | }; | ||
256 | } | ||||
257 | |||||
258 | package NetAddr::IP::Util; | ||||
259 | |||||
260 | sub naip_gethostbyname { | ||||
261 | # turn off complaint from Socket6 about missing numeric argument | ||||
262 | undef local $^W; | ||||
263 | my @rv = &$mygethostbyname($_[0]); | ||||
264 | return wantarray | ||||
265 | ? @rv | ||||
266 | : $rv[4]; | ||||
267 | } | ||||
268 | |||||
269 | 1 | 86µs | 1; | ||
270 | |||||
271 | __END__ | ||||
# spent 17µs within NetAddr::IP::Util::CORE:match which was called:
# once (17µs+0s) by NetAddr::IP::Lite::BEGIN@18 at line 24 | |||||
# spent 78µs within NetAddr::IP::Util::bootstrap which was called:
# once (78µs+0s) by DynaLoader::bootstrap at line 210 of DynaLoader.pm | |||||
# spent 22µs within NetAddr::IP::Util::hasbits which was called 2 times, avg 11µs/call:
# 2 times (22µs+0s) by NetAddr::IP::Lite::within at line 1355 of NetAddr/IP/Lite.pm, avg 11µs/call | |||||
# spent 47µs within NetAddr::IP::Util::ipv4to6 which was called 8 times, avg 6µs/call:
# 6 times (41µs+0s) by NetAddr::IP::Lite::_xnew at line 1038 of NetAddr/IP/Lite.pm, avg 7µs/call
# 2 times (6µs+0s) by NetAddr::IP::Lite::_xnew at line 868 of NetAddr/IP/Lite.pm, avg 3µs/call | |||||
# spent 12µs within NetAddr::IP::Util::mask4to6 which was called:
# once (12µs+0s) by NetAddr::IP::BEGIN@8 at line 647 of NetAddr/IP/Lite.pm | |||||
# spent 82µs within NetAddr::IP::Util::notcontiguous which was called 23 times, avg 4µs/call:
# 19 times (70µs+0s) by NetAddr::IP::Lite::_xnew at line 1054 of NetAddr/IP/Lite.pm, avg 4µs/call
# 4 times (12µs+0s) by NetAddr::IP::Lite::masklen at line 1130 of NetAddr/IP/Lite.pm, avg 3µs/call | |||||
# spent 62µs within NetAddr::IP::Util::shiftleft which was called 10 times, avg 6µs/call:
# 6 times (45µs+0s) by NetAddr::IP::Lite::_xnew at line 889 of NetAddr/IP/Lite.pm, avg 7µs/call
# 2 times (9µs+0s) by NetAddr::IP::Lite::_xnew at line 879 of NetAddr/IP/Lite.pm, avg 4µs/call
# 2 times (9µs+0s) by NetAddr::IP::Lite::_xnew at line 870 of NetAddr/IP/Lite.pm, avg 4µs/call | |||||
# spent 7µs within NetAddr::IP::Util::sub128 which was called 2 times, avg 4µs/call:
# 2 times (7µs+0s) by NetAddr::IP::Lite::within at line 1360 of NetAddr/IP/Lite.pm, avg 4µs/call |