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   134771 use strict;
  3         22  
  3         87  
4 3     3   15 use warnings;
  3         6  
  3         133  
5              
6             our $VERSION;
7             $VERSION = '0.03';
8              
9 3     3   1433 use Net::DNS qw(:DEFAULT);
  3         296452  
  3         1352  
10 3     3   81 use base qw(Exporter Net::DNS);
  3         34  
  3         2911  
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              
42             package Net::DNS::Resolver; ## Add methods to (otherwise empty) package
43              
44             my $NAME_REGEX = q/\.(local|254\.169\.in-addr\.arpa|[89AB]\.E\.F\.ip6\.arpa)$/;
45              
46             sub send {
47 2     2 1 1440 my ( $self, @argument ) = @_;
48 2         10 my $packet = $self->_make_query_packet(@argument);
49 2         13436 my ($q) = $packet->question;
50              
51 2 100       22 if ( $q->qname =~ /$NAME_REGEX/oi ) {
52 1         113 local $packet->{status} = 0;
53 1         4 local @{$self}{qw(nameservers nameserver4 nameserver6 port retrans)};
  1         5  
54 1         11 $self->_reset_errorstring;
55 1         10 $self->nameservers( @{$self->{multicast_group}} );
  1         8  
56 1         96 $self->port( $self->{multicast_port} );
57 1         33 $self->retrans(3);
58 1         10 return $self->_send_udp( $packet, $packet->data );
59             }
60              
61 1         47 return $self->SUPER::send($packet);
62             }
63              
64             sub bgsend {
65 2     2 1 1574 my ( $self, @argument ) = @_;
66 2         7 my $packet = $self->_make_query_packet(@argument);
67 2         449 my ($q) = $packet->question;
68              
69 2 100       19 if ( $q->qname =~ /$NAME_REGEX/oi ) {
70 1         56 local $packet->{status} = 0;
71 1         3 local @{$self}{qw(nameservers nameserver4 nameserver6 port)};
  1         3  
72 1         4 $self->_reset_errorstring;
73 1         5 $self->nameservers( @{$self->{multicast_group}} );
  1         4  
74 1         88 $self->port( $self->{multicast_port} );
75 1         9 return $self->_bgsend_udp( $packet, $packet->data );
76             }
77              
78 1         20 return $self->SUPER::bgsend($packet);
79             }
80              
81             sub string {
82 1     1 1 517 my $self = shift;
83 1         8 return join( '', $self->SUPER::string, <
84 1         68 ;; multicast_group @{$self->{multicast_group}}
85             ;; multicast_ port $self->{multicast_port}
86             END
87             }
88              
89             my $defaults = __PACKAGE__->_defaults;
90             $defaults->{multicast_group} = [qw(FF02::FB 224.0.0.251)];
91             $defaults->{multicast_port} = 5353;
92             }
93              
94              
95             sub Net::DNS::Question::unicast_response {
96 3     3 0 2112 my ( $self, @value ) = @_; # uncoverable pod
97 3         8 for (@value) { $self->{qclass} |= ( $_ << 15 ) }
  1         5  
98 3         21 return $self->{qclass} >> 15;
99             }
100              
101             sub Net::DNS::RR::cache_flush {
102 3     3 0 2849 my ( $self, @value ) = @_; # uncoverable pod
103 3         10 for (@value) { $self->{class} |= ( $_ << 15 ) }
  1         7  
104 3         17 return $self->{class} >> 15;
105             }
106              
107              
108             1;
109             __END__