X-Git-Url: https://iam.tj/gitweb/gitweb.cgi?p=cfe_generate_password.git;a=blobdiff_plain;f=cfe_generate_password.c;h=f806b2c908eb3fdb93123a8950de8f14b66d9179;hp=6331dbd1a3c0266e31dc28a0f8c287e9695ad502;hb=90e959b83814234b2f38ec612e90c4c51c994b62;hpb=43b4a2bde34a377b9d4f54e781beed8a7742e1f2 diff --git a/cfe_generate_password.c b/cfe_generate_password.c index 6331dbd..f806b2c 100644 --- a/cfe_generate_password.c +++ b/cfe_generate_password.c @@ -1,6 +1,7 @@ static const char *title = \ "Generate Broadcom CFE seeds and passwords for many popular modem/router devices\n" ; +static const float VERSION = 1.3f; static const char *copyright = \ "Copyright 2015 TJ \n" @@ -67,7 +68,6 @@ static const char *help = \ #include #include -static const float VERSION = 1.3f; static const size_t TIMESTAMP_SIZE = 8; static const size_t SEED_SIZE = 12; static const size_t PASSWORD_SIZE = 8; @@ -76,17 +76,18 @@ static const size_t MAC_ADDR_SIZE = 17; static const size_t DATESTRING_SIZE = 20; static void -pr_usage() +pr_usage(int verbose) { - fprintf(stderr, "%s\n", + fprintf(stderr, "Usage:\n" " -v show version\n" " -s 00:01:02:03:04:05 create seed from MAC address\n" " -t [00000000] seconds since 1970-01-01 (defaults to NOW) \n" - " -p [SEED] generate password (with optional seed)\n\n" - " E.g. -s 01:02:03:04:05 \n" - " -s 01:02:03:04:05 -p\n" - " -p 000000030405\n" + " -p [SEED] generate password (with optional seed)\n" + " -h show additional help\n" + "\n" + "%s", + verbose ? help : "" ); } @@ -103,7 +104,7 @@ pr_error_exit(unsigned int usage, const char *error, ...) va_end(args); fprintf(stderr, "Error: %s\n", error_message); - if (usage) pr_usage(); + if (usage) pr_usage(usage); exit(EXIT_FAILURE); } @@ -174,7 +175,7 @@ main(int argc, char **argv, char **env) int result = 0; if (argc == 1) { - pr_usage(); + pr_usage(0); } else { unsigned int arg; @@ -205,6 +206,9 @@ main(int argc, char **argv, char **env) case 't': opt_ts = 1; break; + case 'h': + pr_usage(1); + exit(0); case 'v': fprintf(stderr, "Version: %0.2f\n", VERSION); } @@ -226,7 +230,7 @@ main(int argc, char **argv, char **env) } } if (! opt_seed && ! opt_pass) - pr_usage(); + pr_usage(0); else if (opt_seed && opt_seed != 2) pr_error_exit(1, "seed requires MAC-ADDRESS"); else if (! opt_seed && opt_pass && opt_pass != 2)