Browse Source

Show default values of some command-line options

Joseph C. Lehner 1 year ago
parent
commit
4fa516602c
3 changed files with 30 additions and 23 deletions
  1. 16 13
      main.c
  2. 2 10
      nmrp.c
  3. 12 0
      nmrpd.h

+ 16 - 13
main.c

@@ -23,27 +23,24 @@
 #include <stdio.h>
 #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 <ipaddr>     IP address to assign to target device\n"
-			" -A <ipaddr>     IP address to assign to selected interface\n"
+			" -a <ipaddr>     IP address to assign to target device [%s]\n"
+			" -A <ipaddr>     IP address to assign to selected interface [%s]\n"
 			" -B              Blind mode (don't wait for response packets)\n"
 			" -c <command>    Command to run before (or instead of) TFTP upload\n"
 			" -f <firmware>   Firmware file\n"
 			" -F <filename>   Remote filename to use during TFTP upload\n"
 			" -i <interface>  Network interface directly connected to device\n"
 			" -m <mac>        MAC address of target device (xx:xx:xx:xx:xx:xx)\n"
-			" -M <netmask>    Subnet mask to assign to target device\n"
-			" -t <timeout>    Timeout (in milliseconds) for NMRP packets\n"
-			" -T <timeout>    Time (seconds) to wait after successfull TFTP upload\n"
-			" -p <port>       Port to use for TFTP upload\n"
+			" -M <netmask>    Subnet mask to assign to target device [%s]\n"
+			" -t <timeout>    Timeout (in milliseconds) for NMRP packets [%d ms]\n"
+			" -T <timeout>    Time (seconds) to wait after successfull TFTP upload [%d s]\n"
+			" -p <port>       Port to use for TFTP upload [%d]\n"
 #ifdef NMRPFLASH_SET_REGION
 			" -R <region>     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,

+ 2 - 10
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;

+ 12 - 0
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];