.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\" ========================================================================
.\"
.IX Title "Net::DNS::Nameserver 3"
.TH Net::DNS::Nameserver 3 "2019-03-22" "perl v5.10.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Net::DNS::Nameserver \- DNS server class
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Net::DNS::Nameserver;
\&
\& my $nameserver = new Net::DNS::Nameserver(
\& LocalAddr => [\*(Aq::1\*(Aq , \*(Aq127.0.0.1\*(Aq],
\& ZoneFile => "filename"
\& );
\&
\& my $nameserver = new Net::DNS::Nameserver(
\& LocalAddr => \*(Aq10.1.2.3\*(Aq,
\& LocalPort => 5353,
\& ReplyHandler => \e&reply_handler
\& );
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Net::DNS::Nameserver offers a simple mechanism for instantiation of
customised \s-1DNS\s0 server objects intended to provide test responses to
queries emanating from a client resolver.
.PP
It is not, nor will it ever be, a general-purpose \s-1DNS\s0 nameserver
implementation.
.PP
See \*(L"\s-1EXAMPLE\s0\*(R" for an example.
.SH "METHODS"
.IX Header "METHODS"
.SS "new"
.IX Subsection "new"
.Vb 4
\& $nameserver = new Net::DNS::Nameserver(
\& LocalAddr => [\*(Aq::1\*(Aq , \*(Aq127.0.0.1\*(Aq],
\& ZoneFile => "filename"
\& );
\&
\& $nameserver = new Net::DNS::Nameserver(
\& LocalAddr => \*(Aq10.1.2.3\*(Aq,
\& LocalPort => 5353,
\& ReplyHandler => \e&reply_handler,
\& Verbose => 1,
\& Truncate => 0
\& );
.Ve
.PP
Returns a Net::DNS::Nameserver object, or undef if the object
could not be created.
.PP
Each instance is configured using the following optional arguments:
.PP
.Vb 10
\& LocalAddr IP address on which to listen Defaults to loopback address
\& LocalPort Port on which to listen Defaults to 53
\& ZoneFile Name of file containing RRs
\& accessed using the default
\& reply\-handling subroutine
\& ReplyHandler Reference to customised
\& reply\-handling subroutine
\& NotifyHandler Reference to reply\-handling
\& subroutine for queries with
\& opcode NOTIFY (RFC1996)
\& UpdateHandler Reference to reply\-handling
\& subroutine for queries with
\& opcode UPDATE (RFC2136)
\& Verbose Report internal activity Defaults to 0 (off)
\& Truncate Truncates UDP packets that
\& are too big for the reply Defaults to 1 (on)
\& IdleTimeout TCP clients are disconnected
\& if they are idle longer than
\& this duration Defaults to 120 (secs)
.Ve
.PP
The LocalAddr attribute may alternatively be specified as a list of \s-1IP\s0
addresses to listen to.
If the IO::Socket::IP library package is available on the system
this may also include IPv6 addresses.
.PP
The ReplyHandler subroutine is passed the query name, query class,
query type and optionally an argument containing the peerhost, the
incoming query, and the name of the incoming socket (sockethost). It
must either return the response code and references to the answer,
authority, and additional sections of the response, or undef to leave
the query unanswered. Common response codes are:
.PP
.Vb 6
\& NOERROR No error
\& FORMERR Format error
\& SERVFAIL Server failure
\& NXDOMAIN Non\-existent domain (name doesn\*(Aqt exist)
\& NOTIMP Not implemented
\& REFUSED Query refused
.Ve
.PP
For advanced usage it may also contain a headermask containing an
hashref with the settings for the \f(CW\*(C`aa\*(C'\fR, \f(CW\*(C`ra\*(C'\fR, and \f(CW\*(C`ad\*(C'\fR
header bits. The argument is of the form
\&\f(CW\*(C`{ ad => 1, aa => 0, ra => 1 }\*(C'\fR.
.PP
\&\s-1EDNS\s0 options may be specified in a similar manner using optionmask
\&\f(CW\*(C`{ $optioncode => $value, $optionname => $value }\*(C'\fR.
.PP
See \s-1RFC\s0 1035 and the \s-1IANA\s0 dns-parameters file for more information:
.PP
.Vb 2
\& ftp://ftp.rfc\-editor.org/in\-notes/rfc1035.txt
\& http://www.isi.edu/in\-notes/iana/assignments/dns\-parameters
.Ve
.PP
The nameserver will listen for both \s-1UDP\s0 and \s-1TCP\s0 connections. On
Unix-like systems, the program will probably have to run as root
to listen on the default port, 53. A non-privileged user should
be able to listen on ports 1024 and higher.
.PP
\&\s-1UDP\s0 reply truncation functionality was introduced in \s-1VERSION\s0 830.
The size limit is determined by the \s-1EDNS0\s0 size advertised in the query,
otherwise 512 is used.
If you want to do packet truncation yourself you should set \f(CW\*(C`Truncate\*(C'\fR
to 0 and truncate the reply packet in the code of the ReplyHandler.
.PP
See \*(L"\s-1EXAMPLE\s0\*(R" for an example.
.SS "main_loop"
.IX Subsection "main_loop"
.Vb 1
\& $ns\->main_loop;
.Ve
.PP
Start accepting queries. Calling main_loop never returns.
.SS "loop_once"
.IX Subsection "loop_once"
.Vb 1
\& $ns\->loop_once( [TIMEOUT_IN_SECONDS] );
.Ve
.PP
Start accepting queries, but returns. If called without a parameter, the
call will not return until a request has been received (and replied to).
Otherwise, the parameter specifies the maximum time to wait for a request.
A zero timeout forces an immediate return if there is nothing to do.
.PP
Handling a request and replying obviously depends on the speed of
ReplyHandler. Assuming a fast ReplyHandler, loop_once should spend just a
fraction of a second, if called with a timeout value of 0.0 seconds. One
exception is when an \s-1AXFR\s0 has requested a huge amount of data that the \s-1OS\s0
is not ready to receive in full. In that case, it will remain in a loop
(while servicing new requests) until the reply has been sent.
.PP
In case loop_once accepted a \s-1TCP\s0 connection it will immediately check if
there is data to be read from the socket. If not it will return and you
will have to call \fIloop_once()\fR again to check if there is any data waiting
on the socket to be processed. In most cases you will have to count on
calling \*(L"loop_once\*(R" twice.
.PP
A code fragment like:
.PP
.Vb 4
\& $ns\->loop_once(10);
\& while( $ns\->get_open_tcp() ){
\& $ns\->loop_once(0);
\& }
.Ve
.PP
Would wait for 10 seconds for the initial connection and would then
process all \s-1TCP\s0 sockets until none is left.
.SS "get_open_tcp"
.IX Subsection "get_open_tcp"
In scalar context returns the number of \s-1TCP\s0 connections for which state
is maintained. In array context it returns IO::Socket objects, these could
be useful for troubleshooting but be careful using them.
.SH "EXAMPLE"
.IX Header "EXAMPLE"
The following example will listen on port 5353 and respond to all queries
for A records with the \s-1IP\s0 address 10.1.2.3. All other queries will be
answered with \s-1NXDOMAIN\s0. Authority and additional sections are left empty.
The \f(CW$peerhost\fR variable catches the \s-1IP\s0 address of the peer host, so that
additional filtering on its basis may be applied.
.PP
.Vb 1
\& #!/usr/bin/perl
\&
\& use strict;
\& use warnings;
\& use Net::DNS::Nameserver;
\&
\& sub reply_handler {
\& my ( $qname, $qclass, $qtype, $peerhost, $query, $conn ) = @_;
\& my ( $rcode, @ans, @auth, @add );
\&
\& print "Received query from $peerhost to " . $conn\->{sockhost} . "\en";
\& $query\->print;
\&
\& if ( $qtype eq "A" && $qname eq "foo.example.com" ) {
\& my ( $ttl, $rdata ) = ( 3600, "10.1.2.3" );
\& my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata");
\& push @ans, $rr;
\& $rcode = "NOERROR";
\& } elsif ( $qname eq "foo.example.com" ) {
\& $rcode = "NOERROR";
\&
\& } else {
\& $rcode = "NXDOMAIN";
\& }
\&
\& # mark the answer as authoritative (by setting the \*(Aqaa\*(Aq flag)
\& my $headermask = {aa => 1};
\&
\& # specify EDNS options { option => value }
\& my $optionmask = {};
\&
\& return ( $rcode, \e@ans, \e@auth, \e@add, $headermask, $optionmask );
\& }
\&
\&
\& my $ns = new Net::DNS::Nameserver(
\& LocalPort => 5353,
\& ReplyHandler => \e&reply_handler,
\& Verbose => 1
\& ) || die "couldn\*(Aqt create nameserver object\en";
\&
\&
\& $ns\->main_loop;
.Ve
.SH "BUGS"
.IX Header "BUGS"
Limitations in perl 5.8.6 makes it impossible to guarantee that
replies to \s-1UDP\s0 queries from Net::DNS::Nameserver are sent from the
IP-address they were received on. This is a problem for machines with
multiple IP-addresses and causes violation of \s-1RFC2181\s0 section 4.
Thus a \s-1UDP\s0 socket created listening to \s-1INADDR_ANY\s0 (all available
IP-addresses) will reply not necessarily with the source address being
the one to which the request was sent, but rather with the address that
the operating system chooses. This is also often called \*(L"the closest
address\*(R". This should really only be a problem on a server which has
more than one IP-address (besides localhost \- any experience with IPv6
complications here, would be nice). If this is a problem for you, a
work-around would be to not listen to \s-1INADDR_ANY\s0 but to specify each
address that you want this module to listen on. A separate set of
sockets will then be created for each IP-address.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (c)2000 Michael Fuhr.
.PP
Portions Copyright (c)2002\-2004 Chris Reinhardt.
.PP
Portions Copyright (c)2005 Robert Martin-Legene.
.PP
Portions Copyright (c)2005\-2009 O.M, Kolkman, \s-1RIPE\s0 \s-1NCC\s0.
.PP
Portions Copyright (c)2017 Dick Franks.
.PP
All rights reserved.
.SH "LICENSE"
.IX Header "LICENSE"
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising
or publicity pertaining to distribution of the software without specific
prior written permission.
.PP
\&\s-1THE\s0 \s-1SOFTWARE\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R", \s-1WITHOUT\s0 \s-1WARRANTY\s0 \s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0, \s-1EXPRESS\s0 \s-1OR\s0
\&\s-1IMPLIED\s0, \s-1INCLUDING\s0 \s-1BUT\s0 \s-1NOT\s0 \s-1LIMITED\s0 \s-1TO\s0 \s-1THE\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \s-1MERCHANTABILITY\s0,
\&\s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0 \s-1AND\s0 \s-1NONINFRINGEMENT\s0. \s-1IN\s0 \s-1NO\s0 \s-1EVENT\s0 \s-1SHALL\s0
\&\s-1THE\s0 \s-1AUTHORS\s0 \s-1OR\s0 \s-1COPYRIGHT\s0 \s-1HOLDERS\s0 \s-1BE\s0 \s-1LIABLE\s0 \s-1FOR\s0 \s-1ANY\s0 \s-1CLAIM\s0, \s-1DAMAGES\s0 \s-1OR\s0 \s-1OTHER\s0
\&\s-1LIABILITY\s0, \s-1WHETHER\s0 \s-1IN\s0 \s-1AN\s0 \s-1ACTION\s0 \s-1OF\s0 \s-1CONTRACT\s0, \s-1TORT\s0 \s-1OR\s0 \s-1OTHERWISE\s0, \s-1ARISING\s0
\&\s-1FROM\s0, \s-1OUT\s0 \s-1OF\s0 \s-1OR\s0 \s-1IN\s0 \s-1CONNECTION\s0 \s-1WITH\s0 \s-1THE\s0 \s-1SOFTWARE\s0 \s-1OR\s0 \s-1THE\s0 \s-1USE\s0 \s-1OR\s0 \s-1OTHER\s0
\&\s-1DEALINGS\s0 \s-1IN\s0 \s-1THE\s0 \s-1SOFTWARE\s0.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
perl, Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
Net::DNS::Update, Net::DNS::Header, Net::DNS::Question,
Net::DNS::RR, \s-1RFC\s0 1035
Copyright 2K16 - 2K18 Indonesian Hacker Rulez