Subject: | Net::DNS::Packet->data doesn't parse answer/additional/authority |
Directly printing a Packet works.
eval: Net::DNS::Resolver->new->query("www.cpan.org")->print;
...
;; ANSWER SECTION (3 records)
www.cpan.org. 86031 IN CNAME cpan-www.develooper.com.
cpan-www.develooper.com. 6831 IN CNAME
cpan-global.l.develooper.org.
cpan-global.l.develooper.org. 60 IN A 212.117.177.118
;; AUTHORITY SECTION (4 records)
...
However, I'm trying to serialise a response packet to send it over a
pipe between two processes. This doesn't:
eval: my $data = Net::DNS::Resolver->new->query("www.cpan.org")->data;
"\xf6\x97\x81\x80\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x04cpan\x03org\x00\x00\x01\x00\x01"
eval: Net::DNS::Packet->new(\$data)->print
...
;; ANSWER SECTION (0 records)
;; AUTHORITY SECTION (0 records)
Having read sub Net::DNS::Packet::data, I believe this is because it
doesn't correctly parse the other fields, before trying to pack the data
again. However, the following workaround seems to work OK:
eval: my $q = Net::DNS::Resolver->new->query("www.cpan.org");
eval: $q->answer
'3'
eval: $q->authority
'4'
eval: $q->additional
'0'
eval: my $data = $q->data;
"\xa1\x84\x81\x80\x00\x01\x00\x03\x00\x04\x00\x00\x03www\x04cpan\x03org\x00\x00\x01\x00\x01\xc0\x0c\x00\x05\x00\x01\x00\x01Q\x80\x00\x19\x08cpan-www\ndevelooper\x03com\x00\xc0*\x00\x05\x00\x01\x00\x00\x1c
\x00\e\x0bcpan-global\x01l\ndevelooper\xc0\x15\xc0O\x00\x01\x00\x01\x00\x00\x00<\x00\x04\xd4u\xb1v\xc0[\x00\x02\x00\x01\x00\x01Q\x80\x00\x14\x03ns2\x03p20\x06dynect\x03net\x00\xc0[\x00\x02\x00\x01\x00\x01Q\x80\x00\x06\x03ns1\xc0\x8a\xc0[\x00\x02\x00\x01\x00\x01Q\x80\x00\x06\x03ns4\xc0\x8a\xc0[\x00\x02\x00\x01\x00\x01Q\x80\x00\x06\x03ns3\xc0\x8a"
eval: Net::DNS::Packet->new(\$data)->print
;; HEADER SECTION
;; id = 41348
;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1
;; ra = 1 ad = 0 cd = 0 rcode = NOERROR
;; qdcount = 1 ancount = 3 nscount = 4 arcount = 0
;; QUESTION SECTION (1 record)
;; www.cpan.org. IN A
;; ANSWER SECTION (3 records)
www.cpan.org. 86400 IN CNAME cpan-www.develooper.com.
cpan-www.develooper.com. 7200 IN CNAME
cpan-global.l.develooper.org.
cpan-global.l.develooper.org. 60 IN A 212.117.177.118
;; AUTHORITY SECTION (4 records)
eval: Net::DNS::Packet->new( \$q->data )->print
;; HEADER SECTION
;; id = 13956
;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1
;; ra = 1 ad = 0 cd = 0 rcode = NOERROR
;; qdcount = 1 ancount = 3 nscount = 4 arcount = 0
;; QUESTION SECTION (1 record)
;; www.cpan.org. IN A
;; ANSWER SECTION (3 records)
www.cpan.org. 86283 IN CNAME cpan-www.develooper.com.
cpan-www.develooper.com. 7083 IN CNAME
cpan-global.l.develooper.org.
cpan-global.l.develooper.org. 60 IN A 212.117.177.118
;; AUTHORITY SECTION (4 records)
--
Paul Evans