From e5fcb64cc3e674c1e6ddb629dd3789eb04191db6 Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Mon, 25 Jan 2016 15:03:58 +0100 Subject: [PATCH] Fix messages --- main.c | 22 +++++++++++++++++++--- nmrp.c | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 7f9797c..4d20411 100644 --- a/main.c +++ b/main.c @@ -27,7 +27,7 @@ void usage(FILE *fp) fprintf(fp, "Usage: nmrp-flash [OPTIONS...]\n" "\n" - "Options:\n" + "Options (-a, -i and -f are mandatory):\n" " -a IP address to assign to target device\n" " -f Firmware file\n" " -i Network interface directly connected to device\n" @@ -36,10 +36,18 @@ void usage(FILE *fp) " -t Timeout (in milliseconds) for regular messages\n" " -T Time to wait after successfull TFTP upload\n" " -p Port to use for TFTP upload\n" + " -V Print version and exit\n" " -h Show this screen\n" "\n" - "Options -a, -i and -f are mandatory!\n" + "Example:\n" "\n" + "$ sudo nmrp-flash -a 192.168.1.254 -i eth0 -f firmware.bin\n" + "\n" + "nmrp-flash v%s, Copyright (C) 2016 Joseph C. Lehner\n" + "nmrp-flash is free software, licensed under the GNU GPLv3.\n" + "Source code at https://github.com/jclehner/nmrp-flash\n" + "\n", + NMRPD_VERSION ); } @@ -61,7 +69,7 @@ int main(int argc, char **argv) opterr = 0; - while ((c = getopt(argc, argv, "a:f:i:m:M:p:t:T:")) != -1) { + while ((c = getopt(argc, argv, "a:f:i:m:M:p:t:T:hV")) != -1) { max = 0xffffffff; switch (c) { case 'a': @@ -98,6 +106,9 @@ int main(int argc, char **argv) } break; + case 'V': + printf("nmrp-flash v%s\n", NMRPD_VERSION); + return 0; case 'h': usage(stdout); return 0; @@ -112,5 +123,10 @@ int main(int argc, char **argv) return 1; } + if (geteuid() != 0) { + fprintf(stderr, "This program must be run as root!\n"); + return 1; + } + return nmrp_do(&args); } diff --git a/nmrp.c b/nmrp.c index 0b77130..59d0abc 100644 --- a/nmrp.c +++ b/nmrp.c @@ -437,7 +437,7 @@ int nmrp_do(struct nmrpd_args *args) expect = NMRP_C_TFTP_UL_REQ; - printf("Configuration request received from " + printf("Received configuration request from " "%02x:%02x:%02x:%02x:%02x:%02x.\n", rx.eh.ether_shost[0], rx.eh.ether_shost[1], rx.eh.ether_shost[2], rx.eh.ether_shost[3], -- 2.25.1