Set env vars when using -c
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sun, 13 Nov 2016 10:15:45 +0000 (11:15 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sun, 13 Nov 2016 10:17:55 +0000 (11:17 +0100)
README.md
main.c
nmrp.c

index 72757b450be7f098f01fd7ab9df94e7a6e699bd3..235c9128d610f340a5b490024a12b99d70df79e9 100644 (file)
--- a/README.md
+++ b/README.md
@@ -110,7 +110,7 @@ it will actually use `eth0:42`. To override this, manually specify an alias (e.g
 This error message could also indicate a bug in the TFTP code; try using an external tftp
 client (busybox in this example), by specifying the `-c` flag instead of the `-f` flag:
 
-`# nmrpflash -i eth0 -c "busybox tftp -p -l EX2700-V1.0.1.8.img @IP@"`
+`# nmrpflash -i eth0 -c "busybox tftp -p -l EX2700-V1.0.1.8.img \$IP"`
 
 ###### "Timeout while waiting for CLOSE_REQ."
 
diff --git a/main.c b/main.c
index 1091bf81d3d7690b4ec51699dad62ca5766e76d5..fa4cdceee05f2b3722514fc0530b1bddc60ae56f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -67,6 +67,9 @@ void usage(FILE *fp)
 #else
                        "C:\\> nmrpflash.exe -i net0 -f firmware.bin\n"
 #endif
+                       "\n"
+                       "When using -c, the environment variables IP, NETMASK and MAC are\n"
+                       "set to the device IP address, subnet mask and MAC address.\n"
                        "\n"
                        "nmrpflash %s, Copyright (C) 2016 Joseph C. Lehner\n"
                        "nmrpflash is free software, licensed under the GNU GPLv3.\n"
diff --git a/nmrp.c b/nmrp.c
index 1d7008255b1c9d9abc37699e668754e5ad55f2c2..8dbb95693be198f8a3f2171244f0a88acff70ff4 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
 #define PACKED __attribute__((__packed__))
 #endif
 
+#ifdef NMRPFLASH_WINDOWS
+#define setenv(name, value, overwrite) SetEnvironmentVariable(name, value)
+#endif
+
 enum nmrp_code {
        NMRP_C_NONE = 0,
        NMRP_C_ADVERTISE = 1,
@@ -631,10 +635,11 @@ int nmrp_do(struct nmrpd_args *args)
                                status = 0;
 
                                if (args->tftpcmd) {
-                                       printf("Executing '%s' ... ", args->tftpcmd);
-                                       fflush(stdout);
+                                       printf("Executing '%s' ... \n", args->tftpcmd);
+                                       setenv("IP", inet_ntoa(ipconf.addr), 1);
+                                       setenv("MAC", mac_to_str(rx.eh.ether_shost), 1);
+                                       setenv("NETMASK", inet_ntoa(ipconf.mask), 1);
                                        status = system(args->tftpcmd);
-                                       printf("\n");
                                }
 
                                if (!status && args->file_local) {