I need to parse a text file stream after downloading and without saving the text file to harddisk or sdcard using tftp protocol. I've the data in payload. Please help.
struct pbuf {
struct pbuf *next;
void *payload;
u16_t tot_len;
u16_t len;
u8_t type;
u8_t flags;
u16_t ref;
};
The following code assigns the opcode and filename. But how to get the contents of the file?
/* Extract the opcode from a TFTP message in a buffer */
tftp_opcode tftp_decode_op(char *buf)
{
return (tftp_opcode)(buf[1]);
}
void tftp_extract_filename(char *fname, char *buf)
{
strcpy(fname, buf + 2);
}
In the TFTP protocol, you first get a write request packet (opcode WRQ), and then the data in separate data packets (opcode DATA). You will need to do something whenever a data packet is received in order to process the contents of the file. I'd recommend reading up a bit on the TFTP protocol if you haven't done that yet. An overview is at http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol#Protocol_walkthrough and the spec (which is very readable) is at https://www.rfc-editor.org/rfc/rfc1350 .