Net-DNS

 view release on metacpan or  search on metacpan

lib/Net/DNS/Question.pm  view on Meta::CPAN

sub qname {
	my ( $self, @argument ) = @_;
	for (@argument) { croak 'immutable object: argument invalid' }
	return $self->{qname}->name;
}

sub zname { return &qname; }


=head2 qtype, ztype, type

	$qtype = $question->type;
	$qtype = $question->qtype;
	$ztype = $question->ztype;

Returns the question type attribute.  In dynamic update packets,
this attribute is known as ztype() and refers to the zone type.

=cut

sub type {
	my ( $self, @argument ) = @_;
	for (@argument) { croak 'immutable object: argument invalid' }
	return typebyval( $self->{qtype} );
}

sub qtype { return &type; }
sub ztype { return &type; }


=head2 qclass, zclass, class

	$qclass = $question->class;
	$qclass = $question->qclass;
	$zclass = $question->zclass;

Returns the question class attribute.  In dynamic update packets,
this attribute is known as zclass() and refers to the zone class.

=cut

sub class {
	my ( $self, @argument ) = @_;
	for (@argument) { croak 'immutable object: argument invalid' }
	return classbyval( $self->{qclass} );
}

sub qclass { return &class; }
sub zclass { return &class; }


########################################

sub _dns_addr {				## Map IP address into reverse lookup namespace
	local $_ = shift;

	# IP address must contain address characters only
	s/[%].+$//;						# discard RFC4007 scopeid
	return unless m#^[a-fA-F0-9:./]+$#;

	my ( $address, $pfxlen ) = split m#/#;

	# map IPv4 address to in-addr.arpa space
	if (m#^\d*[.\d]*\d(/\d+)?$#) {
		my @parse = split /\./, $address;
		$pfxlen = scalar(@parse) << 3 unless $pfxlen;
		my $last = $pfxlen > 24 ? 3 : ( $pfxlen - 1 ) >> 3;
		return join '.', reverse( ( @parse, (0) x 3 )[0 .. $last] ), 'in-addr.arpa.';
	}

	# map IPv6 address to ip6.arpa space
	return unless m#^[:\w]+:([.\w]*)(/\d+)?$#;
	my $rhs = $1 || '0';
	return _dns_addr($rhs) if m#^[:0]*:0*:[fF]{4}:[^:]+$#;	# IPv4
	$rhs = sprintf '%x%0.2x:%x%0.2x', map { $_ || 0 } split( /\./, $rhs, 4 ) if /\./;
	$address =~ s/:[^:]*$/:0$rhs/;
	my @parse = split /:/, ( reverse "0$address" ), 9;
	my @xpand = map { /./ ? $_ : ('0') x ( 9 - @parse ) } @parse;	 # expand ::
	$pfxlen = ( scalar(@xpand) << 4 ) unless $pfxlen;	# implicit length if unspecified
	my $len = $pfxlen > 124 ? 32 : ( $pfxlen + 3 ) >> 2;
	my $hex = pack 'A4' x 8, map { $_ . '000' } ('0') x ( 8 - @xpand ), @xpand;
	return join '.', split( //, substr( $hex, -$len ) ), 'ip6.arpa.';
}


1;
__END__

########################################

=head1 COPYRIGHT

Copyright (c)1997-2000 Michael Fuhr. 

Portions Copyright (c)2002,2003 Chris Reinhardt.

Portions Copyright (c)2003,2006-2011 Dick Franks.

All rights reserved.


=head1 LICENSE

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the original copyright notices appear in all copies and that both
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.


=head1 SEE ALSO



( run in 1.015 second using v1.01-cache-2.11-cpan-71847e10f99 )