File: 05-AAAA.t

package info (click to toggle)
libnet-dns-perl 1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: perl: 18,185; makefile: 9
file content (151 lines) | stat: -rw-r--r-- 4,652 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
# $Id: 05-AAAA.t 1910 2023-03-30 19:16:30Z willem $	-*-perl-*-
#

use strict;
use warnings;
use Test::More tests => 133;

use Net::DNS;


my $name = 'AAAA.example';
my $type = 'AAAA';
my $code = 28;
my @attr = qw( address );
my @data = qw( 1:203:405:607:809:a0b:c0d:e0f );
my @also = qw( );

my $wire = '000102030405060708090a0b0c0d0e0f';

my $typecode = unpack 'xn', Net::DNS::RR->new( type => $type )->encode;
is( $typecode, $code, "$type RR type code = $code" );

my $hash = {};
@{$hash}{@attr} = @data;


for my $rr ( Net::DNS::RR->new( name => $name, type => $type, %$hash ) ) {
	my $string = $rr->string;
	my $rr2	   = Net::DNS::RR->new($string);
	is( $rr2->string, $string, 'new/string transparent' );

	is( $rr2->encode, $rr->encode, 'new($string) and new(%hash) equivalent' );

	foreach (@attr) {
		is( $rr->$_, $hash->{$_}, "expected result from rr->$_()" );
	}

	foreach (@also) {
		is( $rr2->$_, $rr->$_, "additional attribute rr->$_()" );
	}

	my $encoded = $rr->encode;
	my $decoded = Net::DNS::RR->decode( \$encoded );
	my $hex1    = unpack 'H*', $encoded;
	my $hex2    = unpack 'H*', $decoded->encode;
	my $hex3    = unpack 'H*', $rr->rdata;
	is( $hex2, $hex1, 'encode/decode transparent' );
	is( $hex3, $wire, 'encoded RDATA matches example' );
}


my %IPv6compression = (
	'0:0:0:0:0:0:0:0' => '::',
	'0:0:0:0:0:0:0:8' => '::8',
	'0:0:0:0:0:0:7:0' => '::7:0',
	'0:0:0:0:0:6:0:0' => '::6:0:0',
	'0:0:0:0:0:6:0:8' => '::6:0:8',
	'0:0:0:0:5:0:0:0' => '::5:0:0:0',
	'0:0:0:0:5:0:0:8' => '::5:0:0:8',
	'0:0:0:0:5:0:7:0' => '::5:0:7:0',
	'0:0:0:4:0:0:0:0' => '0:0:0:4::',
	'0:0:0:4:0:0:0:8' => '::4:0:0:0:8',
	'0:0:0:4:0:0:7:0' => '::4:0:0:7:0',
	'0:0:0:4:0:6:0:0' => '::4:0:6:0:0',
	'0:0:0:4:0:6:0:8' => '::4:0:6:0:8',
	'0:0:3:0:0:0:0:0' => '0:0:3::',
	'0:0:3:0:0:0:0:8' => '0:0:3::8',
	'0:0:3:0:0:0:7:0' => '0:0:3::7:0',
	'0:0:3:0:0:6:0:0' => '::3:0:0:6:0:0',
	'0:0:3:0:0:6:0:8' => '::3:0:0:6:0:8',
	'0:0:3:0:5:0:0:0' => '0:0:3:0:5::',
	'0:0:3:0:5:0:0:8' => '::3:0:5:0:0:8',
	'0:0:3:0:5:0:7:0' => '::3:0:5:0:7:0',
	'0:2:0:0:0:0:0:0' => '0:2::',
	'0:2:0:0:0:0:0:8' => '0:2::8',
	'0:2:0:0:0:0:7:0' => '0:2::7:0',
	'0:2:0:0:0:6:0:0' => '0:2::6:0:0',
	'0:2:0:0:0:6:0:8' => '0:2::6:0:8',
	'0:2:0:0:5:0:0:0' => '0:2:0:0:5::',
	'0:2:0:0:5:0:0:8' => '0:2::5:0:0:8',
	'0:2:0:0:5:0:7:0' => '0:2::5:0:7:0',
	'0:2:0:4:0:0:0:0' => '0:2:0:4::',
	'0:2:0:4:0:0:0:8' => '0:2:0:4::8',
	'0:2:0:4:0:0:7:0' => '0:2:0:4::7:0',
	'0:2:0:4:0:6:0:0' => '0:2:0:4:0:6::',
	'0:2:0:4:0:6:0:8' => '0:2:0:4:0:6:0:8',
	'1:0:0:0:0:0:0:0' => '1::',
	'1:0:0:0:0:0:0:8' => '1::8',
	'1:0:0:0:0:0:7:0' => '1::7:0',
	'1:0:0:0:0:6:0:0' => '1::6:0:0',
	'1:0:0:0:0:6:0:8' => '1::6:0:8',
	'1:0:0:0:5:0:0:0' => '1::5:0:0:0',
	'1:0:0:0:5:0:0:8' => '1::5:0:0:8',
	'1:0:0:0:5:0:7:0' => '1::5:0:7:0',
	'1:0:0:4:0:0:0:0' => '1:0:0:4::',
	'1:0:0:4:0:0:0:8' => '1:0:0:4::8',
	'1:0:0:4:0:0:7:0' => '1::4:0:0:7:0',
	'1:0:0:4:0:6:0:0' => '1::4:0:6:0:0',
	'1:0:0:4:0:6:0:8' => '1::4:0:6:0:8',
	'1:0:3:0:0:0:0:0' => '1:0:3::',
	'1:0:3:0:0:0:0:8' => '1:0:3::8',
	'1:0:3:0:0:0:7:0' => '1:0:3::7:0',
	'1:0:3:0:0:6:0:0' => '1:0:3::6:0:0',
	'1:0:3:0:0:6:0:8' => '1:0:3::6:0:8',
	'1:0:3:0:5:0:0:0' => '1:0:3:0:5::',
	'1:0:3:0:5:0:0:8' => '1:0:3:0:5::8',
	'1:0:3:0:5:0:7:0' => '1:0:3:0:5:0:7:0',
	);

foreach my $address ( sort keys %IPv6compression ) {
	my $compact = $IPv6compression{$address};
	my $rr1	    = Net::DNS::RR->new( name => $name, type => $type, address => $address );
	is( $rr1->address_short, $compact, "address compression:\t$address" );
	my $rr2 = Net::DNS::RR->new( name => $name, type => $type, address => $compact );
	is( $rr2->address_long, $address, "address expansion:\t$compact" );
}


my %IPv6completion = (
	'1'		 => '1:0:0:0:0:0:0:0',
	'1:'		 => '1:0:0:0:0:0:0:0',
	'1:2'		 => '1:2:0:0:0:0:0:0',
	'1:2:'		 => '1:2:0:0:0:0:0:0',
	'1:2:3'		 => '1:2:3:0:0:0:0:0',
	'1:2:3:'	 => '1:2:3:0:0:0:0:0',
	'1:2:3:4'	 => '1:2:3:4:0:0:0:0',
	'1:2:3:4:'	 => '1:2:3:4:0:0:0:0',
	'1:2:3:4:5'	 => '1:2:3:4:5:0:0:0',
	'1:2:3:4:5:'	 => '1:2:3:4:5:0:0:0',
	'1:2:3:4:5:6'	 => '1:2:3:4:5:6:0:0',
	'1:2:3:4:5:6:'	 => '1:2:3:4:5:6:0:0',
	'1:2:3:4:5:6:7'	 => '1:2:3:4:5:6:7:0',
	'1:2:3:4:5:6:7:' => '1:2:3:4:5:6:7:0',
	'::ffff:1.2.3.4' => '0:0:0:0:0:ffff:102:304',
	'::ffff:1.2.4'	 => '0:0:0:0:0:ffff:102:4',
	'::ffff:1.4'	 => '0:0:0:0:0:ffff:100:4',
	);

foreach my $address ( sort keys %IPv6completion ) {
	my $expect = Net::DNS::RR->new(
		name	=> $name,
		type	=> $type,
		address => $IPv6completion{$address} );
	my $rr = Net::DNS::RR->new( name => $name, type => $type, address => $address );
	is( $rr->address, $expect->address, "address completion:\t$address" );
}


exit;