Filename | /usr/lib/perl5/Socket6.pm |
Statements | Executed 18 statements in 579µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 827µs | 975µs | BEGIN@215 | Socket6::
1 | 1 | 1 | 51µs | 51µs | gethostbyname2 (xsub) | Socket6::
1 | 1 | 1 | 42µs | 42µs | bootstrap (xsub) | Socket6::
1 | 1 | 1 | 13µs | 25µs | BEGIN@38 | Socket6::
1 | 1 | 1 | 7µs | 39µs | BEGIN@213 | Socket6::
1 | 1 | 1 | 7µs | 72µs | BEGIN@39 | Socket6::
0 | 0 | 0 | 0s | 0s | AUTOLOAD | Socket6::
0 | 0 | 0 | 0s | 0s | sockaddr_in6 | Socket6::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Copyright (C) 2000-2013 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,v 1.51 2013/12/08 17:23:56 ume Exp $ | ||||
35 | |||||
36 | package Socket6; | ||||
37 | |||||
38 | 2 | 31µs | 2 | 38µs | # spent 25µs (13+12) within Socket6::BEGIN@38 which was called:
# once (13µs+12µs) by NetAddr::IP::Lite::BEGIN@9 at line 38 # spent 25µs making 1 call to Socket6::BEGIN@38
# spent 12µs making 1 call to strict::import |
39 | 2 | 100µs | 2 | 136µs | # spent 72µs (7+65) within Socket6::BEGIN@39 which was called:
# once (7µs+65µs) by NetAddr::IP::Lite::BEGIN@9 at line 39 # spent 72µs making 1 call to Socket6::BEGIN@39
# spent 65µs making 1 call to vars::import |
40 | 1 | 600ns | $VERSION = "0.25"; | ||
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 | 28µs | 2 | 71µs | # spent 39µs (7+32) within Socket6::BEGIN@213 which was called:
# once (7µs+32µs) by NetAddr::IP::Lite::BEGIN@9 at line 213 # spent 39µs making 1 call to Socket6::BEGIN@213
# spent 32µs making 1 call to Exporter::import |
214 | |||||
215 | 2 | 382µs | 2 | 1.08ms | # spent 975µs (827+148) within Socket6::BEGIN@215 which was called:
# once (827µs+148µs) by NetAddr::IP::Lite::BEGIN@9 at line 215 # spent 975µs making 1 call to Socket6::BEGIN@215
# spent 101µs making 1 call to base::import |
216 | |||||
217 | 1 | 9µ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 | IPV6_ADDRFORM | ||||
264 | IPV6_ADD_MEMBERSHIP | ||||
265 | IPV6_DROP_MEMBERSHIP | ||||
266 | IPV6_MTU | ||||
267 | IPV6_MTU_DISCOVER | ||||
268 | IPV6_MULTICAST_HOPS | ||||
269 | IPV6_MULTICAST_IF | ||||
270 | IPV6_MULTICAST_LOOP | ||||
271 | IPV6_PKTINFO | ||||
272 | IPV6_RTHDR | ||||
273 | IPV6_AUTHHDR | ||||
274 | IPV6_DSTOPS | ||||
275 | IPV6_HOPOPTS | ||||
276 | IPV6_FLOWINFO | ||||
277 | IPV6_HOPLIMIT | ||||
278 | IPV6_RECVERR | ||||
279 | IPV6_ROUTER_ALERT | ||||
280 | IPV6_UNICAST_HOPS | ||||
281 | IPV6_V6ONLY | ||||
282 | NI_NOFQDN | ||||
283 | NI_NUMERICHOST | ||||
284 | NI_NAMEREQD | ||||
285 | NI_NUMERICSERV | ||||
286 | NI_DGRAM | ||||
287 | NI_WITHSCOPEID | ||||
288 | ); | ||||
289 | 2 | 1µs | push @EXPORT, qw(AF_INET6) unless defined eval {Socket::AF_INET6()}; | ||
290 | 2 | 300ns | push @EXPORT, qw(PF_INET6) unless defined eval {Socket::PF_INET6()}; | ||
291 | |||||
292 | 1 | 1µs | @EXPORT_OK = qw(AF_INET6 PF_INET6); | ||
293 | |||||
294 | 1 | 9µs | %EXPORT_TAGS = ( | ||
295 | all => [@EXPORT], | ||||
296 | ); | ||||
297 | |||||
298 | sub sockaddr_in6 { | ||||
299 | if (wantarray) { | ||||
300 | croak "usage: (port,iaddr) = sockaddr_in6(sin_sv)" unless @_ == 1; | ||||
301 | unpack_sockaddr_in6(@_); | ||||
302 | } else { | ||||
303 | croak "usage: sin_sv = sockaddr_in6(port,iaddr))" unless @_ == 2; | ||||
304 | pack_sockaddr_in6(@_); | ||||
305 | } | ||||
306 | } | ||||
307 | |||||
308 | sub AUTOLOAD { | ||||
309 | my($constname); | ||||
310 | ($constname = $AUTOLOAD) =~ s/.*:://o; | ||||
311 | $! = 0; | ||||
312 | my $val = constant($constname, @_ ? $_[0] : 0); | ||||
313 | if ($! != 0) { | ||||
314 | croak "Your vendor has not defined Socket macro $constname, used"; | ||||
315 | } | ||||
316 | eval "sub $AUTOLOAD { $val }"; | ||||
317 | goto &$AUTOLOAD; | ||||
318 | } | ||||
319 | |||||
320 | 1 | 6µs | 1 | 185µs | bootstrap Socket6 $VERSION; # spent 185µs making 1 call to DynaLoader::bootstrap |
321 | |||||
322 | 1 | 12µs | 1; | ||
# spent 42µs within Socket6::bootstrap which was called:
# once (42µs+0s) by DynaLoader::bootstrap at line 207 of DynaLoader.pm | |||||
# spent 51µs within Socket6::gethostbyname2 which was called:
# once (51µs+0s) by NetAddr::IP::Lite::BEGIN@18 at line 240 of NetAddr/IP/Util.pm |