| 1 | # | ||||||||||
| 2 | # $Id: Question.pm 49 2009-05-31 13:15:34Z VinsWorldcom $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Net::Frame::Layer::DNS::Question; | ||||||||||
| 5 | 10 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 10 | ▶ | use Net::Frame::Layer qw(:consts :subs); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 10 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||
| 9 | |||||||||||
| 10 | 10 | ▶ | use Net::Frame::Layer::DNS::Constants qw(:consts); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 10 | my @consts; | |||||||||
| 12 | 10 | for my $c (sort(keys(%constant::declared))) { | |||||||||
| 13 | 2083 | ▶ | if ($c =~ /^Net::Frame::Layer::DNS::Constants::/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 800 | $c =~ s/^Net::Frame::Layer::DNS::Constants:://; | |||||||||
| 15 | 800 | push @consts, $c | |||||||||
| 16 | } | ||||||||||
| 17 | } | ||||||||||
| 18 | 10 | our %EXPORT_TAGS = ( | |||||||||
| 19 | consts => [@consts] | ||||||||||
| 20 | ); | ||||||||||
| 21 | our @EXPORT_OK = ( | ||||||||||
| 22 | 10 | @{$EXPORT_TAGS{consts}}, | |||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 10 | our @AS = qw( | |||||||||
| 26 | name | ||||||||||
| 27 | type | ||||||||||
| 28 | class | ||||||||||
| 29 | ); | ||||||||||
| 30 | 10 | __PACKAGE__->cgBuildIndices; | |||||||||
| 31 | 10 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||
| 32 | |||||||||||
| 33 | 10 | ▶ | use Net::Frame::Layer::DNS qw(:subs); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 4 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | shift->SUPER::new( | ||||||||||
| 37 | 4 | name => '', | |||||||||
| 38 | type => NF_DNS_TYPE_A, | ||||||||||
| 39 | class => NF_DNS_CLASS_IN, | ||||||||||
| 40 | @_, | ||||||||||
| 41 | ); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub getLength { | ||||||||
|
Subroutine
getLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | |||||||||||
| 47 | # 1 byte leading length, name, 1 byte trailing null, 2 bytes type, 2 bytes class | ||||||||||
| 48 | 0 | ▶ | if (length($self->name) == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | return length($self->name) + 5 | |||||||||
| 50 | } else { | ||||||||||
| 51 | 0 | return length($self->name) + 6 | |||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | sub pack { | ||||||||
|
Subroutine
pack: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 56 | 1 | my $self = shift; | |||||||||
| 57 | |||||||||||
| 58 | 1 | my $name = dnsAton($self->name); | |||||||||
| 59 | |||||||||||
| 60 | 1 | ▶ | $self->raw($self->SUPER::pack('H* nn', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | $name, $self->type, $self->class, | ||||||||||
| 62 | )) or return; | ||||||||||
| 63 | |||||||||||
| 64 | 1 | return $self->raw; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | sub unpack { | ||||||||
|
Subroutine
unpack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 68 | 1 | my $self = shift; | |||||||||
| 69 | |||||||||||
| 70 | 1 | my @parts = split /\0/, $self->raw, 2; | |||||||||
| 71 | 1 | my ($name) = dnsNtoa($parts[0]); | |||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | my ($type, $class, $payload) = | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | $self->SUPER::unpack('nn a*', $parts[1]) | ||||||||||
| 75 | or return; | ||||||||||
| 76 | |||||||||||
| 77 | 1 | $self->name($name); | |||||||||
| 78 | 1 | $self->type($type); | |||||||||
| 79 | 1 | $self->class($class); | |||||||||
| 80 | 1 | $self->payload($payload); | |||||||||
| 81 | |||||||||||
| 82 | 1 | return $self; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 1 | ▶ | sub encapsulate { | ||||||||
|
Subroutine
encapsulate: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||
| 86 | 1 | my $self = shift; | |||||||||
| 87 | |||||||||||
| 88 | 1 | ▶ | return $self->nextLayer if $self->nextLayer; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | |||||||||||
| 90 | 1 | ▶ | if ($self->payload) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | return 'DNS::RR'; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 1 | NF_LAYER_NONE; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 1 | ▶ | sub print { | ||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 98 | 1 | my $self = shift; | |||||||||
| 99 | |||||||||||
| 100 | 1 | my $l = $self->layer; | |||||||||
| 101 | 1 | my $buf = sprintf | |||||||||
| 102 | "$l: name:%s\n". | ||||||||||
| 103 | "$l: type:%d class:%d", | ||||||||||
| 104 | $self->name, | ||||||||||
| 105 | $self->type, $self->class; | ||||||||||
| 106 | |||||||||||
| 107 | 1 | return $buf; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 10 | 1; | |||||||||
| 111 | |||||||||||
| 112 | __END__ | ||||||||||