update tftp client code (tftp_put).
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@140 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
3c41a849a8
commit
5f878bb6a2
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue