From 5f878bb6a29ef3acd3087edd24992cfb9997d66f Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Mon, 26 Oct 2009 06:02:07 +0000 Subject: [PATCH] update tftp client code (tftp_put). git-svn-id: https://rt-thread.googlecode.com/svn/trunk@140 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- net/apps/tftp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/net/apps/tftp.c b/net/apps/tftp.c index 2a0e385533..a2d3525bfa 100644 --- a/net/apps/tftp.c +++ b/net/apps/tftp.c @@ -146,22 +146,34 @@ void tftp_put(const char* host, const char* filename) do { + rt_uint16_t *ptr; + ptr = (rt_uint16_t*)&tftp_buffer[0]; + length = read(fd, &tftp_buffer[4], 512); if (length > 0) { /* make opcode and block number */ - tftp_buffer[0] = 0; tftp_buffer[1] = TFTP_DATA; - tftp_buffer[2] = block_number ; tftp_buffer[3] = block_number; + *ptr = TFTP_DATA; *(ptr + 1) = block_number; lwip_sendto(sock_fd, tftp_buffer, length + 4, 0, - (struct sockaddr *)&from_addr, fromlen); + (struct sockaddr *)&tftp_addr, fromlen); } + else break; /* no data yet */ /* receive ack */ length = lwip_recvfrom(sock_fd, tftp_buffer, sizeof(tftp_buffer), 0, (struct sockaddr *)&from_addr, &fromlen); if (length > 0) { + if (*ptr == TFTP_ACK && *(ptr + 1) == block_number) + { + block_number ++; + } + else + { + rt_kprintf("server respondes with an error\n"); + break; + } } } while (length != 516);