0

I'm looking for an example of an TFTP client running on Linux platform. I'm trying do this problem using boost::asio here's the code:

void packi16 (char *buf, unsigned short int i){   //change the host order to network byte order (16bit)
i = htons(i);
memcpy(buf,&i,2);
}

int main()
{
boost::asio::io_service service;
boost::asio::ip::udp::socket sock(service);
sock.open(boost::asio::ip::udp::v4());
boost::asio::ip::udp::endpoint receiver_ep(boost::asio::ip::address::from_string("127.0.0.1"), 69);
char filename[] = "first";
char mode[] = "netascii";
int filename_size = (sizeof(filename)/sizeof(*filename));
int mode_size = (sizeof(mode)/sizeof(*mode));
char *packet;
packet = (char *)malloc((17)*sizeof(char));
packi16(packet,1); // 1 opcode for read request
memcpy(packet+2,filename,filename_size-1);
memset(packet+1+filename_size, '\0', 1);
memcpy(packet+2+filename_size, mode, mode_size-1);
memset(packet+1+filename_size+mode_size, '\0', 1);
sock.send_to(boost::asio::buffer(packet, 17), receiver_ep);
char buff[512];
boost::asio::ip::udp::endpoint sender_ep;
sock.receive_from(boost::asio::buffer(buff), sender_ep);
std::cout << buff;
return 0;
}

The problem is in program no error but code don't print anything although in the TFTP server i have this file : first. I use sniffer (wireshark) for see what's going on in my request packet, i capture packet made in tftp client in ubuntu then capture my program capture and it seems my program build correct packet.

Thanks m.s., Prabhu for your comments.

Astein
  • 1
  • 2
  • 3
    If you want to implement a TFTP client, you need to send [TFTP requests](http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol#Details) instead of GET requests. You can also have a look at this [TFTP server implemenation using boost::asio](https://github.com/daminetreg/lib-tftp-server). – m.s. May 25 '15 at 13:47
  • Why is there a request like GET like request? Shouldn't it be `READ REQUEST`? The buffer should contain - `opcode`, `source file` and the `file type` – Prabhu May 25 '15 at 13:47

0 Answers0