line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNS::Resolver::Mock; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
175719
|
use strict; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
72
|
|
4
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
93
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.20220817'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
21
|
use base 'Net::DNS::Resolver'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1463
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
242151
|
use Net::DNS::Packet; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
131
|
|
11
|
3
|
|
|
3
|
|
26
|
use Net::DNS::Question; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
189
|
|
12
|
3
|
|
|
3
|
|
1903
|
use Net::DNS::ZoneFile; |
|
3
|
|
|
|
|
18449
|
|
|
3
|
|
|
|
|
1955
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $die_on = {}; |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
my @_debug_output; |
17
|
|
|
|
|
|
|
sub enable_debug { |
18
|
1
|
|
|
1
|
1
|
465
|
my ( $self ) = @_; |
19
|
1
|
|
|
|
|
2
|
$self->{_mock_debug} = 1; |
20
|
1
|
|
|
|
|
5
|
$self->_add_debug( "Net::DNS::Resolver::Mock Debugging enabled" ); |
21
|
1
|
|
|
|
|
2
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
sub disable_debug { |
24
|
1
|
|
|
1
|
0
|
430
|
my ( $self ) = @_; |
25
|
1
|
|
|
|
|
3
|
$self->clear_debug(); |
26
|
1
|
|
|
|
|
2
|
delete $self->{_mock_debug}; |
27
|
1
|
|
|
|
|
1
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
sub _add_debug { |
30
|
4
|
|
|
4
|
|
6
|
my ( $self, $debug ) = @_; |
31
|
4
|
|
|
|
|
7
|
push @_debug_output, $debug; |
32
|
4
|
|
|
|
|
51
|
warn $debug; |
33
|
4
|
|
|
|
|
17
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
sub clear_debug { |
36
|
1
|
|
|
1
|
1
|
2
|
my ( $self ) = @_; |
37
|
1
|
|
|
|
|
2
|
@_debug_output = (); |
38
|
1
|
|
|
|
|
2
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
sub get_debug { |
41
|
5
|
|
|
5
|
1
|
2434
|
my ( $self ) = @_; |
42
|
5
|
|
|
|
|
15
|
return @_debug_output; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub die_on { |
47
|
1
|
|
|
1
|
1
|
949
|
my ( $self, $name, $type, $error ) = @_; |
48
|
1
|
|
|
|
|
5
|
$die_on->{ "$name $type" } = $error; |
49
|
1
|
|
|
|
|
2
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub zonefile_read { |
53
|
1
|
|
|
1
|
1
|
1792
|
my ( $self, $zonefile ) = @_; |
54
|
1
|
|
|
|
|
6
|
$self->{ 'zonefile' } = Net::DNS::ZoneFile->read( $zonefile ); |
55
|
1
|
|
|
|
|
5835
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub zonefile_parse { |
59
|
3
|
|
|
3
|
1
|
2467
|
my ( $self, $zonefile ) = @_; |
60
|
3
|
|
|
|
|
22
|
$self->{ 'zonefile' } = Net::DNS::ZoneFile->parse( $zonefile ); |
61
|
3
|
|
|
|
|
3281
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub send { |
65
|
16
|
|
|
16
|
1
|
8729
|
my ( $self, $name, $type ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
16
|
100
|
|
|
|
56
|
$self->_add_debug( "DNS Lookup '$name' '$type'" ) if $self->{_mock_debug}; |
68
|
|
|
|
|
|
|
|
69
|
16
|
100
|
|
|
|
51
|
if ( exists ( $die_on->{ "$name $type" } ) ) { |
70
|
1
|
|
|
|
|
14
|
die $die_on->{ "$name $type" }; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
15
|
100
|
|
|
|
46
|
$name =~ s/\.$// unless $name eq '.'; |
74
|
|
|
|
|
|
|
|
75
|
15
|
|
|
|
|
27
|
my $FakeZone = $self->{ 'zonefile' }; |
76
|
|
|
|
|
|
|
|
77
|
15
|
|
|
|
|
20
|
my $origname = $name; |
78
|
15
|
100
|
|
|
|
40
|
if ( lc $type eq 'ptr' ) { |
79
|
4
|
100
|
|
|
|
13
|
if ( index( lc $name, '.in-addr.arpa' ) == -1 ) { |
80
|
3
|
100
|
|
|
|
12
|
if ( $name =~ /^\d+\.\d+\.\d+\.\d+$/ ) { |
81
|
2
|
|
|
|
|
8
|
$name = join( '.', reverse( split( /\./, $name ) ) ); |
82
|
2
|
|
|
|
|
6
|
$name .= '.in-addr.arpa'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
15
|
|
|
|
|
78
|
my $Packet = Net::DNS::Packet->new(); |
87
|
15
|
|
|
|
|
211
|
$Packet->push( 'question' => Net::DNS::Question->new( $origname, $type, 'IN' ) ); |
88
|
15
|
|
|
|
|
995
|
foreach my $Item ( @$FakeZone ) { |
89
|
32
|
|
|
|
|
133
|
my $itemname = $Item->name(); |
90
|
32
|
|
|
|
|
500
|
my $itemtype = $Item->type(); |
91
|
32
|
100
|
100
|
|
|
328
|
if ( ( lc $itemname eq lc $name ) && ( lc $itemtype eq lc $type ) ) { |
|
|
100
|
66
|
|
|
|
|
92
|
6
|
|
|
|
|
13
|
$Packet->push( 'answer' => $Item ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( ( lc $itemname eq lc $name ) && ( lc $itemtype eq lc 'cname' ) ) { |
95
|
1
|
|
|
|
|
3
|
$Packet->push( 'answer' => $Item ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
15
|
|
|
|
|
60
|
$Packet->{ 'answerfrom' } = '127.0.0.1'; |
99
|
15
|
|
|
|
|
24
|
$Packet->{ 'status' } = 33152; |
100
|
15
|
|
|
|
|
31
|
return $Packet; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |