Unix/Linux Go Back    

RedHat 9 (Linux i386) - man page for net::dns::nameserver (redhat section 3)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)

Net::DNS::Nameserver(3)        User Contributed Perl Documentation	  Net::DNS::Nameserver(3)

       Net::DNS::Nameserver - DNS server class

       "use Net::DNS::Nameserver;"

       Instances of the "Net::DNS::Nameserver" class represent simple DNS server objects.  See
       "EXAMPLE" for an example.


	       my $ns = Net::DNS::Nameserver->new(
	       LocalAddr	=> "",
	       LocalPort	=> "5353",
	       ReplyHandler => \&reply_handler,
	       Verbose		=> 1

       Creates a nameserver object.  Attributes are:

	 LocalAddr	       IP address on which to listen.  Defaults to INADDR_ANY.
	 LocalPort	       Port on which to listen.  Defaults to 53.
	 ReplyHandler  Reference to reply-handling subroutine.	Required.
	 Verbose	       Print info about received queries.      Defaults to 0 (off).

       The ReplyHandler subroutine is passed the query name, query class, and query type.      It
       must return the response code and references to the answer, authority, and additional sec-
       tions of the response.  Common response codes are:

	 NOERROR       No error
	 FORMERR       Format error
	 SERVFAIL      Server failure
	 NXDOMAIN      Non-existent domain (name doesn't exist)
	 NOTIMP        Not implemented
	 REFUSED       Query refused

       See RFC 1035 and the IANA dns-parameters file for more information:


       The nameserver will listen for both UDP and TCP connections.  On Unix-like systems, the
       program will probably have to run as root to listen on the default port, 53. A non-privi-
       leged user should be able to listen on ports 1024 and higher.

       Returns a Net::DNS::Nameserver object, or undef if the object couldn't be created.

       See "EXAMPLE" for an example.



       Start accepting queries.

       The following example will listen on port 5353 and respond to all queries for A records
       with the IP address	All other queries will be answered with NXDOMAIN.
       Authority and additional sections are left empty.

	 #!/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, "");
		       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) {
	 else {
		 die "couldn't create nameserver object\n";

       Net::DNS::Nameserver objects can handle only one query at a time.

       Copyright (c) 2000-2002 Michael Fuhr.  All rights reserved. This program is free software;
       you can redistribute it and/or modify it under the same terms as Perl itself.

       perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Update,
       Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 1035

perl v5.8.0				    2002-05-31			  Net::DNS::Nameserver(3)
Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums

All times are GMT -4. The time now is 10:21 PM.