| 1 | # $Id: DNS.pm,v 1.3 2003/07/03 15:11:04 matt Exp $ | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package Net::SenderBase::Query::DNS; | ||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw($HOST); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | $HOST = 'test.senderbase.org'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Net::DNS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use IO::Select; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Net::SenderBase::Results; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 14 | 0 | my $class = shift; | |||||||||||||||||||
| 15 | 0 | my %attrs = @_; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | ▶ | $attrs{Address} || die "No address"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 0 | ▶ | $attrs{Host} ||= $HOST; | ||||||||||||||||||
|
Condition0%0/3
$attrs{"Host"} ||= $Net::SenderBase::Query::DNS::HOST
MC/DC0%0/2
$attrs{"Host"} ||= $Net::SenderBase::Query::DNS::HOST
$attrs{"Host"}
$Net::SenderBase::Query::DNS::HOST
Truth table0%0/3
A ||= B
A= $attrs{"Host"}B= $Net::SenderBase::Query::DNS::HOST
| |||||||||||||||||||||
| 19 | 0 | ▶ | $attrs{Timeout} || die "No timeout"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | my $self = bless { %attrs }, $class; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | my $res = Net::DNS::Resolver->new(); | |||||||||||||||||||
| 24 | 0 | my $sel = IO::Select->new(); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | my $reversed_ip = join('.', reverse(split(/\./,$attrs{Address}))); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | my $mask = $attrs{Mask} ? ".$attrs{Mask}" : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | $sel->add($res->bgsend("$reversed_ip$mask.$attrs{Host}", "TXT")); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | $self->{_sel} = $sel; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | return $self; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | sub results { | ||||||||||||||||||
|
Subroutine
results: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | my $res = Net::DNS::Resolver->new(); | |||||||||||||||||||
| 41 | 0 | my $sel = $self->{_sel}; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | my @ready = $sel->can_read($self->{Timeout}); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | ▶ | @ready || die "Timeout occurred getting results"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | my @lines; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | for my $socket (@ready) { | |||||||||||||||||||
| 50 | 0 | my $query = $res->bgread($socket); | |||||||||||||||||||
| 51 | 0 | $sel->remove($socket); | |||||||||||||||||||
| 52 | 0 | undef($socket); | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | if (!$query) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 0 | die $res->errorstring; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | foreach my $rr ($query->answer) { | |||||||||||||||||||
| 59 | 0 | ▶ | next unless $rr->type eq 'TXT'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | my $line = $rr->txtdata; | |||||||||||||||||||
| 61 | 0 | ▶ | if ($line =~ s/^(\d+)-//) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | my $id = $1; | |||||||||||||||||||
| 63 | 0 | $lines[$id] = $line; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||
| 66 | 0 | die "Unable to parse TXT record: $line"; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | @lines || die "No results came back for $self->{Address}"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | return Net::SenderBase::Results->cons($self->{Address}, join('', @lines)); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||