line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Gnutella::Packet::Reply;
|
2
|
1
|
|
|
1
|
|
4
|
use Socket qw(inet_ntoa inet_aton);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
3
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw/$VERSION $AUTOLOAD/;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
938
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = $VERSION = "0.1";
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Use AUTOHANDLER to supply generic attribute methods
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
sub AUTOLOAD {
|
12
|
0
|
|
|
0
|
|
|
my $self = shift;
|
13
|
0
|
|
|
|
|
|
my $attr = $AUTOLOAD;
|
14
|
0
|
|
|
|
|
|
$attr =~ s/.*:://;
|
15
|
0
|
0
|
|
|
|
|
return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods
|
16
|
0
|
0
|
|
|
|
|
croak sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr};
|
17
|
0
|
0
|
|
|
|
|
$self->{_attr}->{lc $attr} = shift if @_;
|
18
|
0
|
|
|
|
|
|
return $self->{_attr}->{lc $attr};
|
19
|
|
|
|
|
|
|
}
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new {
|
22
|
0
|
|
|
0
|
0
|
|
my $proto = shift;
|
23
|
0
|
|
|
|
|
|
my %args = @_;
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $self = {
|
26
|
|
|
|
|
|
|
_attr => {
|
27
|
|
|
|
|
|
|
msgid => [],
|
28
|
|
|
|
|
|
|
ttl => 7,
|
29
|
|
|
|
|
|
|
hops => 1,
|
30
|
|
|
|
|
|
|
function => 129,
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
ip => [],
|
33
|
|
|
|
|
|
|
port => 0,
|
34
|
|
|
|
|
|
|
speed => 0,
|
35
|
|
|
|
|
|
|
results => [],
|
36
|
|
|
|
|
|
|
guid => [],
|
37
|
|
|
|
|
|
|
},
|
38
|
|
|
|
|
|
|
};
|
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
bless $self, $proto;
|
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
foreach my $key (keys %args) {
|
43
|
0
|
|
|
|
|
|
my $lkey = lc $key;
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->$lkey($args{$key});
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $self;
|
49
|
|
|
|
|
|
|
}
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub ip {
|
52
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if (@_) {
|
55
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq 'ARRAY') {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{_attr}->{ip} = $_[0];
|
57
|
|
|
|
|
|
|
} elsif ($_[0] =~ /^[\d.]+$/) {
|
58
|
0
|
|
|
|
|
|
$self->{_attr}->{ip} = [ split(/\./, $_[0]) ];
|
59
|
|
|
|
|
|
|
} elsif ($_[0] =~ /\D/) {
|
60
|
0
|
|
|
|
|
|
$self->{_attr}->{ip} = [ split(/\./, inet_ntoa(inet_aton($_[0]))) ];
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return @{ $self->{_attr}->{ip} };
|
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub ip_as_string {
|
68
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return join(".", @{ $self->{_attr}->{ip} });
|
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub parse {
|
74
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
75
|
0
|
|
|
|
|
|
my $data = shift;
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $count = unpack("C", substr($data, 0, 1, ''));
|
78
|
0
|
|
|
|
|
|
my $port = unpack("S", substr($data, 0, 2, ''));
|
79
|
0
|
|
|
|
|
|
my @ip = unpack("C4", substr($data, 0, 4, ''));
|
80
|
0
|
|
|
|
|
|
my $speed = unpack("L", substr($data, 0, 4, ''));
|
81
|
0
|
|
|
|
|
|
my @set;
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $count; $i++) {
|
84
|
0
|
|
|
|
|
|
my $index = unpack("L", substr($data, 0, 4, ''));
|
85
|
0
|
|
|
|
|
|
my $size = unpack("L", substr($data, 0, 4, ''));
|
86
|
0
|
|
|
|
|
|
my $name = substr($data, 0, index($data, "\x00\x00"), '');
|
87
|
0
|
|
|
|
|
|
my $extra;
|
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if (index($name, "\x00") != -1) {
|
90
|
0
|
|
|
|
|
|
$extra = $name;
|
91
|
0
|
|
|
|
|
|
$name = substr($extra, 0, index($extra, "\x00"), '');
|
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
substr($extra, 0, 1, '');
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
substr($data, 0, 2, '');
|
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
push @set, [ $index, $size, $name, $extra ];
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my @guid = unpack("L4", substr($data, 0, 16, ''));
|
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->port($port);
|
104
|
0
|
|
|
|
|
|
$self->ip(\@ip);
|
105
|
0
|
|
|
|
|
|
$self->speed($speed);
|
106
|
0
|
|
|
|
|
|
$self->results(\@set);
|
107
|
0
|
|
|
|
|
|
$self->guid(\@guid);
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub format {
|
111
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
112
|
0
|
|
|
|
|
|
my $data;
|
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $results = $self->results;
|
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$data .= pack("C", scalar @$results);
|
117
|
0
|
|
|
|
|
|
$data .= pack("S", $self->port);
|
118
|
0
|
|
|
|
|
|
$data .= pack("C4", $self->ip);
|
119
|
0
|
|
|
|
|
|
$data .= pack("L", $self->speed);
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
foreach my $res (@$results) {
|
122
|
0
|
|
|
|
|
|
$data .= pack("L", $res->[0]);
|
123
|
0
|
|
|
|
|
|
$data .= pack("L", $res->[1]);
|
124
|
0
|
|
|
|
|
|
$data .= $res->[2];
|
125
|
0
|
0
|
|
|
|
|
$data .= $data =~ /\x00\x00$/ ? "" : "\x00\x00";
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$data .= pack("L4", @{ $self->guid });
|
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $data;
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1;
|