/[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

Annotation of /lib/PXElator/dnsd.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 125 - (hide annotations)
Mon Aug 3 15:06:23 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 1230 byte(s)
implement resolver for queries which we don't handle

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

  ViewVC Help
Powered by ViewVC 1.1.26