Skip to content
Advertisement

Tftp commands implementation to fetch remote data in a local ring buffer

I was looking for an implementation using tftp command sets which can fetch data from a remote server but instead getting data completely as a whole, it fetches the data in a local ring buffer of size lesser than the remote file size and it overwrites the data after the ring has been circled. So, if any process uses the data during the time data is available, it succeeds otherwise it loses the data. For example, say I have a 100 MB of data in a remote file and (want to create?) ring buffer of 10 MB size locally. So, it fetches the remote data and puts it into the ring buffer. After the 10 MB is circled, it starts overwriting. Any suggestion will be highly appreciated. Thanks in advance.

Advertisement

Answer

As you are using Linux, data will reach your tftp client via a Linux socket. Ordinarily, you would call read on this socket to get data.

However, if you want to use a ring buffer you can simply set the socket option PACKET_RX_RING and read from a memory mapped address space (available in Linux 2.4/2.6/3.x according to the packet_mmap documentation) instead of calling read. There is no need to implement a ring buffer yourself.

Sample code is available from the Wiki linked there, from a related Stack Overflow question, or from various websites.

Advertisement