From: Joseph C. Lehner Date: Mon, 2 Mar 2020 07:45:21 +0000 (+0100) Subject: Change select_fd args to microseconds X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=30a2f28f1abc60d0c988fe8498313c8f29adbdb0;p=oweals%2Fnmrpflash.git Change select_fd args to microseconds --- diff --git a/ethsock.c b/ethsock.c index 838f6bf..b346ce9 100644 --- a/ethsock.c +++ b/ethsock.c @@ -640,8 +640,8 @@ int select_fd(int fd, unsigned timeout) FD_ZERO(&fds); FD_SET(fd, &fds); - tv.tv_sec = timeout / 1000; - tv.tv_usec = 1000 * (timeout % 1000); + tv.tv_sec = timeout / 1000000; + tv.tv_usec = timeout % 1000000; status = select(fd + 1, &fds, NULL, NULL, &tv); if (status < 0) { diff --git a/main.c b/main.c index 6dda5e8..242e7be 100644 --- a/main.c +++ b/main.c @@ -33,14 +33,14 @@ void usage(FILE *fp) "Options (-i, -f and/or -c are mandatory):\n" " -a IP address to assign to target device\n" " -A IP address to assign to seleted interface\n" - " -B Blind mode (don't wait for NMRP responses)\n" + " -B Blind mode (don't wait for response packets)\n" " -c Command to run before (or instead of) TFTP upload\n" " -f Firmware file\n" " -F Remote filename to use during TFTP upload\n" " -i Network interface directly connected to device\n" " -m MAC address of target device (xx:xx:xx:xx:xx:xx)\n" " -M Subnet mask to assign to target device\n" - " -t Timeout (in milliseconds) for regular messages\n" + " -t Timeout (in milliseconds) for NMRP packets\n" " -T Time (seconds) to wait after successfull TFTP upload\n" " -p Port to use for TFTP upload\n" #ifdef NMRPFLASH_SET_REGION @@ -133,7 +133,7 @@ int main(int argc, char **argv) int c, val, max; bool list = false, have_dest_mac = false; struct nmrpd_args args = { - .rx_timeout = 200, + .rx_timeout = NMRPFLASH_DEF_RX_TIMEOUT * 1000, .ul_timeout = 5 * 60 * 1000, .tftpcmd = NULL, .file_local = NULL, @@ -235,7 +235,7 @@ int main(int argc, char **argv) if (c == 'p') { args.port = val; } else if (c == 't') { - args.rx_timeout = val; + args.rx_timeout = val * 1000; } else if (c == 'T') { args.ul_timeout = val * 1000; } diff --git a/nmrpd.h b/nmrpd.h index d65c811..c1dc77e 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -72,6 +72,8 @@ #define NMRPFLASH_SET_REGION +#define NMRPFLASH_DEF_RX_TIMEOUT 200 + struct eth_hdr { uint8_t ether_dhost[6]; uint8_t ether_shost[6]; diff --git a/tftp.c b/tftp.c index 9fd361a..5c37693 100644 --- a/tftp.c +++ b/tftp.c @@ -315,7 +315,7 @@ int tftp_put(struct nmrpd_args *args) const char *file_remote = args->file_remote; char *val, *end; bool rollover; - unsigned rx_timeout = MAX(args->rx_timeout / 200, 1); + unsigned rx_timeout = MAX(args->rx_timeout / NMRPFLASH_DEF_RX_TIMEOUT, 1000); sock = -1; ret = -1;