From 4fa516602cc116619fd3bcdade5875598250463b Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Sat, 11 Jun 2022 19:25:38 +0200 Subject: [PATCH] Show default values of some command-line options --- main.c | 29 ++++++++++++++++------------- nmrp.c | 12 ++---------- nmrpd.h | 12 ++++++++++++ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/main.c b/main.c index 4678709..02c3e8b 100644 --- a/main.c +++ b/main.c @@ -23,27 +23,24 @@ #include #include "nmrpd.h" -#define NMRP_UL_TIMEOUT_S 30 * 60 -#define NMRP_RX_TIMEOUT_MS 10000 - void usage(FILE *fp) { fprintf(fp, "Usage: nmrpflash [OPTIONS...]\n" "\n" "Options (-i, and -f or -c are mandatory):\n" - " -a IP address to assign to target device\n" - " -A IP address to assign to selected interface\n" + " -a IP address to assign to target device [%s]\n" + " -A IP address to assign to selected interface [%s]\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 NMRP packets\n" - " -T Time (seconds) to wait after successfull TFTP upload\n" - " -p Port to use for TFTP upload\n" + " -M Subnet mask to assign to target device [%s]\n" + " -t Timeout (in milliseconds) for NMRP packets [%d ms]\n" + " -T Time (seconds) to wait after successfull TFTP upload [%d s]\n" + " -p Port to use for TFTP upload [%d]\n" #ifdef NMRPFLASH_SET_REGION " -R Set device region (NA, WW, GR, PR, RU, BZ, IN, KO, JP)\n" #endif @@ -77,6 +74,12 @@ void usage(FILE *fp) "nmrpflash is free software, licensed under the GNU GPLv3.\n" "Source code at https://github.com/jclehner/nmrpflash\n" "\n", + NMRP_DEFAULT_IP_REMOTE, + NMRP_DEFAULT_IP_LOCAL, + NMRP_DEFAULT_SUBNET, + NMRP_DEFAULT_RX_TIMEOUT_MS, + NMRP_DEFAULT_UL_TIMEOUT_S, + NMRP_DEFAULT_TFTP_PORT, NMRPFLASH_VERSION ); } @@ -135,18 +138,18 @@ int main(int argc, char **argv) int c, val, max; bool list = false, have_dest_mac = false; struct nmrpd_args args = { - .rx_timeout = (NMRP_RX_TIMEOUT_MS), - .ul_timeout = (NMRP_UL_TIMEOUT_S) * 1000, + .rx_timeout = NMRP_DEFAULT_RX_TIMEOUT_MS, + .ul_timeout = NMRP_DEFAULT_UL_TIMEOUT_S * 1000, .tftpcmd = NULL, .file_local = NULL, .file_remote = NULL, .ipaddr_intf = NULL, .ipaddr = NULL, - .ipmask = "255.255.255.0", + .ipmask = NMRP_DEFAULT_SUBNET, .intf = NULL, .mac = "ff:ff:ff:ff:ff:ff", .op = NMRP_UPLOAD_FW, - .port = 69, + .port = NMRP_DEFAULT_TFTP_PORT, .region = NULL, .blind = false, .offset = 0, diff --git a/nmrp.c b/nmrp.c index 383d8f5..4f6bb10 100644 --- a/nmrp.c +++ b/nmrp.c @@ -386,18 +386,10 @@ int nmrp_do(struct nmrpd_args *args) if (!args->ipaddr) { autoip = true; - /* A random IP address. The MAC of the first device that was - * used to test this utility starts with a4:2b:8c, so we use - * 164 (0xa4) and 183 (0x2b + 0x8c). - * - * These addresses should not cause collisions on most networks, - * and if they do, the user is probably "poweruser" enough to - * be able to use the -a and -A options. - */ - args->ipaddr = "10.164.183.252"; + args->ipaddr = NMRP_DEFAULT_IP_REMOTE; if (!args->ipaddr_intf) { - args->ipaddr_intf = "10.164.183.253"; + args->ipaddr_intf = NMRP_DEFAULT_IP_LOCAL; } } else if (args->ipaddr_intf) { autoip = true; diff --git a/nmrpd.h b/nmrpd.h index e536a5b..f7ca57b 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -72,6 +72,18 @@ #define NMRPFLASH_SET_REGION +#define NMRP_DEFAULT_UL_TIMEOUT_S (30 * 60) +#define NMRP_DEFAULT_RX_TIMEOUT_MS (10000) +/* + * These addresses should not cause collisions on most networks, + * and if they do, the user is probably "poweruser" enough to + * be able to use the -a and -A options. + */ +#define NMRP_DEFAULT_IP_LOCAL "10.164.183.252" +#define NMRP_DEFAULT_IP_REMOTE "10.164.183.253" +#define NMRP_DEFAULT_SUBNET "255.255.255.0" +#define NMRP_DEFAULT_TFTP_PORT 69 + struct eth_hdr { uint8_t ether_dhost[6]; uint8_t ether_shost[6];