Skip to content

Commit

Permalink
Add PORT env var
Browse files Browse the repository at this point in the history
  • Loading branch information
jclehner committed Nov 19, 2016
1 parent a88d28b commit fd02c7d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions nmrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions nmrpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include "nmrpd.h"
Expand Down Expand Up @@ -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;
}

0 comments on commit fd02c7d

Please sign in to comment.