DNS-Unbound
view release on metacpan or search on metacpan
lib/DNS/Unbound.pm view on Meta::CPAN
Z<>
=cut
sub add_ta_file {
my ($self, $path) = @_;
my $err = $self->{'_ub'}->_ub_ctx_add_ta_file( $path );
if ($err) {
die _create_unbound_error("Failed to add zone-style trust anchor file", $err);
}
return $self;
}
=head2 I<OBJ>->trustedkeys( $PATH )
Z<>
=cut
sub trustedkeys {
my ($self, $path) = @_;
my $err = $self->{'_ub'}->_ub_ctx_trustedkeys( $path );
if ($err) {
die _create_unbound_error("Failed to add BIND-style trust anchor file", $err);
}
return $self;
}
#----------------------------------------------------------------------
# In case I decide to expose these:
#
# sub decode_ipv4 {
# shift if (ref $_[0]) && (ref $_[0])->isa(__PACKAGE__);
# return join('.', unpack('C4', $_[0]));
# }
#
# sub decode_ipv6 {
# shift if (ref $_[0]) && (ref $_[0])->isa(__PACKAGE__);
# return join(':', unpack('(H4)8', $_[0]));
# }
=head1 CONVENIENCE FUNCTIONS
The following may be called either as object methods or as static
functions (but not as class methods). In addition to these,
L<Socket> provides the C<inet_ntoa()> and C<inet_ntop()>
functions for decoding the values of C<A> and C<AAAA> records.
B<NOTE:> Consider parsing L<DNS::Unbound::Result>âs C<answer_packet()>
as a more robust, albeit heavier, way to parse query result data.
L<Net::DNS::Packet> and L<AnyEvent::DNS>âs C<dns_unpack()> are two good
ways to parse DNS packets.
=head2 $decoded = decode_name($encoded)
Decodes a DNS name. Useful for, e.g., C<NS>, C<CNAME>, and C<PTR> query
results.
Note that this functionâs return will normally include a trailing C<.>
because of the trailing NUL byte in an encoded DNS name. This is normal
and expected.
=cut
sub decode_name {
shift if ( ref $_[0] ) && ( ref $_[0] )->isa(__PACKAGE__);
return join( '.', @{ decode_character_strings( $_[0] ) } );
}
=head2 $strings_ar = decode_character_strings($encoded)
Decodes a list of character-strings into component strings,
returned as an array reference. Useful for C<TXT> query results.
=cut
sub decode_character_strings {
shift if ( ref $_[0] ) && ( ref $_[0] )->isa(__PACKAGE__);
return [ unpack( '(C/a)*', $_[0] ) ];
}
#----------------------------------------------------------------------
sub DESTROY {
my $self = shift;
if ($$ != $self->{'_pid'}) {
my $is_gd = ${^GLOBAL_PHASE};
$is_gd &&= ($is_gd eq 'DESTRUCT');
if ($is_gd) {
warn "$self DESTROYed at global destruction; memory leak likely!";
}
}
}
1;
=head1 SEE ALSO
L<Net::DNS::Resolver::Recurse> provides comparable logic to this module
in pure Perl. Like Unbound, it is maintained by
L<NLnet Labs|https://nlnetlabs.nl/>.
L<Net::DNS::Resolver::Unbound> is another XS binding to Unbound,
implemented as a subclass of L<Net::DNS::Resolver>.
=head1 LICENSE & COPYRIGHT
Copyright 2019-2022 Gasper Software Consulting.
This library is licensed under the same terms as Perl itself.
=head1 REPOSITORY
( run in 0.938 second using v1.01-cache-2.11-cpan-9581c071862 )