Search code examples
c++ctftp

TFTP data packet


I need to write all data from a file of a large size into TFTP data packets(512 bytes) in C++. I am aware that the following criteria is required for successful file transmission between a client and server.

TFTP supports five types of packets, all of which have been mentioned below:

opcode  operation
1     Read request (RRQ)
2     Write request (WRQ)
3     Data (DATA)
4     Acknowledgment (ACK)
5     Error (ERROR)

The TFTP header of a packet contains the opcode associated with that packet.

2 bytes     string    1 byte     string   1 byte
------------------------------------------------
| Opcode |  Filename  |   0  |    Mode    |   0  |

How can I generate such a packet protocol(i.e. specify headers and opcodes) in C++ in the simplest way possible? I have searched everywhere online and cannot find a helpful solution in C++ or C. Also, should I use UDP?


Solution

  • You maybe can take a look at:

    http://sourceforge.net/projects/tftp/

    There is a small implementation of server and client part of the tftp protocol. It is written in C but for your usage it seems ok.

    Hint: Requesting for "search a library" here is off topic!