3 # Copyright (C) 2004, 2007, 2009, 2012 Internet Systems Consortium, Inc. ("ISC")
4 # Copyright (C) 2000, 2001 Internet Software Consortium.
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
10 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 # PERFORMANCE OF THIS SOFTWARE.
18 # Id: ans.pl,v 1.12 2009/11/04 02:15:30 marka Exp
29 my $sock = IO
::Socket
::INET
->new(LocalAddr
=> "10.53.0.3",
30 LocalPort
=> 5300, Proto
=> "udp") or die "$!";
32 my $pidf = new IO
::File
"ans.pid", "w" or die "cannot open pid file: $!";
33 print $pidf "$$\n" or die "cannot write pid file: $!";
34 $pidf->close or die "cannot close pid file: $!";
35 sub rmpid
{ unlink "ans.pid"; exit 1; };
41 $sock->recv($buf, 512);
43 print "**** request from " , $sock->peerhost, " port ", $sock->peerport, "\n";
47 if ($Net::DNS
::VERSION
> 0.68) {
48 $packet = new Net
::DNS
::Packet
(\
$buf, 0);
52 ($packet, $err) = new Net
::DNS
::Packet
(\
$buf, 0);
59 $packet->header->qr(1);
60 $packet->header->aa(1);
62 my @questions = $packet->question;
63 my $qname = $questions[0]->qname;
65 if ($qname eq "badcname.example.net") {
66 $packet->push("answer",
67 new Net
::DNS
::RR
($qname .
68 " 300 CNAME badcname.example.org"));
69 } elsif ($qname eq "foo.baddname.example.net") {
70 $packet->push("answer",
71 new Net
::DNS
::RR
("baddname.example.net" .
72 " 300 DNAME baddname.example.org"));
73 } elsif ($qname eq "foo.gooddname.example.net") {
74 $packet->push("answer",
75 new Net
::DNS
::RR
("gooddname.example.net" .
76 " 300 DNAME gooddname.example.org"));
77 } elsif ($qname eq "goodcname.example.net") {
78 $packet->push("answer",
79 new Net
::DNS
::RR
($qname .
80 " 300 CNAME goodcname.example.org"));
81 } elsif ($qname eq "cname.sub.example.org") {
82 $packet->push("answer",
83 new Net
::DNS
::RR
($qname .
84 " 300 CNAME ok.sub.example.org"));
85 } elsif ($qname eq "ok.sub.example.org") {
86 $packet->push("answer",
87 new Net
::DNS
::RR
($qname . " 300 A 192.0.2.1"));
88 } elsif ($qname eq "www.dname.sub.example.org") {
89 $packet->push("answer",
90 new Net
::DNS
::RR
("dname.sub.example.org" .
91 " 300 DNAME ok.sub.example.org"));
92 } elsif ($qname eq "www.ok.sub.example.org") {
93 $packet->push("answer",
94 new Net
::DNS
::RR
($qname . " 300 A 192.0.2.1"));
96 $packet->push("answer", new Net
::DNS
::RR
("www.example.com 300 A 1.2.3.4"));
99 $sock->send($packet->data);