4 * Creates random packet traces. Useful for debugging sniffers by testing
5 * assumptions about the veracity of the data found in the packet.
7 * Copyright (C) 1999 by Gilbert Ramirez <gram@alumni.rice.edu>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <wsutil/ws_diag_control.h>
28 #include <wsutil/unicode-utils.h>
29 #include <wsutil/file_util.h>
35 #ifndef HAVE_GETOPT_LONG
36 #include "wsutil/wsgetopt.h"
39 #include "randpkt_core/randpkt_core.h"
41 /* Print usage statement and exit program */
43 usage(gboolean is_error)
46 const char** abbrev_list;
47 const char** longname_list;
58 fprintf(output, "Usage: randpkt [-b maxbytes] [-c count] [-t type] [-r] filename\n");
59 fprintf(output, "Default max bytes (per packet) is 5000\n");
60 fprintf(output, "Default count is 1000.\n");
61 fprintf(output, "-r: random packet type selection\n");
62 fprintf(output, "\n");
63 fprintf(output, "Types:\n");
65 /* Get the examples list */
66 randpkt_example_list(&abbrev_list, &longname_list, &list_num);
67 for (i = 0; i < list_num; i++) {
68 fprintf(output, "\t%-16s%s\n", abbrev_list[i], longname_list[i]);
70 g_free((char**)abbrev_list);
71 g_free((char**)longname_list);
73 fprintf(output, "\nIf type is not specified, a random packet will be chosen\n\n");
75 exit(is_error ? 1 : 0);
78 main(int argc, char **argv)
81 int produce_type = -1;
82 char *produce_filename = NULL;
83 int produce_max_bytes = 5000;
84 int produce_count = 1000;
85 randpkt_example *example;
87 int allrandom = FALSE;
88 wtap_dumper *savedump;
89 static const struct option long_options[] = {
90 {"help", no_argument, NULL, 'h'},
95 arg_list_utf_16to8(argc, argv);
96 create_app_running_mutex();
99 while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
101 case 'b': /* max bytes */
102 produce_max_bytes = atoi(optarg);
103 if (produce_max_bytes > 65536) {
104 fprintf(stderr, "randpkt: Max bytes is 65536\n");
109 case 'c': /* count */
110 produce_count = atoi(optarg);
113 case 't': /* type of packet to produce */
114 type = g_strdup(optarg);
131 /* any more command line parameters? */
133 produce_filename = argv[optind];
142 produce_type = randpkt_parse_type(type);
145 example = randpkt_find_example(produce_type);
149 randpkt_example_init(example, produce_filename, produce_max_bytes);
150 randpkt_loop(example, produce_count);
153 fprintf(stderr, "Can't set type in random mode\n");
157 produce_type = randpkt_parse_type(NULL);
158 example = randpkt_find_example(produce_type);
161 randpkt_example_init(example, produce_filename, produce_max_bytes);
163 while (produce_count-- > 0) {
164 randpkt_loop(example, 1);
165 produce_type = randpkt_parse_type(NULL);
167 savedump = example->dump;
169 example = randpkt_find_example(produce_type);
172 example->dump = savedump;
175 if (!randpkt_example_close(example))
182 * Editor modelines - http://www.wireshark.org/tools/modelines.html
187 * indent-tabs-mode: t
190 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
191 * :indentSize=8:tabSize=8:noTabs=false: