projects
/
oweals
/
nmrpflash.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update README.md
[oweals/nmrpflash.git]
/
tftp.c
diff --git
a/tftp.c
b/tftp.c
index de8f765d010214cb3727d52892cabe2d2593e52d..735f992e36e635379c180087657e489b88c8a9c7 100644
(file)
--- a/
tftp.c
+++ b/
tftp.c
@@
-305,6
+305,8
@@
inline bool tftp_is_valid_filename(const char *filename)
return strlen(filename) <= 255 && is_netascii(filename);
}
return strlen(filename) <= 255 && is_netascii(filename);
}
+static const char *spinner = "\\|/-";
+
int tftp_put(struct nmrpd_args *args)
{
struct sockaddr_in addr;
int tftp_put(struct nmrpd_args *args)
{
struct sockaddr_in addr;
@@
-314,6
+316,9
@@
int tftp_put(struct nmrpd_args *args)
char rx[2048], tx[2048];
const char *file_remote = args->file_remote;
char *val, *end;
char rx[2048], tx[2048];
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;
sock = -1;
ret = -1;
@@
-366,6
+371,7
@@
int tftp_put(struct nmrpd_args *args)
xperror("inet_addr");
goto cleanup;
}
xperror("inet_addr");
goto cleanup;
}
+
addr.sin_port = htons(args->port);
blksize = 512;
addr.sin_port = htons(args->port);
blksize = 512;
@@
-373,6
+379,7
@@
int tftp_put(struct nmrpd_args *args)
last_len = -1;
len = 0;
errors = 0;
last_len = -1;
len = 0;
errors = 0;
+ rollover = false;
/* Not really, but this way the loop sends our WRQ before receiving */
timeouts = 1;
/* Not really, but this way the loop sends our WRQ before receiving */
timeouts = 1;
@@
-394,14
+401,26
@@
int tftp_put(struct nmrpd_args *args)
ret = -1;
goto cleanup;
}
ret = -1;
goto cleanup;
}
+
+ if (verbosity) {
+ printf("Remote accepted blksize option: %d b\n", blksize);
+ }
}
}
}
if (timeouts || ackblock == block) {
if (!timeouts) {
}
}
}
if (timeouts || ackblock == block) {
if (!timeouts) {
- // TODO: set block to 1 if ++block == 0 ?
- ++block;
+ if (++block == 0) {
+ if (!rollover) {
+ printf("Warning: TFTP block rollover. Upload might fail!\n");
+ rollover = true;
+ }
+ }
+
+ printf("%c ", spinner[block & 3]);
+ fflush(stdout);
+ printf("\b\b");
pkt_mknum(tx, DATA);
pkt_mknum(tx + 2, block);
pkt_mknum(tx, DATA);
pkt_mknum(tx + 2, block);
@@
-437,11
+456,17
@@
int tftp_put(struct nmrpd_args *args)
}
}
}
}
- 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 (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);
continue;
} else if (block) {
fprintf(stderr, "Timeout while waiting for ACK(%d).\n", block);