File: 04-packet.t

package info (click to toggle)
libnet-dns-perl 0.19-0.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 544 kB
  • ctags: 323
  • sloc: perl: 5,191; makefile: 54
file content (111 lines) | stat: -rw-r--r-- 2,984 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
# $Id: 04-packet.t,v 1.4 2000/11/19 06:11:00 mfuhr Exp mfuhr $

BEGIN { $| = 1; print "1..19\n"; }
END {print "not ok 1\n" unless $loaded;}

use Net::DNS;

$loaded = 1;
print "ok 1\n";

$domain = "example.com";
$type   = "MX";
$class  = "IN";

#------------------------------------------------------------------------------
# Make sure we can create a DNS packet.
#------------------------------------------------------------------------------

$packet = Net::DNS::Packet->new($domain, $type, $class);
print "not " unless defined $packet;
print "ok 2\n";

print "not " unless defined $packet->header;
print "ok 3\n";

@question = $packet->question;
print "not " unless @question  && (@question == 1);
print "ok 4\n";

@answer = $packet->answer;
print "not " if @answer;
print "ok 5\n";

@authority = $packet->authority;
print "not " if @authority;
print "ok 6\n";

@additional = $packet->additional;
print "not " if @additional;
print "ok 7\n";

#------------------------------------------------------------------------------
# Make sure we can add records to the packet.
#------------------------------------------------------------------------------

$packet->push("answer", Net::DNS::RR->new(
	Name    => "a1.example.com",
	Type    => "A",
	Address => "10.0.0.1"));
print "not " unless $packet->header->ancount == 1;
print "ok 8\n";

$packet->push("answer", Net::DNS::RR->new(
	Name    => "a2.example.com",
	Type    => "A",
	Address => "10.0.0.2"));
print "not " unless $packet->header->ancount == 2;
print "ok 9\n";

$packet->push("authority", Net::DNS::RR->new(
	Name    => "a3.example.com",
	Type    => "A",
	Address => "10.0.0.3"));
print "not " unless $packet->header->nscount == 1;
print "ok 10\n";

$packet->push("authority", Net::DNS::RR->new(
	Name    => "a4.example.com",
	Type    => "A",
	Address => "10.0.0.4"));
print "not " unless $packet->header->nscount == 2;
print "ok 11\n";

$packet->push("additional", Net::DNS::RR->new(
	Name    => "a5.example.com",
	Type    => "A",
	Address => "10.0.0.5"));
print "not " unless $packet->header->adcount == 1;
print "ok 12\n";

$packet->push("additional", Net::DNS::RR->new(
	Name    => "a6.example.com",
	Type    => "A",
	Address => "10.0.0.6"));
print "not " unless $packet->header->adcount == 2;
print "ok 13\n";

#------------------------------------------------------------------------------
# Make sure we can convert a packet to data and back to a packet.
#------------------------------------------------------------------------------

$data1 = $packet->data;
$data2 = $packet->data;
print "not " unless $data1 eq $data2;
print "ok 14\n";

$packet2 = Net::DNS::Packet->new(\$data1);
print "not " unless defined $packet2;
print "ok 15\n";

print "not " unless $packet2->header->qdcount == 1;
print "ok 16\n";

print "not " unless $packet2->header->ancount == 2;
print "ok 17\n";

print "not " unless $packet2->header->nscount == 2;
print "ok 18\n";

print "not " unless $packet2->header->adcount == 2;
print "ok 19\n";