File: TFTPd.html

package info (click to toggle)
libnet-tftpd-perl 0.06-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 140 kB
  • ctags: 63
  • sloc: perl: 939; makefile: 7
file content (280 lines) | stat: -rwxr-xr-x 17,362 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Net::TFTPd - Perl extension for Trivial File Transfer Protocol Server</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body style="background-color: white">
<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="block" style="background-color: #cccccc" valign="middle">
<big><strong><span class="block">&nbsp;Net::TFTPd - Perl extension for Trivial File Transfer Protocol Server</span></strong></big>
</td></tr>
</table>


<!-- INDEX BEGIN -->
<div name="index">
<p><a name="__index__"></a></p>

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#export">EXPORT</a></li>
	<ul>

		<li><a href="#_opcodes">%OPCODES</a></li>
	</ul>

	<li><a href="#listener_constructor">Listener constructor</a></li>
	<ul>

		<li><a href="#new__"><code>new()</code></a></li>
		<li><a href="#callback">CallBack</a></li>
	</ul>

	<li><a href="#listener_methods">Listener methods</a></li>
	<ul>

		<li><a href="#waitrq__"><code>waitRQ()</code></a></li>
	</ul>

	<li><a href="#request_methods">Request methods</a></li>
	<ul>

		<li><a href="#processrq__"><code>processRQ()</code></a></li>
		<li><a href="#getfilename__"><code>getFileName()</code></a></li>
		<li><a href="#getmode__"><code>getMode()</code></a></li>
		<li><a href="#getblksize__"><code>getBlkSize()</code></a></li>
		<li><a href="#server__"><code>server()</code></a></li>
		<li><a href="#getpeeraddr__"><code>getPeerAddr()</code></a></li>
		<li><a href="#getpeerport__"><code>getPeerPort()</code></a></li>
		<li><a href="#gettotalbytes__"><code>getTotalBytes()</code></a></li>
	</ul>

	<li><a href="#credits">CREDITS</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>

<hr name="index" />
</div>
<!-- INDEX END -->

<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Net::TFTPd - Perl extension for Trivial File Transfer Protocol Server</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  <span class="keyword">use</span> <span class="variable">strict</span><span class="operator">;</span>
  <span class="keyword">use</span> <span class="variable">Net::TFTPd</span><span class="operator">;</span>
</pre>
<pre>
  <span class="keyword">my</span> <span class="variable">$tftpdOBJ</span> <span class="operator">=</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">'RootDir'</span> <span class="operator">=&gt;</span> <span class="string">'path/to/files'</span><span class="operator">)</span>
    <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Error creating TFTPd listener: %s"</span><span class="operator">,</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">error</span><span class="operator">;</span>
</pre>
<pre>
  <span class="keyword">my</span> <span class="variable">$tftpRQ</span> <span class="operator">=</span> <span class="variable">$tftpdOBJ</span><span class="operator">-&gt;</span><span class="variable">waitRQ</span><span class="operator">(</span><span class="number">10</span><span class="operator">)</span>
    <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Error waiting for TFTP request: %s"</span><span class="operator">,</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">error</span><span class="operator">;</span>
</pre>
<pre>
  <span class="variable">$tftpRQ</span><span class="operator">-&gt;</span><span class="variable">processRQ</span><span class="operator">()</span>
    <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Error processing TFTP request: %s"</span><span class="operator">,</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">error</span><span class="operator">;</span>
</pre>
<pre>
  <span class="keyword">printf</span> <span class="string">"%u bytes has been transferred"</span><span class="operator">,</span> <span class="variable">$tftpRQ</span><span class="operator">-&gt;</span><span class="variable">getTotalBytes</span><span class="operator">()</span> <span class="operator">||</span> <span class="number">0</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p><code>Net::TFTPd</code> is a class implementing a simple <em>Trivial File Transfer Protocol</em> server in Perl as described in <a href="http://www.ietf.org/rfc/rfc1350.txt" class="rfc">RFC1350</a>.</p>
<p><code>Net::TFTPd</code> also supports the TFTP Option Extension (as described in <a href="http://www.ietf.org/rfc/rfc2347.txt" class="rfc">RFC2347</a>), with the following options:</p>
<pre>
  RFC2348 TFTP Blocksize Option
  RFC2349 TFTP Timeout Interval and Transfer Size Options</pre>
<p>
</p>
<hr />
<h1><a name="export">EXPORT</a></h1>
<p>None by default.</p>
<p>
</p>
<h2><a name="_opcodes">%OPCODES</a></h2>
<p>The %OPCODES tag exports the <em>%OPCODES</em> hash:</p>
<pre>
  <span class="variable">%OPCODES</span> <span class="operator">=</span> <span class="operator">(</span>
    <span class="number">1</span>       <span class="operator">=&gt;</span> <span class="string">'RRQ'</span><span class="operator">,</span>
    <span class="number">2</span>       <span class="operator">=&gt;</span> <span class="string">'WRQ'</span><span class="operator">,</span>
    <span class="number">3</span>       <span class="operator">=&gt;</span> <span class="string">'DATA'</span><span class="operator">,</span>
    <span class="number">4</span>       <span class="operator">=&gt;</span> <span class="string">'ACK'</span><span class="operator">,</span>
    <span class="number">5</span>       <span class="operator">=&gt;</span> <span class="string">'ERROR'</span><span class="operator">,</span>
    <span class="number">6</span>       <span class="operator">=&gt;</span> <span class="string">'OACK'</span><span class="operator">,</span>
    <span class="string">'RRQ'</span>   <span class="operator">=&gt;</span> <span class="number">1</span><span class="operator">,</span>
    <span class="string">'WRQ'</span>   <span class="operator">=&gt;</span> <span class="number">2</span><span class="operator">,</span>
    <span class="string">'DATA'</span>  <span class="operator">=&gt;</span> <span class="number">3</span><span class="operator">,</span>
    <span class="string">'ACK'</span>   <span class="operator">=&gt;</span> <span class="number">4</span><span class="operator">,</span>
    <span class="string">'ERROR'</span> <span class="operator">=&gt;</span> <span class="number">5</span><span class="operator">,</span>
    <span class="string">'OACK'</span>  <span class="operator">=&gt;</span> <span class="number">6</span>
  <span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="listener_constructor">Listener constructor</a></h1>
<p>
</p>
<h2><a name="new__"><code>new()</code></a></h2>
<pre>
  <span class="variable">$listener</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Net::TFTPd</span><span class="operator">(</span> <span class="operator">[</span><span class="string">'RootDir'</span> <span class="operator">=&gt;</span> <span class="string">'path/to/files'</span> <span class="operator">|</span> <span class="string">'FileName'</span> <span class="operator">=&gt;</span> <span class="string">'path/to/file'</span><span class="operator">]</span> <span class="operator">[</span><span class="operator">,</span> <span class="variable">OPTIONS</span> <span class="operator">]</span> <span class="operator">);</span>
</pre>
<p>or</p>
<pre>
  <span class="variable">$listener</span> <span class="operator">=</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span> <span class="operator">[</span><span class="string">'RootDir'</span> <span class="operator">=&gt;</span> <span class="string">'path/to/files'</span> <span class="operator">|</span> <span class="string">'FileName'</span> <span class="operator">=&gt;</span> <span class="string">'path/to/file'</span><span class="operator">]</span> <span class="operator">[</span><span class="operator">,</span> <span class="variable">OPTIONS</span> <span class="operator">]</span> <span class="operator">);</span>
</pre>
<p>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 OPTIONS are the default server
options.</p>
<p>Valid options are:</p>
<pre>
  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)</pre>
<p><strong>NOTE</strong>:  IPv6 requires <strong>IO::Socket::IP</strong>.  Failback is <strong>IO::Socket::INET</strong> 
and only IPv4 support.</p>
<p>
</p>
<h2><a name="callback">CallBack</a></h2>
<p>The CallBack code is called by processRQ method for each tranferred block.</p>
<p>The code receives (into @_ array) a reference to internal <em>$request</em> object.</p>
<p>Example:</p>
<pre>
  <span class="keyword">sub</span><span class="variable"> callback
  </span><span class="operator">{</span>
    <span class="keyword">my</span> <span class="variable">$req</span> <span class="operator">=</span> <span class="keyword">shift</span><span class="operator">;</span>
    <span class="keyword">printf</span> <span class="string">"block: %u\/%u\n"</span><span class="operator">,</span> <span class="variable">$req</span><span class="operator">-&gt;</span><span class="operator">{</span><span class="string">'_REQUEST_'</span><span class="operator">}{</span><span class="string">'LASTACK'</span><span class="operator">}</span><span class="operator">,</span> <span class="variable">$req</span><span class="operator">-&gt;</span><span class="operator">{</span><span class="string">'_REQUEST_'</span><span class="operator">}{</span><span class="string">'LASTBLK'</span><span class="operator">}</span><span class="operator">;</span>
  <span class="operator">}</span>
</pre>
<pre>
  <span class="keyword">my</span> <span class="variable">$tftpdOBJ</span> <span class="operator">=</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">'RootDir'</span> <span class="operator">=&gt;</span> <span class="string">'c:/temp'</span><span class="operator">,</span> <span class="string">'Timeout'</span> <span class="operator">=&gt;</span> <span class="number">60</span><span class="operator">,</span> <span class="string">'CallBack'</span> <span class="operator">=&gt;</span> <span class="operator">\&amp;</span><span class="variable">callback</span><span class="operator">)</span> <span class="keyword">or</span> <span class="keyword">die</span> <span class="variable">Net::TFTPd</span><span class="operator">-&gt;</span><span class="variable">error</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="listener_methods">Listener methods</a></h1>
<p>
</p>
<h2><a name="waitrq__"><code>waitRQ()</code></a></h2>
<pre>
  <span class="variable">$request</span> <span class="operator">=</span> <span class="variable">$listener</span><span class="operator">-&gt;</span><span class="variable">waitRQ</span><span class="operator">(</span><span class="operator">[</span><span class="variable">Timeout</span><span class="operator">]</span><span class="operator">);</span>
</pre>
<p>Waits for a client request (RRQ or WRQ) and returns a <em>$request</em> object or <em>undef</em> if timed out.</p>
<p>If <em>Timeout</em> is missing, the timeout defined for <em>$listener</em> object is used instead.</p>
<p>When the method returns, the program should <code>fork()</code> and process the request invoking <code>processRQ()</code> while the parent process should re-start waiting for another request.</p>
<p>
</p>
<hr />
<h1><a name="request_methods">Request methods</a></h1>
<p>
</p>
<h2><a name="processrq__"><code>processRQ()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">processRQ</span><span class="operator">();</span>
</pre>
<p>Processes a request and returns 1 if success, undef if error.</p>
<p>
</p>
<h2><a name="getfilename__"><code>getFileName()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">getFileName</span><span class="operator">();</span>
</pre>
<p>Returns the requested file name.</p>
<p>
</p>
<h2><a name="getmode__"><code>getMode()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">getMode</span><span class="operator">();</span>
</pre>
<p>Returns the transfer mode for the request.</p>
<p>
</p>
<h2><a name="getblksize__"><code>getBlkSize()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">getBlkSize</span><span class="operator">();</span>
</pre>
<p>Returns the block size used for the transfer.</p>
<p>
</p>
<h2><a name="server__"><code>server()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">server</span><span class="operator">();</span>
</pre>
<p>Return <strong>IO::Socket::*</strong> object for the created server.  
All <strong>IO::Socket::*</strong> accessors can then be called.</p>
<p>
</p>
<h2><a name="getpeeraddr__"><code>getPeerAddr()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">getPeerAddr</span><span class="operator">();</span>
</pre>
<p>Returns the address of the requesting client.</p>
<p>
</p>
<h2><a name="getpeerport__"><code>getPeerPort()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">getPeerMode</span><span class="operator">();</span>
</pre>
<p>Returns the port of the requesting client.</p>
<p>
</p>
<h2><a name="gettotalbytes__"><code>getTotalBytes()</code></a></h2>
<pre>
  <span class="variable">$ret</span> <span class="operator">=</span> <span class="variable">$request</span><span class="operator">-&gt;</span><span class="variable">getTotalBytes</span><span class="operator">();</span>
</pre>
<p>Returns the number of bytes transferred for the request.</p>
<p>
</p>
<hr />
<h1><a name="credits">CREDITS</a></h1>
<p>Thanks to Michael Vincent (&lt;VINSWORLD&gt;) for the NETASCII support, transferred bytes and IPv6 patches.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Luigino Masarati, &lt;<a href="mailto:lmasarati@hotmail.com">lmasarati@hotmail.com</a>&gt;</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="/Net/TFTP.html">the Net::TFTP manpage</a>.</p>
<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="block" style="background-color: #cccccc" valign="middle">
<big><strong><span class="block">&nbsp;Net::TFTPd - Perl extension for Trivial File Transfer Protocol Server</span></strong></big>
</td></tr>
</table>

</body>

</html>