From fd02c7dfa9296e3cd43fc70755e314def14895c9 Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Sat, 19 Nov 2016 11:07:38 +0100 Subject: [PATCH] Add PORT env var --- main.c | 5 +++-- nmrp.c | 2 ++ nmrpd.h | 1 + util.c | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 4692a8f..2830cf7 100644 --- 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 eebaf83..0d39259 100644 --- 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 ac54949..2e85012 100644 --- 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 4743af3..4422442 100644 --- a/util.c +++ b/util.c @@ -1,3 +1,4 @@ +#include #include #include #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; +}