Add PORT env var
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 19 Nov 2016 10:07:38 +0000 (11:07 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sat, 19 Nov 2016 10:14:47 +0000 (11:14 +0100)
main.c
nmrp.c
nmrpd.h
util.c

diff --git a/main.c b/main.c
index 4692a8f98873834d129337ee503a8b2c2999e7f0..2830cf7f68c4443d2dd1cc5925e9a31c700e6c6e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -68,8 +68,9 @@ void usage(FILE *fp)
                        "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"
+                       "When using -c, the environment variables IP, PORT, NETMASK\n"
+                       "and MAC are set to the device IP address, TFTP port, subnet\n"
+                       "mask and MAC address, respectively.\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 eebaf830b76fec3c89fab9b560cd581581e43ab8..0d392592e05c02c52d0e54e16b29f2b554af7e5b 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
@@ -654,8 +654,10 @@ int nmrp_do(struct nmrpd_args *args)
                                if (args->tftpcmd) {
                                        printf("Executing '%s' ... \n", args->tftpcmd);
                                        setenv("IP", inet_ntoa(ipconf.addr), 1);
+                                       setenv("PORT", lltostr(args->port, 10), 1);
                                        setenv("MAC", mac_to_str(rx.eh.ether_shost), 1);
                                        setenv("NETMASK", inet_ntoa(ipconf.mask), 1);
+                                       //setenv("FILENAME", args->file_remote ? args->file_remote : "", 1);
                                        status = system(args->tftpcmd);
                                }
 
diff --git a/nmrpd.h b/nmrpd.h
index ac54949efd1dc58be19142b46d4782b041fb215a..2e85012694658b9329410cf5ad8a5f6b1fe0d216 100644 (file)
--- a/nmrpd.h
+++ b/nmrpd.h
@@ -131,4 +131,5 @@ int ethsock_ip_add(struct ethsock *sock, uint32_t ipaddr, uint32_t ipmask, struc
 int ethsock_ip_del(struct ethsock *sock, struct ethsock_ip_undo **undo);
 
 time_t time_monotonic();
+char *lltostr(long long ll, int base);
 #endif
diff --git a/util.c b/util.c
index 4743af32abceb89d9bf450a0cb437ec0321285de..4422442dea94197604636dcd1f4e6d12fa947b3d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <time.h>
 #include <math.h>
 #include "nmrpd.h"
@@ -27,3 +28,10 @@ time_t time_monotonic()
        return round(GetTickCount() / 1000.0);
 #endif
 }
+
+char *lltostr(long long ll, int base)
+{
+       static char buf[32];
+       snprintf(buf, sizeof(buf) - 1, (base == 16 ? "%llx" : (base == 8 ? "%llo" : "%lld")), ll);
+       return buf;
+}