1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
# $Id: 10-recurse.t 566 2006-02-20 12:00:50Z olaf $ -*-perl-*-
use Test::More;
use strict;
BEGIN {
if (-e 't/online.enabled') {
#
# Some people try to run these on private address space."
use IO::Socket::INET;
my $sock = IO::Socket::INET->new(PeerAddr => '193.0.14.129', # k.root-servers.net.
PeerPort => '25',
Proto => 'udp');
unless($sock){
plan skip_all => "Cannot bind to socket:\n\t".$!."\n";
diag "This is an indication you do not have network problems";
exit;
}else{
use Net::IP;
my $ip=Net::IP->new(inet_ntoa($sock->sockaddr));
if ($ip->iptype() ne "PUBLIC"){
plan skip_all => 'Cannot run these tests from this IP:' .$ip->ip() ;
}else{
plan tests => 12;
}
}
} else {
plan skip_all => 'Online tests disabled.';
}
}
BEGIN { use_ok('Net::DNS::Resolver::Recurse'); }
{
my $res = Net::DNS::Resolver::Recurse->new;
isa_ok($res, 'Net::DNS::Resolver::Recurse');
$res->debug(0);
$res->udp_timeout(20);
# Hard code A and K.ROOT-SERVERS.NET hint
ok($res->hints("193.0.14.129", "198.41.0.4" ), "hints() set");
ok(%{ $res->{'hints'} }, 'sanity check worked');
my $packet;
# Try a domain that is a CNAME
$packet = $res->query_dorecursion("www.netscape.com.","A");
ok($packet, 'got a packet');
ok(scalar $packet->answer, 'answer has RRs');
# Try a big hairy one
undef $packet;
$packet = $res->query_dorecursion("www.rob.com.au.","A");
ok($packet, 'got a packet');
ok(scalar $packet->answer, 'anwer section had RRs');
}
# test the callback
{
my $res = Net::DNS::Resolver::Recurse->new ;
my $count;
$res->recursion_callback(sub {
my $packet = shift;
isa_ok($packet, 'Net::DNS::Packet');
$count++;
});
$res->query_dorecursion('a.t.net-dns.org', 'A');
is($count, 3);
}
|