lib-tftp-server icon indicating copy to clipboard operation
lib-tftp-server copied to clipboard

TFTP server implemetation in C++ : Boost.ASIO + Boost.Spirit Based, header only and trivial.

lib-tftp-server

I had to automate the flashing process of an embedded device, basically : read/write to a serial console to configure a bootloader to load our NAND image from TFTP and flash it down. But there was no clean, modern C++, header only, moderate in terms of dependencies implementation of a library to launch Trivial File Transfer Protocol server ( c.f. RFC 1350 ) implementation.

So the idea with this server, is to provide other people in a need similar to mine with a simple tftp server that they can start from their application as a library.

TFTP Support

This server isn't a fully complete implementation of TFTP, but is a quite trivial sufficient solution as it doesn't implements the strange things you don't need, see ( c.f. RFC 1350 for the strange beast like netascii encoding and mail forwarding.

Supported Features:

  • Supports Read Requests (RRQ, Download) of type octet/binary
  • Supports Data and ACK for files in the work dir of the application
  • TFTP Options extension as specified in RFC2347, RFC2348, RFC2349.

Easy-to-implement to be RFC1350 compliant: I welcome pull-requests or forks, as the code is small and the following might be implemented fast.

  • Support for Write Requests (WRQ, Upload) of type octet/binary : may be added in 15 lines of code.
  • Support for netascii transfers (I don't see why one would want this, as most clients like barebox doesn't even support them, as it requires further processing of bytes stream)
  • Support for resending unacked packet instead of aborting transfer

How to use it ?

Compiling

If you want to compile the demo tftp-server executable you can simply do the following :

Dependencies

It only requires you to have Boost installed on your system :

sudo apt-get install libboost-1.55-all libboost-1.55-dev

Build

mkdir build/
cd build/ && cmake ..
make

And then you to run a tftp-server on port 6565 you can run :

build/src/tftp-server 6565

To query it with a tftp client, like tftp on linux, do :

sudo apt-get install tftp
tftp 
tftp> connect 127.0.0.1 6565
tftp> binary
tftp> get file

Reusing the library and starting it within your app

It's header only so you simply have to include the folder src/ and then link to boost_system, boost_filesystem.

To ease reuse I don't distribute a cmake package config file for the moment, however you can using make install to install the headers.

Additionally integrating it in your code simply requires the same as in src/main.cpp :

#include <boost/asio.hpp>
#include <tftp/server.hpp>

boost::asio::io_service io_service;
tftp::server s(io_service, 69);
io_service.run();

License

Copyright (c) 2015 Damien Buhl (alias daminetreg)

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)