aboutsummaryrefslogtreecommitdiffstats
path: root/randpkt.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-09-05 17:33:20 -0700
committerGuy Harris <guy@alum.mit.edu>2016-09-06 00:34:07 +0000
commitc1dcaff9417ba8697d9686185002ab03fee83fe5 (patch)
tree97df657860f9b4e717aa62100d1daf98bd472e03 /randpkt.c
parent94d8250bd00b30e6b0935a0c48d78bec0f2a9242 (diff)
Use get_positive_int() to parse signed positive arguments.
Clean up indentation while we're at it. Change-Id: Ie7223f96c758bd71d2435203635db9c2b28e2249 Reviewed-on: https://code.wireshark.org/review/17508 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'randpkt.c')
-rw-r--r--randpkt.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/randpkt.c b/randpkt.c
index 4346afb52c..58ff3b1aaa 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -27,6 +27,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <wsutil/clopts_common.h>
+#include <wsutil/cmdarg_err.h>
#include <wsutil/unicode-utils.h>
#include <wsutil/file_util.h>
#include <wsutil/filesystem.h>
@@ -47,7 +49,6 @@
#include "randpkt_core/randpkt_core.h"
-#ifdef HAVE_PLUGINS
/*
* General errors are reported with an console message in randpkt.
*/
@@ -58,7 +59,16 @@ failure_message(const char *msg_format, va_list ap)
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
-#endif
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+static void
+failure_message_cont(const char *msg_format, va_list ap)
+{
+ vfprintf(stderr, msg_format, ap);
+ fprintf(stderr, "\n");
+}
/* Print usage statement and exit program */
static void
@@ -118,11 +128,13 @@ main(int argc, char **argv)
char *init_progfile_dir_error;
#endif
- /*
- * Get credential information for later use.
- */
- init_process_policies();
- init_open_routines();
+ /*
+ * Get credential information for later use.
+ */
+ init_process_policies();
+ init_open_routines();
+
+ cmdarg_err_init(failure_message, failure_message_cont);
#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
@@ -157,15 +169,14 @@ main(int argc, char **argv)
while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
switch (opt) {
case 'b': /* max bytes */
- produce_max_bytes = atoi(optarg);
+ produce_max_bytes = get_positive_int(optarg, "max bytes");
if (produce_max_bytes > 65536) {
- fprintf(stderr, "randpkt: Max bytes is 65536\n");
- return 1;
+ cmdarg_err("max bytes is > 65536");
}
break;
case 'c': /* count */
- produce_count = atoi(optarg);
+ produce_count = get_positive_int(optarg, "count");
break;
case 't': /* type of packet to produce */