/[pxelator]/lib/PXElator/dnsd.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/dnsd.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (show annotations)
Mon Aug 3 08:57:59 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 922 byte(s)
skeleton of DNS server from Net::DNS::Nameserver

1 package dnsd;
2
3 use warnings;
4 use strict;
5
6 use Net::DNS::Nameserver;
7 use Data::Dump qw/dump/;
8
9 sub reply_handler {
10 my ($qname, $qclass, $qtype, $peerhost,$query,$conn) = @_;
11 my ($rcode, @ans, @auth, @add);
12
13 print "Received query from $peerhost to ". $conn->{"sockhost"}. "\n";
14 $query->print;
15
16
17 if ($qtype eq "A" && $qname eq "foo.example.com" ) {
18 my ($ttl, $rdata) = (3600, "10.1.2.3");
19 push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
20 $rcode = "NOERROR";
21 }elsif( $qname eq "foo.example.com" ) {
22 $rcode = "NOERROR";
23
24 }else{
25 $rcode = "NXDOMAIN";
26 }
27
28 # mark the answer as authoritive (by setting the 'aa' flag
29 return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
30 }
31
32 sub start {
33 my $ns = Net::DNS::Nameserver->new(
34 LocalPort => 53,
35 ReplyHandler => \&reply_handler,
36 Verbose => 1,
37 ) || die "couldn't create nameserver object\n";
38
39 warn dump( $ns );
40
41 $ns->main_loop;
42 }
43
44 1;

  ViewVC Help
Powered by ViewVC 1.1.26