return strlen(filename) <= 255 && is_netascii(filename);
}
+static const char *spinner = "\\|/-";
+
int tftp_put(struct nmrpd_args *args)
{
struct sockaddr_in addr;
const char *file_remote = args->file_remote;
char *val, *end;
bool rollover;
+ const unsigned rx_timeout = MAX(args->rx_timeout / (args->blind ? 50 : 5), 2000);
+ const unsigned max_timeouts = args->blind ? 3 : 5;
sock = -1;
ret = -1;
xperror("inet_addr");
goto cleanup;
}
+
addr.sin_port = htons(args->port);
blksize = 512;
}
}
+ printf("%c ", spinner[block & 3]);
+ fflush(stdout);
+ printf("\b\b");
+
pkt_mknum(tx, DATA);
pkt_mknum(tx + 2, block);
len = read(fd, tx + 4, blksize);
}
}
- ret = tftp_recvfrom(sock, rx, &port, args->rx_timeout, blksize + 4);
+ ret = tftp_recvfrom(sock, rx, &port, rx_timeout, blksize + 4);
if (ret < 0) {
goto cleanup;
} else if (!ret) {
- if (++timeouts < 5 || (!block && timeouts < 10)) {
+ if (++timeouts < max_timeouts || (!block && timeouts < (max_timeouts * 4))) {
+ continue;
+ } else if (args->blind) {
+ timeouts = 0;
+ // fake an ACK packet
+ pkt_mknum(rx, ACK);
+ pkt_mknum(rx + 2, block);
continue;
} else if (block) {
fprintf(stderr, "Timeout while waiting for ACK(%d).\n", block);