static void pkt_mkwrq(char *pkt, const char *filename, unsigned blksize)
{
- size_t len = 2;
-
filename = leafname(filename);
if (!tftp_is_valid_filename(filename)) {
fprintf(stderr, "Overlong/illegal filename; using 'firmware'.\n");
struct sockaddr_in addr;
uint16_t block, port, op, blksize;
ssize_t len, last_len;
- int fd, sock, ret, timeout, errors, ackblock;
+ int fd, sock, ret, timeouts, errors, ackblock;
char rx[2048], tx[2048];
const char *file_remote = args->file_remote;
char *val, *end;
len = 0;
errors = 0;
/* Not really, but this way the loop sends our WRQ before receiving */
- timeout = 1;
+ timeouts = 1;
pkt_mkwrq(tx, file_remote, TFTP_BLKSIZE);
ackblock = -1;
op = pkt_num(rx);
- if (!timeout) {
+ if (!timeouts) {
if (op == ACK) {
ackblock = pkt_num(rx + 2);
} else if (op == OACK) {
}
}
- if (timeout || ackblock == block) {
- if (!timeout) {
+ if (timeouts || ackblock == block) {
+ if (!timeouts) {
++block;
pkt_mknum(tx, DATA);
pkt_mknum(tx + 2, block);
}
}
- ret = tftp_recvfrom(sock, rx, &port, args->rx_timeout, blksize + 2);
+ ret = tftp_recvfrom(sock, rx, &port, args->rx_timeout, blksize + 4);
if (ret < 0) {
goto cleanup;
} else if (!ret) {
- if (++timeout < 5 || (!block && timeout < 10)) {
+ if (++timeouts < 5 || (!block && timeouts < 10)) {
continue;
} else if (block) {
fprintf(stderr, "Timeout while waiting for ACK(%d).\n", block);
ret = -1;
goto cleanup;
} else {
- timeout = 0;
+ timeouts = 0;
ret = 0;
if (!block && port != args->port) {