TFTP数据包

TFTP data packet

我需要用C++将一个大文件中的所有数据写入TFTP数据包(512字节)。我知道在客户端和服务器之间成功传输文件需要满足以下条件。

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  |

如何以最简单的方式在 C++ 中生成这样的数据包协议(即指定 headers 和操作码)? 我在网上到处搜索,找不到有用的 C++ 或 C 解决方案。另外,我应该使用 UDP 吗?

你或许可以看看:

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

tftp 协议的服务器和客户端部分有一个小的实现。它是用 C 语言编写的,但对于您的使用来说似乎还可以。

提示:这里请求 "search a library" 是题外话!