forked from osmocom/wireshark
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>
This commit is contained in:
parent
94d8250bd0
commit
c1dcaff941
33
randpkt.c
33
randpkt.c
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <wsutil/clopts_common.h>
|
||||||
|
#include <wsutil/cmdarg_err.h>
|
||||||
#include <wsutil/unicode-utils.h>
|
#include <wsutil/unicode-utils.h>
|
||||||
#include <wsutil/file_util.h>
|
#include <wsutil/file_util.h>
|
||||||
#include <wsutil/filesystem.h>
|
#include <wsutil/filesystem.h>
|
||||||
|
@ -47,7 +49,6 @@
|
||||||
|
|
||||||
#include "randpkt_core/randpkt_core.h"
|
#include "randpkt_core/randpkt_core.h"
|
||||||
|
|
||||||
#ifdef HAVE_PLUGINS
|
|
||||||
/*
|
/*
|
||||||
* General errors are reported with an console message in randpkt.
|
* 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);
|
vfprintf(stderr, msg_format, ap);
|
||||||
fprintf(stderr, "\n");
|
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 */
|
/* Print usage statement and exit program */
|
||||||
static void
|
static void
|
||||||
|
@ -118,11 +128,13 @@ main(int argc, char **argv)
|
||||||
char *init_progfile_dir_error;
|
char *init_progfile_dir_error;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get credential information for later use.
|
* Get credential information for later use.
|
||||||
*/
|
*/
|
||||||
init_process_policies();
|
init_process_policies();
|
||||||
init_open_routines();
|
init_open_routines();
|
||||||
|
|
||||||
|
cmdarg_err_init(failure_message, failure_message_cont);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
arg_list_utf_16to8(argc, argv);
|
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) {
|
while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'b': /* max bytes */
|
case 'b': /* max bytes */
|
||||||
produce_max_bytes = atoi(optarg);
|
produce_max_bytes = get_positive_int(optarg, "max bytes");
|
||||||
if (produce_max_bytes > 65536) {
|
if (produce_max_bytes > 65536) {
|
||||||
fprintf(stderr, "randpkt: Max bytes is 65536\n");
|
cmdarg_err("max bytes is > 65536");
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* count */
|
case 'c': /* count */
|
||||||
produce_count = atoi(optarg);
|
produce_count = get_positive_int(optarg, "count");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't': /* type of packet to produce */
|
case 't': /* type of packet to produce */
|
||||||
|
|
Loading…
Reference in New Issue