File: nameserver

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 (33 lines) | stat: -rwxr-xr-x 640 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
#!/usr/bin/perl -Tw

use Net::DNS;
use strict;
      
sub reply_handler {
    my ($qname, $qclass, $qtype) = @_;
    my ($rcode, @ans, @auth, @add);
 
    if ($qtype eq "A") {
      my ($ttl, $rdata) = (3600, "10.1.2.3");
      push @ans, Net::DNS::RR->new("$qname $ttl $qclass $qtype $rdata");
      $rcode = "NOERROR";
    }
    else {
      $rcode = "NXDOMAIN";
    }
      
    return ($rcode, \@ans, \@auth, \@add);
}
  
my $ns = Net::DNS::Nameserver->new(
    LocalPort    => 5353,
    ReplyHandler => \&reply_handler,
    Verbose      => 1
);

if ($ns) {
    $ns->main_loop;
}
else {
    die "couldn't create nameserver object\n";
}