| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id: DNS.pm 49 2013-03-04 13:15:34Z VinsWorldcom $ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | package Net::Frame::Layer::DNS; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | our $VERSION = '1.05'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Net::Frame::Layer qw(:consts :subs); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 14 | consts => [qw( | ||||||||||||||||||||||||||||||||||||||||||
| 15 | NF_DNS_QR_QUERY | ||||||||||||||||||||||||||||||||||||||||||
| 16 | NF_DNS_QR_RESPONSE | ||||||||||||||||||||||||||||||||||||||||||
| 17 | NF_DNS_OPCODE_QUERY | ||||||||||||||||||||||||||||||||||||||||||
| 18 | NF_DNS_OPCODE_IQUERY | ||||||||||||||||||||||||||||||||||||||||||
| 19 | NF_DNS_OPCODE_STATUS | ||||||||||||||||||||||||||||||||||||||||||
| 20 | NF_DNS_OPCODE_NOTIFY | ||||||||||||||||||||||||||||||||||||||||||
| 21 | NF_DNS_OPCODE_UPDATE | ||||||||||||||||||||||||||||||||||||||||||
| 22 | NF_DNS_FLAGS_AA | ||||||||||||||||||||||||||||||||||||||||||
| 23 | NF_DNS_FLAGS_TC | ||||||||||||||||||||||||||||||||||||||||||
| 24 | NF_DNS_FLAGS_RD | ||||||||||||||||||||||||||||||||||||||||||
| 25 | NF_DNS_FLAGS_RA | ||||||||||||||||||||||||||||||||||||||||||
| 26 | NF_DNS_FLAGS_Z | ||||||||||||||||||||||||||||||||||||||||||
| 27 | NF_DNS_FLAGS_AD | ||||||||||||||||||||||||||||||||||||||||||
| 28 | NF_DNS_FLAGS_CD | ||||||||||||||||||||||||||||||||||||||||||
| 29 | NF_DNS_RCODE_NOERROR | ||||||||||||||||||||||||||||||||||||||||||
| 30 | NF_DNS_RCODE_FORMATERROR | ||||||||||||||||||||||||||||||||||||||||||
| 31 | NF_DNS_RCODE_SERVERFAILURE | ||||||||||||||||||||||||||||||||||||||||||
| 32 | NF_DNS_RCODE_NAMEERROR | ||||||||||||||||||||||||||||||||||||||||||
| 33 | NF_DNS_RCODE_NOTIMPLEMENTED | ||||||||||||||||||||||||||||||||||||||||||
| 34 | NF_DNS_RCODE_REFUSED | ||||||||||||||||||||||||||||||||||||||||||
| 35 | NF_DNS_RCODE_YXDOMAIN | ||||||||||||||||||||||||||||||||||||||||||
| 36 | NF_DNS_RCODE_YXRRSET | ||||||||||||||||||||||||||||||||||||||||||
| 37 | NF_DNS_RCODE_NXRRSET | ||||||||||||||||||||||||||||||||||||||||||
| 38 | NF_DNS_RCODE_NOTAUTH | ||||||||||||||||||||||||||||||||||||||||||
| 39 | NF_DNS_RCODE_NOTZONE | ||||||||||||||||||||||||||||||||||||||||||
| 40 | )], | ||||||||||||||||||||||||||||||||||||||||||
| 41 | subs => [qw( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | dnsAton | ||||||||||||||||||||||||||||||||||||||||||
| 43 | dnsNtoa | ||||||||||||||||||||||||||||||||||||||||||
| 44 | )], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | our @EXPORT_OK = ( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | @{$EXPORT_TAGS{consts}}, | |||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | @{$EXPORT_TAGS{subs}}, | |||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 12 | ▶ | use constant NF_DNS_QR_QUERY => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | ▶ | use constant NF_DNS_QR_RESPONSE => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 12 | ▶ | use constant NF_DNS_OPCODE_QUERY => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 12 | ▶ | use constant NF_DNS_OPCODE_IQUERY => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | ▶ | use constant NF_DNS_OPCODE_STATUS => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | use constant NF_DNS_OPCODE_NOTIFY => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | use constant NF_DNS_OPCODE_UPDATE => 5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | ▶ | use constant NF_DNS_FLAGS_AA => 0x40; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | ▶ | use constant NF_DNS_FLAGS_TC => 0x20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | use constant NF_DNS_FLAGS_RD => 0x10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | ▶ | use constant NF_DNS_FLAGS_RA => 0x08; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | ▶ | use constant NF_DNS_FLAGS_Z => 0x04; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | ▶ | use constant NF_DNS_FLAGS_AD => 0x02; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | ▶ | use constant NF_DNS_FLAGS_CD => 0x01; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | use constant NF_DNS_RCODE_NOERROR => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 12 | ▶ | use constant NF_DNS_RCODE_FORMATERROR => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 12 | ▶ | use constant NF_DNS_RCODE_SERVERFAILURE => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 12 | ▶ | use constant NF_DNS_RCODE_NAMEERROR => 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 12 | ▶ | use constant NF_DNS_RCODE_NOTIMPLEMENTED => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 12 | ▶ | use constant NF_DNS_RCODE_REFUSED => 5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | ▶ | use constant NF_DNS_RCODE_YXDOMAIN => 6; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | ▶ | use constant NF_DNS_RCODE_YXRRSET => 7; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 12 | ▶ | use constant NF_DNS_RCODE_NXRRSET => 8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | ▶ | use constant NF_DNS_RCODE_NOTAUTH => 9; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 12 | ▶ | use constant NF_DNS_RCODE_NOTZONE => 10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | our @AS = qw( | |||||||||||||||||||||||||||||||||||||||||
| 78 | id | ||||||||||||||||||||||||||||||||||||||||||
| 79 | qr | ||||||||||||||||||||||||||||||||||||||||||
| 80 | opcode | ||||||||||||||||||||||||||||||||||||||||||
| 81 | flags | ||||||||||||||||||||||||||||||||||||||||||
| 82 | rcode | ||||||||||||||||||||||||||||||||||||||||||
| 83 | qdCount | ||||||||||||||||||||||||||||||||||||||||||
| 84 | anCount | ||||||||||||||||||||||||||||||||||||||||||
| 85 | nsCount | ||||||||||||||||||||||||||||||||||||||||||
| 86 | arCount | ||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | __PACKAGE__->cgBuildIndices; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | #no strict 'vars'; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 12 | ▶ | use Bit::Vector; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 12 | ▶ | use Net::Frame::Layer::DNS::Constants qw(:consts); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | my $dns_payload; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | $Net::Frame::Layer::UDP::Next->{53} = "DNS"; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | shift->SUPER::new( | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | id => getRandom16bitsInt(), | |||||||||||||||||||||||||||||||||||||||||
| 103 | qr => NF_DNS_QR_QUERY, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | opcode => NF_DNS_OPCODE_QUERY, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | flags => NF_DNS_FLAGS_RD, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | rcode => NF_DNS_RCODE_NOERROR, | ||||||||||||||||||||||||||||||||||||||||||
| 107 | qdCount => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | anCount => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | nsCount => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | arCount => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 111 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($with) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $sQr = $self->qr; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $sId = $self->id; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $wQr = $with->qr; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $wId = $with->id; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (($sQr == NF_DNS_QR_QUERY) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$sQr == 0 and $wQr == 1 and $sId == $wId
$sQr == 0 and $wQr == 1
MC/DC0%0/3
$sQr == 0 and $wQr == 1 and $sId == $wId
$sQr == 0
$wQr == 1
$sId == $wId
Truth table0%0/4
A and B and C
A= $sQr == 0B= $wQr == 1C= $sId == $wId
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | && ($wQr == NF_DNS_QR_RESPONSE) | ||||||||||||||||||||||||||||||||||||||||||
| 124 | && ($sId == $wId)) { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # XXX: may be better, by keying on type also | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub getKey { shift->layer } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getKey: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub getKeyReverse { shift->layer } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getKeyReverse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub getLength { 12 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | sub pack { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my $qr = Bit::Vector->new_Dec(1, $self->qr); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my $opcode = Bit::Vector->new_Dec(4, $self->opcode); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | my $flags = Bit::Vector->new_Dec(7, $self->flags); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | my $rcode = Bit::Vector->new_Dec(4, $self->rcode); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | my $bvlist = $qr->Concat_List($opcode, $flags, $rcode); | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | my $raw = $self->SUPER::pack('nnnnnn', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | $self->id, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | $bvlist->to_Dec, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | $self->qdCount, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | $self->anCount, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | $self->nsCount, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | $self->arCount | ||||||||||||||||||||||||||||||||||||||||||
| 152 | ) or return; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | return $self->raw($raw); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | sub unpack { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | $dns_payload = $self->raw; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | ▶ | my ($id, $bv, $qdCount, $anCount, $nsCount, $arCount, $payload) = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | $self->SUPER::unpack('nnnnnn a*', $self->raw) | ||||||||||||||||||||||||||||||||||||||||||
| 164 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $self->id($id); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | my $bvlist = Bit::Vector->new_Dec(16, $bv); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $self->qr ($bvlist->Chunk_Read(1,15)); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $self->opcode($bvlist->Chunk_Read(4,11)); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | $self->flags ($bvlist->Chunk_Read(7, 4)); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | $self->rcode ($bvlist->Chunk_Read(4, 0)); | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | $self->qdCount($qdCount); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $self->anCount($anCount); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $self->nsCount($nsCount); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | $self->arCount($arCount); | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | $self->payload($payload); | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | sub encapsulate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encapsulate: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return $self->nextLayer if $self->nextLayer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | ▶ | if ($self->payload) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return 'DNS::Question'; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | NF_LAYER_NONE; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my $l = $self->layer; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my $buf = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 201 | "$l: id:%d qr:%d opcode:%d flags:0x%02x rcode:%d\n". | ||||||||||||||||||||||||||||||||||||||||||
| 202 | "$l: qdCount:%d anCount:%d\n". | ||||||||||||||||||||||||||||||||||||||||||
| 203 | "$l: nsCount:%d arCount:%d", | ||||||||||||||||||||||||||||||||||||||||||
| 204 | $self->id, $self->qr, $self->opcode, $self->flags, $self->rcode, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | $self->qdCount, $self->anCount, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | $self->nsCount, $self->arCount; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | return $buf; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 16 | ▶ | sub dnsAton { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dnsAton: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # Weird pack routine. Queries are encoded by: | ||||||||||||||||||||||||||||||||||||||||||
| 217 | # <length of characters in bytes to first "."><chars> ... | ||||||||||||||||||||||||||||||||||||||||||
| 218 | # For example: | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # 3www6google3com\0 | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # 0377777706676f6f676c6503636f6d00 | ||||||||||||||||||||||||||||||||||||||||||
| 221 | # 3 w w w 6 g o o g l e 3 c o m\0 | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 16 | my $name = ''; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 16 | my @parts = split /\./, $self; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 16 | for my $part (@parts) { | |||||||||||||||||||||||||||||||||||||||||
| 225 | 17 | $name .= sprintf "%.2x%s", length($part), CORE::unpack "H*", $part | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 16 | $name .= CORE::unpack "H*", "\0"; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 16 | return $name | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | sub dnsNtoa { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dnsNtoa: called CC=12 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | my $name = ''; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | my $i; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | for ($i = 0; $i < length($self); $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | # start counts down the letters in section (originally separate by '.') | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | ▶ | if ($start == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | $start = hex (CORE::unpack "H*", (substr $self, $i, 1)); | |||||||||||||||||||||||||||||||||||||||||
| 241 | # If null, done name | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | ▶ | if ($start == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | $i+=1; | |||||||||||||||||||||||||||||||||||||||||
| 244 | last | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 246 | # if pointer, done name ... | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | ▶ | if (($start & 0xc0) == 0xc0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | # get pointer position | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $ptr = hex (CORE::unpack "H*", (substr $self, $i+1, 1)); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ($name ne '') { $name .= "." } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $name .= "[@" . $ptr . "("; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $i+=2; | |||||||||||||||||||||||||||||||||||||||||
| 253 | # resolve pointer if possible | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if (defined($ptr = _getptr($ptr))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $name .= $ptr | |||||||||||||||||||||||||||||||||||||||||
| 256 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $name .= "!ERROR!" | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $name .= ")]"; | |||||||||||||||||||||||||||||||||||||||||
| 260 | # done | ||||||||||||||||||||||||||||||||||||||||||
| 261 | last | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 263 | # add . to name to separate | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | if ($name ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $name .= '.' | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | next | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 269 | 9 | my $t = hex (CORE::unpack "H*", (substr $self, $i, 1)); | |||||||||||||||||||||||||||||||||||||||||
| 270 | # If null, done name | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 9 | ▶ | if ($t == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $i+=1; | |||||||||||||||||||||||||||||||||||||||||
| 273 | last | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 275 | # If pointer, done name ... | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 9 | ▶ | if (($t & 0xc0) == 0xc0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | # get pointer position | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $ptr = hex (CORE::unpack "H*", (substr $self, $i+1, 1)); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($name ne '') { $name .= "." } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $name .= "[@" . $ptr . "("; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $i+=2; | |||||||||||||||||||||||||||||||||||||||||
| 282 | # resolve pointer if possible | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (defined($ptr = _getptr($ptr))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $name .= $ptr | |||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $name .= "!ERROR!" | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $name .= ")]"; | |||||||||||||||||||||||||||||||||||||||||
| 289 | # done | ||||||||||||||||||||||||||||||||||||||||||
| 290 | last | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 292 | # add next letter to name | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 9 | $name .= substr $self, $i, 1; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | $start-- | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | return ($name, $i) | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub _getptr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getptr: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $ptr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if (defined($dns_payload)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ($name) = dnsNtoa(substr $dns_payload, $ptr); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | return $name | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | __END__ | ||||||||||||||||||||||||||||||||||||||||||