TTFTP Project

by: burt rosenberg
at: university of miami


The original best-effort, packetized data delivery

The Truly Trivial File Transfer Project

The Truly Trivial File Transfer Protocol is a simplification of the Internet standard Trivial File Transfer Protocol (TFTP), defined in 1981 by RFC 783, and updated in RFC 1350.

Specific Objectives

Man Page



NAME
    ttftp, ttfptd
    
SYNOPSIS
    ttftp [-v] hostname:port filename
    ttftpd [-vL] port
    
DESCRIPTION
    Implements the tftp protocol. The ttftp client program is called to read the named
    file from the named host at the optionally specified port. Only client reads are
    supported. The client writes the received bytes to standard out.
    
    The ttftpd program listens on the optionally specified port for read requests. It
    can be multithreaded to handle simultaneous requests, or optionally handle one 
    request and exit.

    The server implements basic security by requiring that filename is in the current
    directory and is world readable. Else an error is returned.
    
    Only OCTET mode is supported. All over requests generate an error responses.
    
OPTIONS
    -L Server does not loop. Handle one read request and exit.
    -v Verbose. Helpful debugging output to stdout. 
 
NOTES
    Implement only octet and only read. If requested return an error packet with 
    message "mode not supported". 
    
    Resend requests on timeout generated only by the client. Server implements required
    anti-sorcerer's apprentice bug fix.
    
    Maximum filename length is 256 characters, and cannot contain a pathname. 

HISTORY
    First introduced in Fall 2003. Made Truly Trivial in Spring 2015.
    Updated interface for Spring 2022, required multi-threaded behavior.

LAST UPDATED 
    March 2, 2022.
	

Detailed description

Please read TFTP RFC 1350.

Write the client (ttftp) and server (ttftpd) implemeting the Truely Trivial File transfer Protocol (TTFTP). Truly Trivial is a restriction on the internet standard Trivial File Transfer Protocol (TFTP) that captures the main ideas but does not require full compliance and services according to the standard.

However the TID's must be implemented, and multiple simultaneous requests should be supported. Also required is the fix for the anti-sorcerer's syndrome.

Installing a standard TFTP client and server

It may help you to have a standard TFTP client/server on your machine, so that you fully understand how TFTP is supposed to work, and have a standard client/server to test against. TTFTP is compatible with TFTP and you should be able to work with the installed server against your client, and the installed client against your server.

To install,

sudo apt-get install tftp tftpd-hpa
sudo systemctl status tftpd-hpa
The systemctl is an interface to systemD which controls services started on the platform. The status request checks that the tftpd is running. The default installation, as shown, is for read only. Look at in the file /etc/default/tftpd-hpa for the root directory of the tftp deamon (typically /src/tftpboot)

Protocol walk-through

Please refer to a tcpdump trace for an actual packet trace of this protocol.

The box on the right is a packet trace using the tftpd-hpa tftp deamon and the tftp client. The tftp client was asked to read the file eecummings.txt.

$ sudo tcpdump -i lo -X udp
18:44:39.513948 IP localhost.59728 > localhost.tftp: 26 RRQ "eecummings.txt" netascii
	0x0000:  4500 0036 daf3 4000 4011 61c1 7f00 0001  E..6..@.@.a.....
	0x0010:  7f00 0001 e950 0045 0022 fe35 0001 6565  .....P.E.".5..ee
	0x0020:  6375 6d6d 696e 6773 2e74 7874 006e 6574  cummings.txt.net
	0x0030:  6173 6369 6900                           ascii.
18:44:39.515122 IP localhost.45978 > localhost.59728: UDP, length 516
	0x0000:  4500 0220 daf4 0000 4011 9fd6 7f00 0001  E.......@.......
	0x0010:  7f00 0001 b39a e950 020c 0020 0003 0001  .......P........
	0x0020:  616e 796f 6e65 206c 6976 6564 2069 6e20  anyone.lived.in.
	0x0030:  6120 7072 6574 7479 2068 6f77 2074 6f77  a.pretty.how.tow
	0x0040:  6e0d 0a28 7769 7468 2075 7020 736f 2066  n..(with.up.so.f
	0x0050:  6c6f 6174 696e 6720 6d61 6e79 2062 656c  loating.many.bel
	0x0060:  6c73 2064 6f77 6e29 0d0a 7370 7269 6e67  ls.down)..spring
	0x0070:  2073 756d 6d65 7220 6175 7475 6d6e 2077  .summer.autumn.w
	0x0080:  696e 7465 720d 0a68 6520 7361 6e67 2068  inter..he.sang.h
	0x0090:  6973 2064 6964 6e27 7420 6865 2064 616e  is.didn't.he.dan
	0x00a0:  6365 6420 6869 7320 6469 642e 0d0a 0d0a  ced.his.did.....
	0x00b0:  576f 6d65 6e20 616e 6420 6d65 6e28 626f  Women.and.men(bo
	0x00c0:  7468 206c 6974 746c 6520 616e 6420 736d  th.little.and.sm
	0x00d0:  616c 6c29 0d0a 6361 7265 6420 666f 7220  all)..cared.for.
	0x00e0:  616e 796f 6e65 206e 6f74 2061 7420 616c  anyone.not.at.al
	0x00f0:  6c0d 0a74 6865 7920 736f 7765 6420 7468  l..they.sowed.th
	0x0100:  6569 7220 6973 6e27 7420 7468 6579 2072  eir.isn't.they.r
	0x0110:  6561 7065 6420 7468 6569 7220 7361 6d65  eaped.their.same
	0x0120:  0d0a 7375 6e20 6d6f 6f6e 2073 7461 7273  ..sun.moon.stars
	0x0130:  2072 6169 6e0d 0a0d 0a63 6869 6c64 7265  .rain....childre
	0x0140:  6e20 6775 6573 7365 6428 6275 7420 6f6e  n.guessed(but.on
	0x0150:  6c79 2061 2066 6577 0d0a 616e 6420 646f  ly.a.few..and.do
	0x0160:  776e 2074 6865 7920 666f 7267 6f74 2061  wn.they.forgot.a
	0x0170:  7320 7570 2074 6865 7920 6772 6577 0d0a  s.up.they.grew..
	0x0180:  6175 7475 6d6e 2077 696e 7465 7220 7370  autumn.winter.sp
	0x0190:  7269 6e67 2073 756d 6d65 7229 0d0a 7468  ring.summer)..th
	0x01a0:  6174 206e 6f6f 6e65 206c 6f76 6564 2068  at.noone.loved.h
	0x01b0:  696d 206d 6f72 6520 6279 206d 6f72 650d  im.more.by.more.
	0x01c0:  0a0d 0a77 6865 6e20 6279 206e 6f77 2061  ...when.by.now.a
	0x01d0:  6e64 2074 7265 6520 6279 206c 6561 660d  nd.tree.by.leaf.
	0x01e0:  0a73 6865 206c 6175 6768 6564 2068 6973  .she.laughed.his
	0x01f0:  206a 6f79 2073 6865 2063 7269 6564 2068  .joy.she.cried.h
	0x0200:  6973 2067 7269 6566 0d0a 6269 7264 2062  is.grief..bird.b
	0x0210:  7920 736e 6f77 2061 6e64 2073 7469 7220  y.snow.and.stir.
18:44:39.515706 IP localhost.59728 > localhost.45978: UDP, length 4
	0x0000:  4500 0020 daf5 4000 4011 61d5 7f00 0001  E.....@.@.a.....
	0x0010:  7f00 0001 e950 b39a 000c fe1f 0004 0001  .....P..........
18:44:39.515727 IP localhost.45978 > localhost.59728: UDP, length 198
	0x0000:  4500 00e2 daf6 0000 4011 a112 7f00 0001  E.......@.......
	0x0010:  7f00 0001 b39a e950 00ce fee1 0003 0002  .......P........
	0x0020:  6279 2073 7469 6c6c 0d0a 616e 796f 6e65  by.still..anyone
	0x0030:  2773 2061 6e79 2077 6173 2061 6c6c 2074  's.any.was.all.t
	0x0040:  6f20 6865 720d 0a0d 0a73 6f6d 656f 6e65  o.her....someone
	0x0050:  7320 6d61 7272 6965 6420 7468 6569 7220  s.married.their.
	0x0060:  6576 6572 796f 6e65 730d 0a6c 6175 6768  everyones..laugh
	0x0070:  6564 2074 6865 6972 2063 7279 696e 6773  ed.their.cryings
	0x0080:  2061 6e64 2064 6964 2074 6865 6972 2064  .and.did.their.d
	0x0090:  616e 6365 0d0a 2873 6c65 6570 2077 616b  ance..(sleep.wak
	0x00a0:  6520 686f 7065 2061 6e64 2074 6865 6e29  e.hope.and.then)
	0x00b0:  7468 6579 0d0a 7361 6964 2074 6865 6972  they..said.their
	0x00c0:  206e 6576 6572 7320 7468 6579 2073 6c65  .nevers.they.sle
	0x00d0:  7074 2074 6865 6972 2064 7265 616d 0d0a  pt.their.dream..
	0x00e0:  0d0a                                     ..
18:44:39.516115 IP localhost.59728 > localhost.45978: UDP, length 4
	0x0000:  4500 0020 daf7 4000 4011 61d3 7f00 0001  E.....@.@.a.....
	0x0010:  7f00 0001 e950 b39a 000c fe1f 0004 0002  .....P..........
  1. The first packet is from the client port 59728 to the wellknown port 69. The port numbers are part of the UDP header, not the TFTP protocol packet; but are shown anyway, in purple.
  2. Since the first packet is an RRQ, its operation code is 1, colored in green. Following is the file name terminated with a null byte, followed by the mode "netascii", spelled out, terminated with a null byte.
  3. TID's are chosen. The client side has already chosen port 59728. The response to the RRQ packet is a DATA packet from port 45978. The port numbers are highlighted in purple. The DATA packet op code is 3, highlighted in green. This is the first block, so the block number is 1 highlighted in blue.
  4. The client responds to the DATA packet with a simple ACK packet. The ACK op code is 4, highlighted in green, and the block number is 1, highlighted in blue.
  5. The server responds to the ACK with DATA packet 2. The op code and block number fields are highlighted as before.
  6. The client responds to DATA packet 2 with ACK with block number 2. The op code and block number fields are highlighted as before.
  7. Because DATA block 2 had less then 512 bytes of data, the client knows that there is no more data and exits after the ACK. The server will linger until it receives ACK 2 and then exists.

Implementation notes and restrictions

Note the restrictions mentioned in the manpage: only RRQ for OCTET data is supported; and the read file must be in the current server directory and world-readable.

Do not implement timeouts and retransmission.

The network is big endian. Intel is little endian. Program accordingly.

Your program must inter-operate with any other correct implementation of TTFTP.

Do not assume the file transfered is text; do not assume nulls terminate byte buffers; do not assume just because it is written to standard out the characters are printable.

Do not crash because of bad inputs. Never trust inputs from the network. It is not excusable that an error surprises your code, and your code crashes. If you want to bail out on bad data, in this class you are free to use an assertion, although user friendly code might handle the error more gracefully.

Be consistent with the RFC in handling of all errrors. Check the TID of the sender and send a non-terminating error, are directed in the RFC. All other errors send a terminating error with correct error number. Refer to the statment "receiving a packet which cannot be explained by a delay or duplication in the network" for the definition of what is an error.

Read about the Sorcerer's Apprentice Syndrome. You will not do timeouts or retransmissions in this version of the project, but be familiar with the issue as you code.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Author: Burton Rosenberg
Created: January 18, 2014 as mytftp
Last Update: 5 March 2022