line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Filter::DNS::TCP; |
2
|
|
|
|
|
|
|
$POE::Filter::DNS::TCP::VERSION = '0.06'; |
3
|
|
|
|
|
|
|
#ABSTRACT: A POE Filter to handle DNS over TCP connections |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
22586
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
7
|
1
|
|
|
1
|
|
965
|
use Net::DNS; |
|
1
|
|
|
|
|
112585
|
|
|
1
|
|
|
|
|
133
|
|
8
|
1
|
|
|
1
|
|
10
|
use Net::DNS::Packet; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use base 'POE::Filter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1042
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
614
|
use bytes; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub FRAMING_BUFFER () { 0 } |
15
|
|
|
|
|
|
|
sub EXPECTED_SIZE () { 1 } |
16
|
|
|
|
|
|
|
sub INT16SZ () { 2 } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
1
|
16
|
my $class = shift; |
20
|
1
|
|
|
|
|
5
|
my $self = bless [ |
21
|
|
|
|
|
|
|
'', # FRAMING_BUFFER |
22
|
|
|
|
|
|
|
undef, # EXPECTED_SIZE |
23
|
|
|
|
|
|
|
], $class; |
24
|
1
|
|
|
|
|
3
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get_one_start { |
28
|
2
|
|
|
2
|
1
|
1123
|
my ($self, $stream) = @_; |
29
|
2
|
|
|
|
|
11
|
$self->[FRAMING_BUFFER] .= join '', @$stream; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_one { |
33
|
4
|
|
|
4
|
1
|
24
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
4
|
100
|
66
|
|
|
20
|
if ( |
36
|
|
|
|
|
|
|
defined($self->[EXPECTED_SIZE]) || |
37
|
|
|
|
|
|
|
defined( |
38
|
|
|
|
|
|
|
$self->[EXPECTED_SIZE] = _decoder(\$self->[FRAMING_BUFFER]) |
39
|
|
|
|
|
|
|
) |
40
|
|
|
|
|
|
|
) { |
41
|
2
|
50
|
|
|
|
8
|
return [ ] if length($self->[FRAMING_BUFFER]) < $self->[EXPECTED_SIZE]; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Four-arg substr() would be better here, but it's not compatible |
44
|
|
|
|
|
|
|
# with Perl as far back as we support. |
45
|
2
|
|
|
|
|
6
|
my $block = substr($self->[FRAMING_BUFFER], 0, $self->[EXPECTED_SIZE]); |
46
|
2
|
|
|
|
|
7
|
substr($self->[FRAMING_BUFFER], 0, $self->[EXPECTED_SIZE]) = ''; |
47
|
2
|
|
|
|
|
3
|
$self->[EXPECTED_SIZE] = undef; |
48
|
|
|
|
|
|
|
|
49
|
2
|
50
|
|
|
|
13
|
if ( my $packet = Net::DNS::Packet->new( \$block ) ) { |
50
|
2
|
|
|
|
|
219
|
return [ $packet ]; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
0
|
warn "Could not parse DNS packet\n"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
6
|
return []; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _decoder { |
59
|
4
|
|
|
4
|
|
6
|
my $data = shift; |
60
|
4
|
|
|
|
|
9
|
my $buf = substr $$data, 0, INT16SZ; |
61
|
4
|
100
|
|
|
|
19
|
return unless length $buf; |
62
|
2
|
|
|
|
|
11
|
my ($len) = unpack 'n', $buf; |
63
|
2
|
50
|
|
|
|
9
|
return unless $len; |
64
|
2
|
|
|
|
|
5
|
substr $$data, 0, INT16SZ, ''; |
65
|
2
|
|
|
|
|
13
|
return $len; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_pending { |
69
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
70
|
0
|
|
|
|
|
0
|
return $self->[FRAMING_BUFFER]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub put { |
74
|
2
|
|
|
2
|
1
|
6203
|
my $self = shift; |
75
|
2
|
|
|
|
|
5
|
my $packets = shift; |
76
|
2
|
|
|
|
|
4
|
my @blocks; |
77
|
2
|
|
|
|
|
7
|
foreach my $packet (@$packets) { |
78
|
2
|
50
|
|
|
|
5
|
next unless eval { $packet->isa('Net::DNS::Packet'); }; |
|
2
|
|
|
|
|
18
|
|
79
|
2
|
|
|
|
|
6
|
$packet->{buffer} = ''; |
80
|
2
|
|
|
|
|
10
|
my $packet_data = $packet->data; |
81
|
2
|
|
|
|
|
4162
|
my $lenmsg = pack( 'n', length $packet_data ); |
82
|
2
|
|
|
|
|
9
|
push @blocks, $lenmsg . $packet_data; |
83
|
|
|
|
|
|
|
} |
84
|
2
|
|
|
|
|
7
|
return \@blocks; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
q[You know like, in'it]; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |