Filename | /usr/local/lib/perl5/site_perl/mach/5.24/Socket6.pm |
Statements | Executed 25 statements in 1.81ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 3.07ms | 3.83ms | BEGIN@215 | Socket6::
1 | 1 | 1 | 225µs | 225µs | gethostbyname2 (xsub) | Socket6::
1 | 1 | 1 | 138µs | 179µs | AUTOLOAD | Socket6::
1 | 1 | 1 | 58µs | 58µs | bootstrap (xsub) | Socket6::
1 | 1 | 1 | 50µs | 65µs | BEGIN@38 | Socket6::
4 | 1 | 1 | 30µs | 30µs | inet_pton (xsub) | Socket6::
1 | 1 | 1 | 29µs | 353µs | BEGIN@39 | Socket6::
1 | 1 | 1 | 27µs | 214µs | BEGIN@213 | Socket6::
1 | 1 | 1 | 25µs | 25µs | constant (xsub) | Socket6::
1 | 1 | 1 | 16µs | 16µs | CORE:subst (opcode) | Socket6::
0 | 0 | 0 | 0s | 0s | sockaddr_in6 | Socket6::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Copyright (C) 2000-2016 Hajimu UMEMOTO <ume@mahoroba.org>. | ||||
2 | # All rights reserved. | ||||
3 | # | ||||
4 | # This module is based on perl5.005_55-v6-19990721 written by KAME | ||||
5 | # Project. | ||||
6 | # | ||||
7 | # Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. | ||||
8 | # All rights reserved. | ||||
9 | # | ||||
10 | # Redistribution and use in source and binary forms, with or without | ||||
11 | # modification, are permitted provided that the following conditions | ||||
12 | # are met: | ||||
13 | # 1. Redistributions of source code must retain the above copyright | ||||
14 | # notice, this list of conditions and the following disclaimer. | ||||
15 | # 2. Redistributions in binary form must reproduce the above copyright | ||||
16 | # notice, this list of conditions and the following disclaimer in the | ||||
17 | # documentation and/or other materials provided with the distribution. | ||||
18 | # 3. Neither the name of the project nor the names of its contributors | ||||
19 | # may be used to endorse or promote products derived from this software | ||||
20 | # without specific prior written permission. | ||||
21 | # | ||||
22 | # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||||
23 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
24 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
25 | # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||||
26 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
27 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
28 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
29 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
30 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
31 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
32 | # SUCH DAMAGE. | ||||
33 | |||||
34 | # $Id: Socket6.pm 683 2016-07-11 05:45:26Z ume $ | ||||
35 | |||||
36 | package Socket6; | ||||
37 | |||||
38 | 2 | 79µs | 2 | 80µs | # spent 65µs (50+15) within Socket6::BEGIN@38 which was called:
# once (50µs+15µs) by NetAddr::IP::Lite::BEGIN@9 at line 38 # spent 65µs making 1 call to Socket6::BEGIN@38
# spent 15µs making 1 call to strict::import |
39 | 2 | 419µs | 2 | 677µs | # spent 353µs (29+324) within Socket6::BEGIN@39 which was called:
# once (29µs+324µs) by NetAddr::IP::Lite::BEGIN@9 at line 39 # spent 353µs making 1 call to Socket6::BEGIN@39
# spent 324µs making 1 call to vars::import |
40 | 1 | 2µs | $VERSION = "0.28"; | ||
41 | |||||
42 | =head1 NAME | ||||
43 | |||||
44 | Socket6 - IPv6 related part of the C socket.h defines and structure manipulators | ||||
45 | |||||
46 | =head1 SYNOPSIS | ||||
47 | |||||
48 | use Socket; | ||||
49 | use Socket6; | ||||
50 | |||||
51 | @res = getaddrinfo('hishost.com', 'daytime', AF_UNSPEC, SOCK_STREAM); | ||||
52 | $family = -1; | ||||
53 | while (scalar(@res) >= 5) { | ||||
54 | ($family, $socktype, $proto, $saddr, $canonname, @res) = @res; | ||||
55 | |||||
56 | ($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV); | ||||
57 | print STDERR "Trying to connect to $host port $port...\n"; | ||||
58 | |||||
59 | socket(Socket_Handle, $family, $socktype, $proto) || next; | ||||
60 | connect(Socket_Handle, $saddr) && last; | ||||
61 | |||||
62 | close(Socket_Handle); | ||||
63 | $family = -1; | ||||
64 | } | ||||
65 | |||||
66 | if ($family != -1) { | ||||
67 | print STDERR "connected to $host port $port\n"; | ||||
68 | } else { | ||||
69 | die "connect attempt failed\n"; | ||||
70 | } | ||||
71 | |||||
72 | =head1 DESCRIPTION | ||||
73 | |||||
74 | This module provides glue routines to the various IPv6 functions. | ||||
75 | |||||
76 | If you use the Socket6 module, | ||||
77 | be sure to specify "use Socket" as well as "use Socket6". | ||||
78 | |||||
79 | Functions supplied are: | ||||
80 | |||||
81 | =over | ||||
82 | |||||
83 | =item inet_pton FAMILY, TEXT_ADDRESS | ||||
84 | |||||
85 | This function takes an IP address in presentation (or string) format | ||||
86 | and converts it into numeric (or binary) format. | ||||
87 | The type of IP address conversion (IPv4 versus IPv6) is controlled | ||||
88 | by the FAMILY argument. | ||||
89 | |||||
90 | =item inet_ntop FAMILY, BINARY_ADDRESS | ||||
91 | |||||
92 | This function takes an IP address in numeric (or binary) format | ||||
93 | and converts it into presentation (or string) format | ||||
94 | The type of IP address conversion (IPv4 versus IPv6) is controlled | ||||
95 | by the FAMILY argument. | ||||
96 | |||||
97 | =item pack_sockaddr_in6 PORT, ADDR | ||||
98 | |||||
99 | This function takes two arguments: a port number, and a 16-octet | ||||
100 | IPv6 address structure (as returned by inet_pton()). | ||||
101 | It returns the sockaddr_in6 structure with these arguments packed | ||||
102 | into their correct fields, as well as the AF_INET6 family. | ||||
103 | The other fields are not set and their values should not be relied upon. | ||||
104 | |||||
105 | =item pack_sockaddr_in6_all PORT, FLOWINFO, ADDR, SCOPEID | ||||
106 | |||||
107 | This function takes four arguments: a port number, a 16-octet | ||||
108 | IPv6 address structure (as returned by inet_pton), any | ||||
109 | special flow information, and any specific scope information. | ||||
110 | It returns a complete sockaddr_in6 structure with these arguments packed | ||||
111 | into their correct fields, as well as the AF_INET6 family. | ||||
112 | |||||
113 | =item unpack_sockaddr_in6 NAME | ||||
114 | |||||
115 | This function takes a sockaddr_in6 structure (as returned by | ||||
116 | pack_sockaddr_in6()) and returns a list of two elements: | ||||
117 | the port number and the 16-octet IP address. | ||||
118 | This function will croak if it determines it has not been | ||||
119 | passed an IPv6 structure. | ||||
120 | |||||
121 | =item unpack_sockaddr_in6_all NAME | ||||
122 | |||||
123 | This function takes a sockaddr_in6 structure (as returned by | ||||
124 | pack_sockaddr_in6()) and returns a list of four elements: | ||||
125 | the port number, the flow information, the 16-octet IP address, | ||||
126 | and the scope information. | ||||
127 | This function will croak if it determines it has not been | ||||
128 | passed an IPv6 structure. | ||||
129 | |||||
130 | =item gethostbyname2 HOSTNAME, FAMILY | ||||
131 | |||||
132 | =item getaddrinfo NODENAME, SERVICENAME, [FAMILY, SOCKTYPE, PROTOCOL, FLAGS] | ||||
133 | |||||
134 | This function converts node names to addresses and service names | ||||
135 | to port numbers. | ||||
136 | If the NODENAME argument is not a false value, | ||||
137 | then a nodename to address lookup is performed; | ||||
138 | otherwise a service name to port number lookup is performed. | ||||
139 | At least one of NODENAME and SERVICENAME must have a true value. | ||||
140 | |||||
141 | If the lookup is successful, a list consisting of multiples of | ||||
142 | five elements is returned. | ||||
143 | Each group of five elements consists of the address family, | ||||
144 | socket type, protocol, 16-octet IP address, and the canonical | ||||
145 | name (undef if the node name passed is already the canonical name). | ||||
146 | |||||
147 | The arguments FAMILY, SOCKTYPE, PROTOCOL, and FLAGS are all optional. | ||||
148 | |||||
149 | This function will croak if it determines it has not been | ||||
150 | passed an IPv6 structure. | ||||
151 | |||||
152 | If the lookup is unsuccessful, the function returns a single scalar. | ||||
153 | This will contain the string version of that error in string context, | ||||
154 | and the numeric value in numeric context. | ||||
155 | |||||
156 | =item getnameinfo NAME, [FLAGS] | ||||
157 | |||||
158 | This function takes a socket address structure. If successful, it returns | ||||
159 | two strings containing the node name and service name. | ||||
160 | |||||
161 | The optional FLAGS argument controls what kind of lookup is performed. | ||||
162 | |||||
163 | If the lookup is unsuccessful, the function returns a single scalar. | ||||
164 | This will contain the string version of that error in string context, | ||||
165 | and the numeric value in numeric context. | ||||
166 | |||||
167 | =item getipnodebyname HOST, [FAMILY, FLAGS] | ||||
168 | |||||
169 | This function takes either a node name or an IP address string | ||||
170 | and performs a lookup on that name (or conversion of the string). | ||||
171 | It returns a list of five elements: the canonical host name, | ||||
172 | the address family, the length in octets of the IP addresses | ||||
173 | returned, a reference to a list of IP address structures, and | ||||
174 | a reference to a list of aliases for the host name. | ||||
175 | |||||
176 | The arguments FAMILY and FLAGS are optional. | ||||
177 | Note: This function does not handle IPv6 scope identifiers, | ||||
178 | and should be used with care. | ||||
179 | And, this function was deprecated in RFC3493. | ||||
180 | The getnameinfo function should be used instead. | ||||
181 | |||||
182 | =item getipnodebyaddr FAMILY, ADDRESS | ||||
183 | |||||
184 | This function takes an IP address family and an IP address structure | ||||
185 | and performs a reverse lookup on that address. | ||||
186 | It returns a list of five elements: the canonical host name, | ||||
187 | the address family, the length in octets of the IP addresses | ||||
188 | returned, a reference to a list of IP address structures, and | ||||
189 | a reference to a list of aliases for the host name. | ||||
190 | |||||
191 | Note: This function does not handle IPv6 scope identifiers, | ||||
192 | and should be used with care. | ||||
193 | And, this function was deprecated in RFC3493. | ||||
194 | The getaddrinfo function should be used instead. | ||||
195 | |||||
196 | =item gai_strerror ERROR_NUMBER | ||||
197 | |||||
198 | This function returns a string corresponding to the error number | ||||
199 | passed in as an argument. | ||||
200 | |||||
201 | =item in6addr_any | ||||
202 | |||||
203 | This function returns the 16-octet wildcard address. | ||||
204 | |||||
205 | =item in6addr_loopback | ||||
206 | |||||
207 | This function returns the 16-octet loopback address. | ||||
208 | |||||
209 | =back | ||||
210 | |||||
211 | =cut | ||||
212 | |||||
213 | 2 | 73µs | 2 | 402µs | # spent 214µs (27+187) within Socket6::BEGIN@213 which was called:
# once (27µs+187µs) by NetAddr::IP::Lite::BEGIN@9 at line 213 # spent 214µs making 1 call to Socket6::BEGIN@213
# spent 187µs making 1 call to Exporter::import |
214 | |||||
215 | 2 | 945µs | 2 | 4.34ms | # spent 3.83ms (3.07+759µs) within Socket6::BEGIN@215 which was called:
# once (3.07ms+759µs) by NetAddr::IP::Lite::BEGIN@9 at line 215 # spent 3.83ms making 1 call to Socket6::BEGIN@215
# spent 510µs making 1 call to base::import |
216 | |||||
217 | 1 | 12µs | @EXPORT = qw( | ||
218 | inet_pton inet_ntop pack_sockaddr_in6 pack_sockaddr_in6_all | ||||
219 | unpack_sockaddr_in6 unpack_sockaddr_in6_all sockaddr_in6 | ||||
220 | gethostbyname2 getaddrinfo getnameinfo | ||||
221 | in6addr_any in6addr_loopback | ||||
222 | gai_strerror getipnodebyname getipnodebyaddr | ||||
223 | AI_ADDRCONFIG | ||||
224 | AI_ALL | ||||
225 | AI_CANONNAME | ||||
226 | AI_NUMERICHOST | ||||
227 | AI_NUMERICSERV | ||||
228 | AI_DEFAULT | ||||
229 | AI_MASK | ||||
230 | AI_PASSIVE | ||||
231 | AI_V4MAPPED | ||||
232 | AI_V4MAPPED_CFG | ||||
233 | EAI_ADDRFAMILY | ||||
234 | EAI_AGAIN | ||||
235 | EAI_BADFLAGS | ||||
236 | EAI_FAIL | ||||
237 | EAI_FAMILY | ||||
238 | EAI_MEMORY | ||||
239 | EAI_NODATA | ||||
240 | EAI_NONAME | ||||
241 | EAI_SERVICE | ||||
242 | EAI_SOCKTYPE | ||||
243 | EAI_SYSTEM | ||||
244 | EAI_BADHINTS | ||||
245 | EAI_PROTOCOL | ||||
246 | IP_AUTH_TRANS_LEVEL | ||||
247 | IP_AUTH_NETWORK_LEVEL | ||||
248 | IP_ESP_TRANS_LEVEL | ||||
249 | IP_ESP_NETWORK_LEVEL | ||||
250 | IPPROTO_IP | ||||
251 | IPPROTO_IPV6 | ||||
252 | IPSEC_LEVEL_AVAIL | ||||
253 | IPSEC_LEVEL_BYPASS | ||||
254 | IPSEC_LEVEL_DEFAULT | ||||
255 | IPSEC_LEVEL_NONE | ||||
256 | IPSEC_LEVEL_REQUIRE | ||||
257 | IPSEC_LEVEL_UNIQUE | ||||
258 | IPSEC_LEVEL_USE | ||||
259 | IPV6_AUTH_TRANS_LEVEL | ||||
260 | IPV6_AUTH_NETWORK_LEVEL | ||||
261 | IPV6_ESP_NETWORK_LEVEL | ||||
262 | IPV6_ESP_TRANS_LEVEL | ||||
263 | NI_NOFQDN | ||||
264 | NI_NUMERICHOST | ||||
265 | NI_NAMEREQD | ||||
266 | NI_NUMERICSERV | ||||
267 | NI_DGRAM | ||||
268 | NI_WITHSCOPEID | ||||
269 | ); | ||||
270 | 2 | 5µs | push @EXPORT, qw(AF_INET6) unless defined eval {Socket::AF_INET6()}; | ||
271 | 2 | 13µs | push @EXPORT, qw(PF_INET6) unless defined eval {Socket::PF_INET6()}; | ||
272 | |||||
273 | 1 | 2µs | @EXPORT_OK = qw(AF_INET6 PF_INET6); | ||
274 | |||||
275 | 1 | 23µs | %EXPORT_TAGS = ( | ||
276 | all => [@EXPORT], | ||||
277 | ); | ||||
278 | |||||
279 | sub sockaddr_in6 { | ||||
280 | if (wantarray) { | ||||
281 | croak "usage: (port,iaddr) = sockaddr_in6(sin_sv)" unless @_ == 1; | ||||
282 | unpack_sockaddr_in6(@_); | ||||
283 | } else { | ||||
284 | croak "usage: sin_sv = sockaddr_in6(port,iaddr))" unless @_ == 2; | ||||
285 | pack_sockaddr_in6(@_); | ||||
286 | } | ||||
287 | } | ||||
288 | |||||
289 | # spent 179µs (138+41) within Socket6::AUTOLOAD which was called:
# once (138µs+41µs) by base::import at line 958 of Net/DNS/Resolver/Base.pm | ||||
290 | 1 | 2µs | my($constname); | ||
291 | 1 | 30µs | 1 | 16µs | ($constname = $AUTOLOAD) =~ s/.*:://o; # spent 16µs making 1 call to Socket6::CORE:subst |
292 | 1 | 3µs | $! = 0; | ||
293 | 1 | 39µs | 1 | 25µs | my $val = constant($constname, @_ ? $_[0] : 0); # spent 25µs making 1 call to Socket6::constant |
294 | 1 | 6µs | if ($! != 0) { | ||
295 | croak "Your vendor has not defined Socket macro $constname, used"; | ||||
296 | } | ||||
297 | 1 | 83µs | eval "sub $AUTOLOAD { $val }"; # spent 14µs executing statements in string eval # includes 4µs spent executing 1 call to 1 sub defined therein. | ||
298 | 1 | 17µs | 1 | 4µs | goto &$AUTOLOAD; # spent 4µs making 1 call to Socket6::AI_NUMERICHOST |
299 | } | ||||
300 | |||||
301 | 1 | 20µs | 1 | 578µs | bootstrap Socket6 $VERSION; # spent 578µs making 1 call to DynaLoader::bootstrap |
302 | |||||
303 | 1 | 34µs | 1; | ||
# spent 16µs within Socket6::CORE:subst which was called:
# once (16µs+0s) by Socket6::AUTOLOAD at line 291 | |||||
# spent 58µs within Socket6::bootstrap which was called:
# once (58µs+0s) by DynaLoader::bootstrap at line 210 of DynaLoader.pm | |||||
# spent 25µs within Socket6::constant which was called:
# once (25µs+0s) by Socket6::AUTOLOAD at line 293 | |||||
# spent 225µs within Socket6::gethostbyname2 which was called:
# once (225µs+0s) by NetAddr::IP::Lite::BEGIN@18 at line 240 of NetAddr/IP/Util.pm | |||||
# spent 30µs within Socket6::inet_pton which was called 4 times, avg 8µs/call:
# 4 times (30µs+0s) by Net::Patricia::AF_INET6::add at line 250 of Net/Patricia.pm, avg 8µs/call |