about Net::DNS 0.47

S

Sun Guonian

Base.pm_00 is original Base.pm file of Net-DNS-0.47,
Base.pm if my updated version.
# diff -c Base.pm_00 Base.pm
*** Base.pm_00 Sat Feb 21 20:45:27 2004
--- Base.pm Sun May 30 10:28:51 2004
***************
*** 430,436 ****

my $ans = $self->send($packet);

! return $ans && $ans->header->ancount ? $ans : undef;
}


--- 430,436 ----

my $ans = $self->send($packet);

! return $ans ? $ans : undef;
}


My question is why it check $ans->header->ancount,
for some authority-only server, its reply has no answer
record, and we think it is right answer. for example,
==== foo.pl ====
#!/usr/bin/perl

use Net::DNS;

my $res1 = Net::DNS::Resolver->new(
nameservers => [qw(81.91.161.5)],
recurse => 1,
debug => 1,
);
my $query1 = $res1->query("nokia.de", "NS");

if (defined($query1)) {
foreach $rr (grep { $_->type eq 'NS' } $query1->answer) {
print $rr->nsdname, "\n";
}
}
else {
warn "query1 failed: ", $res1->errorstring, "\n";
}
==== foo.pl ====

its output is the followed :

;; query(nokia.de, NS, IN)
;; send_udp(81.91.161.5:53)
;; answer from 81.91.161.5:53 : 101 bytes
;; HEADER SECTION
;; id = 39479
;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 0
;; ra = 0 ad = 0 cd = 0 rcode = NOERROR
;; qdcount = 1 ancount = 0 nscount = 2 arcount = 2

;; QUESTION SECTION (1 record)
;; nokia.de. IN NS

;; ANSWER SECTION (0 records)

;; AUTHORITY SECTION (2 records)
nokia.de. 86400 IN NS ns1.openit.de.
nokia.de. 86400 IN NS ns2.openit.de.

;; ADDITIONAL SECTION (2 records)
ns1.openit.de. 86400 IN A 217.69.65.1
ns2.openit.de. 86400 IN A 217.10.64.100
query1 failed: NOERROR

Any advice is appreciated !

Best Regard,
Sun Guonian
 
M

Michael Fuhr

Sun Guonian said:
Base.pm_00 is original Base.pm file of Net-DNS-0.47,
Base.pm if my updated version.
# diff -c Base.pm_00 Base.pm
*** Base.pm_00 Sat Feb 21 20:45:27 2004
--- Base.pm Sun May 30 10:28:51 2004
***************
*** 430,436 ****

my $ans = $self->send($packet);

! return $ans && $ans->header->ancount ? $ans : undef;
}


--- 430,436 ----

my $ans = $self->send($packet);

! return $ans ? $ans : undef;
}

My question is why it check $ans->header->ancount,
for some authority-only server, its reply has no answer
record, and we think it is right answer. for example,

The code you modified belongs to the resolver's "query" method.
That method is intended to mimic the C library's res_query()
function, which returns an error if the DNS response packet
contains no answers. This behavior is documented in the
Net::DNS::Resolver manual page.

If you need to examine the response packet regardless of
whether it contains any answers, then use the "send" method.
 
M

Michael Fuhr

The code you modified belongs to the resolver's "query" method.
That method is intended to mimic the C library's res_query()
function, which returns an error if the DNS response packet
contains no answers. This behavior is documented in the
Net::DNS::Resolver manual page.

If you need to examine the response packet regardless of
whether it contains any answers, then use the "send" method.

I forgot that this is also mentioned in Net::DNS::FAQ:

Why does Net::DNS::Resolver::query() return undef when the ANSWER
section is empty?

The short answer is, don't use query(). Net::DNS::Resolver::send()
will always return the answer packet, as long as an answer was
received.

The longer answer is that query() is modeled after the res_query()
function from the libresolv C library, which has similar behaviors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top