1package Net::DNS::TestNS::Packet; 2use strict; 3use vars qw(@ISA $VERSION); 4 5use Net::DNS::Packet; 6use Net::DNS::Header; 7 8use Data::Dumper; 9 10@ISA = qw(Net::DNS::Packet); 11$VERSION=(qw$LastChangedRevision: 323 $)[1]; 12 13my $debug=0; 14 15# 16# We use the "headermask" to replace header information after the 17# regular Net::DNS::Packet->data() method has compiled the packet 18# 19 20sub data { 21 my $self=shift; 22 my $data; 23 if ($self->{"rawhack"}){ 24 $data=$self->{"data"} 25 }else{ 26 $data=Net::DNS::Packet::data($self); 27 } 28 if (defined $self->headermask()){ 29 print "Applying headermask\n" if $debug; 30 31 my $headermask=$self->headermask(); 32 foreach my $headerfield qw(aa ra ad cd qr rd tc 33 qdcount ancount nscount arcount){ 34 next unless defined $headermask->{$headerfield} ; 35 $self->header->$headerfield($headermask->{$headerfield}); 36 } 37 $self->header->id($headermask->{'id'}) if $headermask->{'id'}; 38 # Replace the original header. 39 my $headerlength=length $self->{"header"}->data; 40 return $self->header->data . substr ($data,$headerlength); 41 } 42 43 return $data; 44 45} 46 47 48# headermask accessor method. 49# header mask is used to store the potentially hacked header settings. 50# only after 51 52sub headermask { 53 54 my $self=shift; 55 my $new_val=shift; 56 57 if (defined $new_val) { 58 $self->{'headermask'} = $new_val; 59 } 60 61 return $self->{'headermask'}; 62}; 63 641; 65