| 1 | #!/usr/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: NIS Domain Name option (code 29) — RFC 1035 domain name | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Option::NisDomainName | ||||||||||||||||||||||||||||
| 4 | package Net::DHCPv6::Option::NisDomainName; | ||||||||||||||||||||||||||||
| 5 | 15 | $Net::DHCPv6::Option::NisDomainName::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 6 | 15 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Net::DHCPv6::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Net::DHCPv6::X::Truncated; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use Net::DHCPv6::X::BadOption; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use parent 'Net::DHCPv6::Option'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub _encode_domain { | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my ( $domain ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_encode_domain: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | return "\x00" unless defined $domain && CORE::length( $domain ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $domain and length $domain
MC/DC0%0/2
defined $domain and length $domain
defined $domain
length $domain
Truth table33%1/3
A and B
A= defined $domainB= length $domain
| |||||||||||||||||||||||||||||
| 17 | 2 | my @labels = split m/\./, $domain; | |||||||||||||||||||||||||||
| 18 | 2 | join( '', map { pack( 'C', CORE::length ) . $_ } @labels ) . "\x00"; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub _read_labels_at { | ||||||||||||||||||||||||||||
| 22 | 1 | ▶ | my ( $data, $offset_ref, $len ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_read_labels_at: called CC=9 SCAR=29.1
| |||||||||||||||||||||||||||||
| 23 | 1 | my @labels; | |||||||||||||||||||||||||||
| 24 | 1 | ▶ | while ( $$offset_ref < $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 4 | my $llen = unpack( 'C', substr( $data, $$offset_ref, 1 ) ); | |||||||||||||||||||||||||||
| 26 | 4 | ▶ | if ( $llen == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 1 | ++$$offset_ref; | |||||||||||||||||||||||||||
| 28 | 1 | last; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 3 | ▶ | if ( ( $llen & 0xC0 ) == 0xC0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | if $$offset_ref + 2 > $len; | ||||||||||||||||||||||||||||
| 34 | 0 | my $ptr = ( ( $llen & 0x3F ) << 8 ) | unpack( 'C', substr( $data, $$offset_ref + 1, 1 ) ); | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | if $ptr >= $len; | ||||||||||||||||||||||||||||
| 37 | 0 | $$offset_ref += 2; | |||||||||||||||||||||||||||
| 38 | 0 | my $ptr_ref = \$ptr; | |||||||||||||||||||||||||||
| 39 | 0 | push @labels, _read_labels_at( $data, $ptr_ref, $len ); | |||||||||||||||||||||||||||
| 40 | 0 | last; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' ); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 3 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > 63; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 3 | ++$$offset_ref; | |||||||||||||||||||||||||||
| 46 | 3 | ▶ | Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if $$offset_ref + $llen > $len; | ||||||||||||||||||||||||||||
| 48 | 3 | push @labels, substr( $data, $$offset_ref, $llen ); | |||||||||||||||||||||||||||
| 49 | 3 | $$offset_ref += $llen; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 1 | return @labels; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub _decode_domain { | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my ( $data ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_decode_domain: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 56 | 1 | ▶ | return '' unless CORE::length( $data ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | my $offset = 0; | |||||||||||||||||||||||||||
| 58 | 1 | my @labels = _read_labels_at( $data, \$offset, CORE::length( $data ) ); | |||||||||||||||||||||||||||
| 59 | 1 | return join( '.', @labels ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub new { | ||||||||||||||||||||||||||||
| 63 | 3 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | croak 'NisDomainName requires domain_name' unless defined $args{domain_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 2 | $args{code} = $OPTION_NIS_DOMAIN_NAME; | |||||||||||||||||||||||||||
| 66 | 2 | $args{data} = _encode_domain( $args{domain_name} ); | |||||||||||||||||||||||||||
| 67 | 2 | my $self = $class->SUPER::new( %args ); | |||||||||||||||||||||||||||
| 68 | 2 | $self->{domain_name} = $args{domain_name}; | |||||||||||||||||||||||||||
| 69 | 2 | bless $self, $class; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | sub domain_name { shift->{domain_name} } | ||||||||||||||||||||||||||
|
Subroutine
domain_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub from_bytes_inner { | ||||||||||||||||||||||||||||
| 75 | 1 | ▶ | my ( $class, $code, $data ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
from_bytes_inner: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 1 | my $name = _decode_domain( $data ); | |||||||||||||||||||||||||||
| 77 | 1 | return $class->new( domain_name => $name ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 15 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_NIS_DOMAIN_NAME} = __PACKAGE__; | |||||||||||||||||||||||||||
| 81 | 15 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||