.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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" '' . ds C` . ds C' '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 >0, 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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Net::TFTPd 3pm" .TH Net::TFTPd 3pm "2022-10-13" "perl v5.34.0" "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::TFTPd \- Perl extension for Trivial File Transfer Protocol Server .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use strict; \& use Net::TFTPd; \& \& my $tftpdOBJ = Net::TFTPd\->new(\*(AqRootDir\*(Aq => \*(Aqpath/to/files\*(Aq) \& or die "Error creating TFTPd listener: %s", Net::TFTPd\->error; \& \& my $tftpRQ = $tftpdOBJ\->waitRQ(10) \& or die "Error waiting for TFTP request: %s", Net::TFTPd\->error; \& \& $tftpRQ\->processRQ() \& or die "Error processing TFTP request: %s", Net::TFTPd\->error; \& \& printf "%u bytes has been transferred", $tftpRQ\->getTotalBytes() || 0; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Net::TFTPd\*(C'\fR is a class implementing a simple \fITrivial File Transfer Protocol\fR server in Perl as described in \s-1RFC1350.\s0 .PP \&\f(CW\*(C`Net::TFTPd\*(C'\fR also supports the \s-1TFTP\s0 Option Extension (as described in \s-1RFC2347\s0), with the following options: .PP .Vb 2 \& RFC2348 TFTP Blocksize Option \& RFC2349 TFTP Timeout Interval and Transfer Size Options .Ve .SH "EXPORT" .IX Header "EXPORT" None by default. .ie n .SS "%OPCODES" .el .SS "\f(CW%OPCODES\fP" .IX Subsection "%OPCODES" The \f(CW%OPCODES\fR tag exports the \fI\f(CI%OPCODES\fI\fR hash: .PP .Vb 10 \& %OPCODES = ( \& 1 => \*(AqRRQ\*(Aq, \& 2 => \*(AqWRQ\*(Aq, \& 3 => \*(AqDATA\*(Aq, \& 4 => \*(AqACK\*(Aq, \& 5 => \*(AqERROR\*(Aq, \& 6 => \*(AqOACK\*(Aq, \& \*(AqRRQ\*(Aq => 1, \& \*(AqWRQ\*(Aq => 2, \& \*(AqDATA\*(Aq => 3, \& \*(AqACK\*(Aq => 4, \& \*(AqERROR\*(Aq => 5, \& \*(AqOACK\*(Aq => 6 \& ); .Ve .SH "Listener constructor" .IX Header "Listener constructor" .SS "\fBnew()\fP" .IX Subsection "new()" .Vb 1 \& $listener = new Net::TFTPd( [\*(AqRootDir\*(Aq => \*(Aqpath/to/files\*(Aq | \*(AqFileName\*(Aq => \*(Aqpath/to/file\*(Aq] [, OPTIONS ] ); .Ve .PP or .PP .Vb 1 \& $listener = Net::TFTPd\->new( [\*(AqRootDir\*(Aq => \*(Aqpath/to/files\*(Aq | \*(AqFileName\*(Aq => \*(Aqpath/to/file\*(Aq] [, OPTIONS ] ); .Ve .PP Create a new Net::TFTPd object where 'path/to/files' is the default path to file repository or 'path/to/file' is the single file allowed for download, and \s-1OPTIONS\s0 are the default server options. .PP Valid options are: .PP .Vb 10 \& Option Description Default \& \-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\- \& LocalAddr Interface to bind to (for multi\-homed server) any \& LocalPort Port to bind server to 69 \& Timeout Timeout in seconds to wait for a request 10 \& ACKtimeout Timeout in seconds to wait for an ACK packet 4 \& ACKretries Maximum number of retries waiting for ACK 4 \& Readable Clients are allowed to read files 1 \& Writable Clients are allowed to write files 0 \& BlkSize Minimum blocksize to negotiate for transfers 512 \& CallBack Reference to code executed for each transferred block \- \& Debug Activates debug mode (verbose) 0 \& Family Address family IPv4/IPv6 IPv4 \& Valid values for IPv4: \& 4, v4, ip4, ipv4, AF_INET (constant) \& Valid values for IPv6: \& 6, v6, ip6, ipv6, AF_INET6 (constant) \& V6Only Enable / disable v6only (see IO::Socket::IP) 1 .Ve .PP \&\fB\s-1NOTE\s0\fR: IPv6 requires \fBIO::Socket::IP\fR. Failback is \fBIO::Socket::INET\fR and only IPv4 support. .SS "CallBack" .IX Subsection "CallBack" The CallBack code is called by processRQ method for each tranferred block. .PP The code receives (into \f(CW@_\fR array) a reference to internal \fI\f(CI$request\fI\fR object. .PP Example: .PP .Vb 5 \& sub callback \& { \& my $req = shift; \& printf "block: %u\e/%u\en", $req\->{\*(Aq_REQUEST_\*(Aq}{\*(AqLASTACK\*(Aq}, $req\->{\*(Aq_REQUEST_\*(Aq}{\*(AqLASTBLK\*(Aq}; \& } \& \& my $tftpdOBJ = Net::TFTPd\->new(\*(AqRootDir\*(Aq => \*(Aqc:/temp\*(Aq, \*(AqTimeout\*(Aq => 60, \*(AqCallBack\*(Aq => \e&callback) or die Net::TFTPd\->error; .Ve .SH "Listener methods" .IX Header "Listener methods" .SS "\fBwaitRQ()\fP" .IX Subsection "waitRQ()" .Vb 1 \& $request = $listener\->waitRQ([Timeout]); .Ve .PP Waits for a client request (\s-1RRQ\s0 or \s-1WRQ\s0) and returns a \fI\f(CI$request\fI\fR object or \fIundef\fR if timed out. .PP If \fITimeout\fR is missing, the timeout defined for \fI\f(CI$listener\fI\fR object is used instead. .PP When the method returns, the program should \fBfork()\fR and process the request invoking \fBprocessRQ()\fR while the parent process should re-start waiting for another request. .SH "Request methods" .IX Header "Request methods" .SS "\fBprocessRQ()\fP" .IX Subsection "processRQ()" .Vb 1 \& $ret = $request\->processRQ(); .Ve .PP Processes a request and returns 1 if success, undef if error. .SS "\fBgetFileName()\fP" .IX Subsection "getFileName()" .Vb 1 \& $ret = $request\->getFileName(); .Ve .PP Returns the requested file name. .SS "\fBgetMode()\fP" .IX Subsection "getMode()" .Vb 1 \& $ret = $request\->getMode(); .Ve .PP Returns the transfer mode for the request. .SS "\fBgetBlkSize()\fP" .IX Subsection "getBlkSize()" .Vb 1 \& $ret = $request\->getBlkSize(); .Ve .PP Returns the block size used for the transfer. .SS "\fBserver()\fP" .IX Subsection "server()" .Vb 1 \& $ret = $request\->server(); .Ve .PP Return \fBIO::Socket::*\fR object for the created server. All \fBIO::Socket::*\fR accessors can then be called. .SS "\fBgetPeerAddr()\fP" .IX Subsection "getPeerAddr()" .Vb 1 \& $ret = $request\->getPeerAddr(); .Ve .PP Returns the address of the requesting client. .SS "\fBgetPeerPort()\fP" .IX Subsection "getPeerPort()" .Vb 1 \& $ret = $request\->getPeerMode(); .Ve .PP Returns the port of the requesting client. .SS "\fBgetTotalBytes()\fP" .IX Subsection "getTotalBytes()" .Vb 1 \& $ret = $request\->getTotalBytes(); .Ve .PP Returns the number of bytes transferred for the request. .SH "CREDITS" .IX Header "CREDITS" Thanks to Michael Vincent (<\s-1VINSWORLD\s0>) for the \s-1NETASCII\s0 support, transferred bytes and IPv6 patches. .SH "AUTHOR" .IX Header "AUTHOR" Luigino Masarati, .SH "SEE ALSO" .IX Header "SEE ALSO" Net::TFTP.