line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Socket::MsgHdr; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
102657
|
use 5.006; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
117
|
|
4
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
505
|
|
5
|
|
|
|
|
|
|
#use bytes; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw( sendmsg recvmsg ); |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( pack_cmsghdr unpack_cmsghdr ); |
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Forcibly export our sendmsg, recvmsg methods |
12
|
|
|
|
|
|
|
INIT { |
13
|
3
|
|
|
3
|
|
19
|
*IO::Socket::sendmsg = \&sendmsg; |
14
|
3
|
|
|
|
|
19
|
*IO::Socket::recvmsg = \&recvmsg; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Define our simple accessor/mutator methods |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub flags { |
20
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
21
|
2
|
100
|
|
|
|
7
|
$self->{flags} = shift if @_; |
22
|
2
|
50
|
|
|
|
7
|
$self->{flags} = 0 unless defined $self->{flags}; |
23
|
2
|
|
|
|
|
8
|
$self->{flags}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
INIT { |
27
|
3
|
|
|
3
|
|
10
|
for my $attr (qw|name buf control|) { |
28
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
264
|
|
29
|
|
|
|
|
|
|
|
30
|
9
|
|
|
|
|
48
|
*{$attr} = sub { |
31
|
69
|
|
|
69
|
|
205
|
my $self = shift; |
32
|
69
|
100
|
|
|
|
229
|
$self->{$attr} = shift if @_; |
33
|
69
|
100
|
|
|
|
160
|
$self->{$attr} = '' unless defined $self->{$attr}; |
34
|
69
|
|
|
|
|
184
|
$self->{$attr}; |
35
|
9
|
|
|
|
|
49
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
10
|
foreach my $attr (qw|name buf control|) { |
39
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
983
|
|
40
|
9
|
|
|
|
|
68
|
*{$attr . "len"} = sub { |
41
|
26
|
|
|
26
|
|
46
|
my $self = shift; |
42
|
26
|
|
|
|
|
51
|
my $olen = length($self->$attr); |
43
|
26
|
100
|
|
|
|
86
|
return $olen unless @_; |
44
|
17
|
|
|
|
|
17
|
my $nlen = shift; |
45
|
|
|
|
|
|
|
|
46
|
17
|
50
|
|
|
|
47
|
if ($nlen != $olen) { |
47
|
17
|
50
|
|
|
|
93
|
$self->{$attr} = $olen > $nlen ? |
48
|
|
|
|
|
|
|
substr($self->{$attr}, 0, $nlen) : |
49
|
|
|
|
|
|
|
"\x00" x $nlen; |
50
|
|
|
|
|
|
|
} |
51
|
17
|
|
|
|
|
34
|
$nlen; |
52
|
9
|
|
|
|
|
32
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# XS functions |
58
|
|
|
|
|
|
|
# ============ |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
# -- sendmsg, recvmsg, pack_cmsghdr, unpack_cmsghdr |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
require XSLoader; |
63
|
|
|
|
|
|
|
XSLoader::load('Socket::MsgHdr', $VERSION); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Module import |
66
|
|
|
|
|
|
|
# ============= |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
sub import { |
69
|
3
|
|
|
3
|
|
29
|
require Exporter; |
70
|
3
|
|
|
|
|
3465
|
goto &Exporter::import; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Constructor |
74
|
|
|
|
|
|
|
# =========== |
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
sub new { |
77
|
25
|
|
|
25
|
1
|
19506
|
my $class = shift; |
78
|
25
|
|
|
|
|
103
|
my $self = { name => '', |
79
|
|
|
|
|
|
|
control => '', |
80
|
|
|
|
|
|
|
buf => '', |
81
|
|
|
|
|
|
|
flags => 0 }; |
82
|
|
|
|
|
|
|
|
83
|
25
|
|
|
|
|
54
|
bless $self, $class; |
84
|
|
|
|
|
|
|
|
85
|
25
|
|
|
|
|
66
|
my %args = @_; |
86
|
25
|
|
|
|
|
58
|
foreach my $m (keys %args) { |
87
|
35
|
|
|
|
|
97
|
$self->$m($args{$m}); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
25
|
|
|
|
|
93
|
return $self; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Methods |
94
|
|
|
|
|
|
|
# ======= |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# -- cmsghdr |
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
sub cmsghdr { |
99
|
5
|
|
|
5
|
1
|
48
|
my $self = shift; |
100
|
5
|
100
|
|
|
|
31
|
unless (@_) { return &unpack_cmsghdr($self->{control}); } |
|
2
|
|
|
|
|
22
|
|
101
|
3
|
|
|
|
|
26
|
$self->{control} = &pack_cmsghdr(@_); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# -- name, buf, control, flags |
105
|
|
|
|
|
|
|
# -- namelen, buflen, controllen |
106
|
|
|
|
|
|
|
# (loaded in INIT) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
__END__ |