in reply to Re^2: Disassembling DNS Packet
in thread Disassembling DNS Packet
my $ip_obj = NetPacket::IP::strip($Raw_IP_Packet); my $udp_obj = NetPacket::UDP->decode($ip_obj); if ($udp_obj->{len}) { my $payload = $udp_obj->{data}; my $transid1 = unpack('n', substr($payload,0,2)); print "The transID is $transid1 \n"; }
My big mistake was the first line was wrong. " ...NetPacket::IP->decode($Raw_IP_packet);" This doesn't get the packet set up right. As the documentation for NetPacket::IP says, it happily parses garbage.
Net::DNS::Packet works, but I didn't see the errors of my ways until I got the ID working. the following code works in my situation.
use Net::DNS::Packet; use Data::Dumper; use NetPacket::UDP; use NetPacket::IP; my $ip_obj = NetPacket::IP::strip($Raw_IP_Packet); my $udp_obj = NetPacket::UDP->decode($ip_obj); if ($udp_obj->{len}) { my $payload2 = $udp_obj->{data}; my $test = Net::DNS::Packet->new(\$payload2); if ($test) { my @answer = $test->answer; print Dumper(@answer); } else { print "no Net::DNS::Packet \n";} } }
I get a complete @answer back when doing "dig slashdot.org" in another terminal.
A big thank you to everyone who gave me a push in the right direction despite my vague question.
|
---|