Display size of uploaded firmware file

This commit is contained in:
Joseph C. Lehner 2021-05-31 17:58:41 +02:00
parent dcedf37624
commit a2267b7351
3 changed files with 13 additions and 8 deletions

11
nmrp.c
View file

@ -358,6 +358,7 @@ int nmrp_do(struct nmrpd_args *args)
char *filename;
time_t beg;
int i, timeout, status, ulreqs, expect, upload_ok, autoip, ka_reqs, fake;
ssize_t bytes;
struct ethsock *sock;
struct ethsock_ip_undo *ip_undo = NULL;
struct ethsock_arp_undo *arp_undo = NULL;
@ -635,6 +636,8 @@ int nmrp_do(struct nmrpd_args *args)
status = system(args->tftpcmd);
}
bytes = 0;
if (!status && args->file_local) {
if (!autoip) {
status = is_valid_ip(sock, &ipaddr, &ipmask);
@ -659,13 +662,13 @@ int nmrp_do(struct nmrpd_args *args)
printf("Uploading %s ... ", leafname(args->file_local));
}
fflush(stdout);
if (!(status = tftp_put(args))) {
printf("OK\n");
}
bytes = tftp_put(args);
}
if (!status) {
if (bytes > 0) {
printf("OK (%zi b)\n", bytes);
if (args->blind) {
goto out;
}

View file

@ -104,7 +104,7 @@ struct nmrpd_args {
};
const char *leafname(const char *path);
int tftp_put(struct nmrpd_args *args);
ssize_t tftp_put(struct nmrpd_args *args);
bool tftp_is_valid_filename(const char *filename);
int nmrp_do(struct nmrpd_args *args);

8
tftp.c
View file

@ -319,11 +319,11 @@ inline bool tftp_is_valid_filename(const char *filename)
static const char *spinner = "\\|/-";
int tftp_put(struct nmrpd_args *args)
ssize_t tftp_put(struct nmrpd_args *args)
{
struct sockaddr_in addr;
uint16_t block, port, op, blksize;
ssize_t len, last_len;
ssize_t len, last_len, bytes;
int fd, sock, ret, timeouts, errors, ackblock;
char rx[2048], tx[2048];
const char *file_remote = args->file_remote;
@ -410,6 +410,7 @@ int tftp_put(struct nmrpd_args *args)
block = 0;
last_len = -1;
len = 0;
bytes = 0;
errors = 0;
rollover = false;
/* Not really, but this way the loop sends our WRQ before receiving */
@ -468,6 +469,7 @@ int tftp_put(struct nmrpd_args *args)
}
last_len = len;
bytes += len;
}
ret = tftp_sendto(sock, tx, len, &addr);
@ -537,5 +539,5 @@ cleanup:
#endif
}
return ret;
return (ret == 0) ? bytes : ret;
}