| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id: RR.pm 49 2009-05-31 13:15:34Z VinsWorldcom $ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package Net::Frame::Layer::DNS::RR; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Net::Frame::Layer qw(:consts :subs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Net::Frame::Layer::DNS::Constants qw(:consts); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | my @consts; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | for my $c (sort(keys(%constant::declared))) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1375 | ▶ | if ($c =~ /^Net::Frame::Layer::DNS::Constants::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 560 | $c =~ s/^Net::Frame::Layer::DNS::Constants:://; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 560 | push @consts, $c | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | consts => [@consts] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | our @EXPORT_OK = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | @{$EXPORT_TAGS{consts}}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | our @AS = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ttl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | rdlength | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | rdata | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | __PACKAGE__->cgBuildIndices; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | use Net::Frame::Layer::DNS qw(:subs); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::A; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::AAAA; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::CNAME; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::HINFO; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::MX; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::NS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::PTR; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::rdata; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::SOA; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::SRV; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | use Net::Frame::Layer::DNS::RR::TXT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | shift->SUPER::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | name => 'localhost', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | type => NF_DNS_TYPE_A, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | class => NF_DNS_CLASS_IN, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ttl => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | rdlength => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | rdata => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | @_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub getLength { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # 1 byte leading length, name, 1 byte trailing null, 2 bytes type, 2 bytes class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # 4 bytes ttl, 2 bytes rdlength, rdata | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if (length($self->name) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return length($self->name) + 11 + length($self->rdata) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return length($self->name) + 12 + length($self->rdata) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub pack { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack: called CC=4 SCAR=15.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my $name = dnsAton($self->name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if (($self->rdlength == 0) && (length($self->rdata) > 0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->rdlength == 0 and length $self->rdata > 0
MC/DC0%0/2
$self->rdlength == 0 and length $self->rdata > 0
$self->rdlength == 0
length $self->rdata > 0
Truth table33%1/3
A and B
A= $self->rdlength == 0B= length $self->rdata > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->rdlength(length($self->rdata)) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | $self->raw($self->SUPER::pack('H* nnNn a*', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $name, $self->type, $self->class, $self->ttl, $self->rdlength, $self->rdata | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | )) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | return $self->raw; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub unpack { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my ($name, $ptr1) = dnsNtoa($self->raw); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | my ($type, $class, $ttl, $rdlength, $payload) = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | $self->SUPER::unpack('nnNn a*', (substr $self->raw, $ptr1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | $self->name($name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | $self->type($type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $self->class($class); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $self->ttl($ttl); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | $self->rdlength($rdlength); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | $self->payload($payload); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | sub encapsulate { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encapsulate: called CC=15 SCAR=51.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | return $self->nextLayer if $self->nextLayer; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | if ($self->payload) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($self->rdlength == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return "DNS::RR" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } elsif ($self->type == NF_DNS_TYPE_A) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return "DNS::RR::A" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } elsif ($self->type == NF_DNS_TYPE_AAAA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return "DNS::RR::AAAA" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } elsif ($self->type == NF_DNS_TYPE_CNAME) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return "DNS::RR::CNAME" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } elsif ($self->type == NF_DNS_TYPE_HINFO) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return "DNS::RR::HINFO" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } elsif ($self->type == NF_DNS_TYPE_MX) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return "DNS::RR::MX" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } elsif ($self->type == NF_DNS_TYPE_NS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return "DNS::RR::NS" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } elsif ($self->type == NF_DNS_TYPE_PTR) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | return "DNS::RR::PTR" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } elsif ($self->type == NF_DNS_TYPE_SOA) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | return "DNS::RR::SOA" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } elsif ($self->type == NF_DNS_TYPE_SRV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return "DNS::RR::SRV" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } elsif ($self->type == NF_DNS_TYPE_TXT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return "DNS::RR::TXT" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # must include rdlength on calls to DNS::RR::rdata | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $temp = $self->SUPER::pack('n a*', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $self->rdlength, $self->payload | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->payload($temp); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return "DNS::RR::rdata" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | NF_LAYER_NONE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | my $l = $self->layer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | my $buf = sprintf | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | "$l: name:%s\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | "$l: type:%d class:%d ttl:%d rdlength:%d", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $self->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $self->type, $self->class, $self->ttl, $self->rdlength; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | return $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||