File Coverage

blib/lib/Net/DNS/Multicast.pm
Criterion Covered Total %
statement 50 50 100.0
branch 4 4 100.0
condition n/a
subroutine 9 9 100.0
pod 3 5 100.0
total 66 68 100.0


line stmt bran cond sub pod time code
1             package Net::DNS::Multicast;
2              
3 3     3   139326 use strict;
  3         21  
  3         85  
4 3     3   15 use warnings;
  3         5  
  3         145  
5              
6             our $VERSION;
7             $VERSION = '0.02_01';
8              
9 3     3   1553 use Net::DNS qw(:DEFAULT);
  3         295298  
  3         1618  
10 3     3   93 use base qw(Exporter Net::DNS);
  3         28  
  3         3294  
11              
12             our @EXPORT = @Net::DNS::EXPORT;
13              
14             =head1 NAME
15              
16             Net::DNS::Multicast - Multicast extension to Net::DNS
17              
18             =head1 SYNOPSIS
19              
20             use Net::DNS::Multicast;
21             my $resolver = Net::DNS::Resolver->new();
22             my $response = $resolver( 'host.local.', 'AAAA' );
23              
24             =head1 DESCRIPTION
25              
26             Net::DNS::Multicast is installed as an extension to an existing Net::DNS
27             installation providing packages to support simple IP multicast queries
28             as described in RFC6762(5.1).
29              
30             The multicast feature is made available by replacing Net::DNS by
31             Net::DNS::Multicast in the use declaration.
32              
33             The use of IP Multicast is confined to the link-local domains listed in
34             RFC6762. Queries for other names in the global DNS are directed to the
35             configured nameservers.
36              
37             =cut
38              
39             {
40              
41             package Net::DNS::Resolver; ## Add methods to (otherwise empty) package
42              
43             my $defaults = __PACKAGE__->_defaults;
44             $defaults->{multicast_group} = [qw(FF02::FB 224.0.0.251)];
45             $defaults->{multicast_port} = 5353;
46              
47             my $NAME_REGEX = q/\.(local|254\.169\.in-addr\.arpa|[89AB]\.E\.F\.ip6\.arpa)$/;
48              
49             sub Net::DNS::Resolver::send {
50 2     2 1 1519 my ( $self, @argument ) = @_;
51 2         12 my $packet = $self->_make_query_packet(@argument);
52 2         14532 my ($q) = $packet->question;
53              
54 2 100       22 if ( $q->qname =~ /$NAME_REGEX/oi ) {
55 1         121 local $packet->{status} = 0;
56 1         4 local @{$self}{qw(nameservers nameserver4 nameserver6 port retrans)};
  1         5  
57 1         12 $self->_reset_errorstring;
58 1         8 $self->nameservers( @{$self->{multicast_group}} );
  1         8  
59 1         146 $self->port( $self->{multicast_port} );
60 1         43 $self->retrans(3);
61 1         16 return $self->_send_udp( $packet, $packet->data );
62             }
63              
64 1         51 return $self->SUPER::send($packet);
65             }
66              
67             sub Net::DNS::Resolver::bgsend {
68 2     2 1 1760 my ( $self, @argument ) = @_;
69 2         8 my $packet = $self->_make_query_packet(@argument);
70 2         398 my ($q) = $packet->question;
71              
72 2 100       31 if ( $q->qname =~ /$NAME_REGEX/oi ) {
73 1         57 local $packet->{status} = 0;
74 1         3 local @{$self}{qw(nameservers nameserver4 nameserver6 port)};
  1         4  
75 1         4 $self->_reset_errorstring;
76 1         4 $self->nameservers( @{$self->{multicast_group}} );
  1         5  
77 1         87 $self->port( $self->{multicast_port} );
78 1         10 return $self->_bgsend_udp( $packet, $packet->data );
79             }
80              
81 1         24 return $self->SUPER::bgsend($packet);
82             }
83              
84             sub Net::DNS::Resolver::string {
85 1     1 1 543 my $self = shift;
86 1         41 return join( '', $self->SUPER::string, <
87 1         91 ;; multicast_group @{$self->{multicast_group}}
88             ;; multicast_ port $self->{multicast_port}
89             END
90             }
91              
92              
93             package Net::DNS::Question;
94              
95             sub unicast_response {
96 3     3 0 2009 my ( $self, @value ) = @_; # uncoverable pod
97 3         9 for (@value) { $self->{qclass} |= ( $_ << 15 ) }
  1         5  
98 3         15 return $self->{qclass} >> 15;
99             }
100              
101              
102             package Net::DNS::RR;
103              
104             sub cache_flush {
105 3     3 0 2777 my ( $self, @value ) = @_; # uncoverable pod
106 3         8 for (@value) { $self->{class} |= ( $_ << 15 ) }
  1         3  
107 3         16 return $self->{class} >> 15;
108             }
109              
110             }
111              
112             1;
113             __END__