line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Paranoid::Network::Socket -- Socket wrapper for seemless IPv6 support |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: lib/Paranoid/Network/Socket.pm, 2.10 2022/03/08 00:01:04 acorliss Exp $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This software is free software. Similar to Perl, you can redistribute it |
6
|
|
|
|
|
|
|
# and/or modify it under the terms of either: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# a) the GNU General Public License |
9
|
|
|
|
|
|
|
# as published by the |
10
|
|
|
|
|
|
|
# Free Software Foundation ; either version 1 |
11
|
|
|
|
|
|
|
# , or any later version |
12
|
|
|
|
|
|
|
# , or |
13
|
|
|
|
|
|
|
# b) the Artistic License 2.0 |
14
|
|
|
|
|
|
|
# , |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# subject to the following additional term: No trademark rights to |
17
|
|
|
|
|
|
|
# "Paranoid" have been or are conveyed under any of the above licenses. |
18
|
|
|
|
|
|
|
# However, "Paranoid" may be used fairly to describe this unmodified |
19
|
|
|
|
|
|
|
# software, in good faith, but not as a trademark. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# (c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) |
22
|
|
|
|
|
|
|
# (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com) |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
##################################################################### |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
##################################################################### |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# Environment definitions |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
##################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package Paranoid::Network::Socket; |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
5
|
|
427
|
use 5.008; |
|
5
|
|
|
|
|
16
|
|
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
5
|
|
21
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
75
|
|
37
|
5
|
|
|
5
|
|
19
|
use warnings; |
|
5
|
|
|
|
|
69
|
|
|
5
|
|
|
|
|
135
|
|
38
|
5
|
|
|
5
|
|
23
|
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
276
|
|
39
|
5
|
|
|
5
|
|
25
|
use base qw(Exporter); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
358
|
|
40
|
5
|
|
|
5
|
|
2498
|
use Socket qw(:all); |
|
5
|
|
|
|
|
15952
|
|
|
5
|
|
|
|
|
6013
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 2.10 $ =~ /(\d+(?:\.\d+)+)/sm ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
##################################################################### |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# Module code follows |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
##################################################################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our $ipv6_enabled; |
51
|
|
|
|
|
|
|
our $socket6; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub has_ipv6 { |
54
|
72
|
|
|
72
|
1
|
631
|
return $ipv6_enabled; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
BEGIN { |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
5
|
|
100
|
@EXPORT = ( 'has_ipv6', @Socket::EXPORT ); |
60
|
5
|
|
|
|
|
45
|
@EXPORT_OK = ( 'has_ipv6', @Socket::EXPORT_OK ); |
61
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
62
|
|
|
|
|
|
|
%Socket::EXPORT_TAGS, |
63
|
5
|
|
|
|
|
18
|
all => [ 'has_ipv6', @{ $Socket::EXPORT_TAGS{all} } ], |
|
5
|
|
|
|
|
138
|
|
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Check to see if we've got any IPv6 functions available |
67
|
5
|
|
|
|
|
133
|
$socket6 = 0; |
68
|
5
|
50
|
|
|
|
36
|
$ipv6_enabled = ( defined *sockaddr_in6{CODE} ) ? 1 : 0; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Set inet_pton/inet_ntop to import by default -- don't know why |
71
|
|
|
|
|
|
|
# this isn't done in Socket at all... |
72
|
5
|
50
|
|
|
|
12
|
if ( grep { $_ eq 'inet_pton' } @EXPORT_OK ) { |
|
545
|
|
|
|
|
681
|
|
73
|
5
|
|
|
|
|
22
|
push @EXPORT, qw(inet_pton inet_ntop); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
5
|
50
|
|
|
|
180
|
unless ($ipv6_enabled) { |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Socket didn't provide it, let's see if Socket6 is available |
79
|
0
|
0
|
|
|
|
0
|
if ( eval 'require Socket6; 1;' ) { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Conditionally import Socket6 routines. This is important |
82
|
|
|
|
|
|
|
# because perl 5.12 has partial IPv6 support, and 5.14 full. I |
83
|
|
|
|
|
|
|
# want to avoid redefined and prototype mismatch warnings. |
84
|
0
|
|
|
|
|
0
|
for my $symbol (@Socket6::EXPORT) { |
85
|
0
|
0
|
|
|
|
0
|
unless ( grep /^$symbol$/s, @EXPORT, @EXPORT_OK ) { |
86
|
0
|
|
|
|
|
0
|
import Socket6 $symbol; |
87
|
0
|
|
|
|
|
0
|
push @EXPORT, $symbol; |
88
|
0
|
|
|
|
|
0
|
push @{ $EXPORT_TAGS{all} }, $symbol; |
|
0
|
|
|
|
|
0
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
0
|
for my $symbol (@Socket6::EXPORT_OK) { |
92
|
0
|
0
|
|
|
|
0
|
unless ( grep /^$symbol$/s, @EXPORT, @EXPORT_OK ) { |
93
|
0
|
|
|
|
|
0
|
import Socket6 $symbol; |
94
|
0
|
|
|
|
|
0
|
push @EXPORT_OK, $symbol; |
95
|
0
|
|
|
|
|
0
|
push @{ $EXPORT_TAGS{all} }, $symbol; |
|
0
|
|
|
|
|
0
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Check one more time... |
101
|
0
|
0
|
|
|
|
0
|
$ipv6_enabled = ( defined *sockaddr_in6{CODE} ) ? 1 : 0; |
102
|
0
|
0
|
|
|
|
0
|
if ($ipv6_enabled) { |
103
|
0
|
0
|
|
|
|
0
|
$socket6 = *sockaddr_in{PACKAGE} eq 'Socket6' ? 1 : 0; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |