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.
30 #include <wsutil/unicode-utils.h>
31 #include <wsutil/file_util.h>
32 #include <wsutil/filesystem.h>
33 #include <wsutil/privileges.h>
36 #include <wsutil/plugins.h>
39 #include <wsutil/report_err.h>
44 #ifndef HAVE_GETOPT_LONG
45 #include "wsutil/wsgetopt.h"
48 #include "randpkt_core/randpkt_core.h"
52 * Don't report failures to load plugins because most (non-wiretap) plugins
53 * *should* fail to load (because we're not linked against libwireshark and
54 * dissector plugins need libwireshark).
57 failure_message(const char *msg_format _U_, va_list ap _U_)
63 /* Print usage statement and exit program */
65 usage(gboolean is_error)
79 fprintf(output, "Usage: randpkt [-b maxbytes] [-c count] [-t type] [-r] filename\n");
80 fprintf(output, "Default max bytes (per packet) is 5000\n");
81 fprintf(output, "Default count is 1000.\n");
82 fprintf(output, "-r: random packet type selection\n");
83 fprintf(output, "\n");
84 fprintf(output, "Types:\n");
86 /* Get the examples list */
87 randpkt_example_list(&abbrev_list, &longname_list);
88 while (abbrev_list[i] && longname_list[i]) {
89 fprintf(output, "\t%-16s%s\n", abbrev_list[i], longname_list[i]);
93 g_strfreev(abbrev_list);
94 g_strfreev(longname_list);
96 fprintf(output, "\nIf type is not specified, a random packet will be chosen\n\n");
98 exit(is_error ? 1 : 0);
101 main(int argc, char **argv)
104 int produce_type = -1;
105 char *produce_filename = NULL;
106 int produce_max_bytes = 5000;
107 int produce_count = 1000;
108 randpkt_example *example;
110 int allrandom = FALSE;
111 wtap_dumper *savedump;
112 static const struct option long_options[] = {
113 {"help", no_argument, NULL, 'h'},
118 char *init_progfile_dir_error;
122 * Get credential information for later use.
124 init_process_policies();
125 init_open_routines();
128 arg_list_utf_16to8(argc, argv);
129 create_app_running_mutex();
133 /* Register wiretap plugins */
134 if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
135 g_warning("randpkt: init_progfile_dir(): %s", init_progfile_dir_error);
136 g_free(init_progfile_dir_error);
138 /* Register all the plugin types we have. */
139 wtap_register_plugin_types(); /* Types known to libwiretap */
141 init_report_err(failure_message,NULL,NULL,NULL);
143 /* Scan for plugins. This does *not* call their registration routines;
144 that's done later. */
147 /* Register all libwiretap plugin modules. */
148 register_all_wiretap_modules();
152 while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
154 case 'b': /* max bytes */
155 produce_max_bytes = atoi(optarg);
156 if (produce_max_bytes > 65536) {
157 fprintf(stderr, "randpkt: Max bytes is 65536\n");
162 case 'c': /* count */
163 produce_count = atoi(optarg);
166 case 't': /* type of packet to produce */
167 type = g_strdup(optarg);
184 /* any more command line parameters? */
186 produce_filename = argv[optind];
195 produce_type = randpkt_parse_type(type);
198 example = randpkt_find_example(produce_type);
202 randpkt_example_init(example, produce_filename, produce_max_bytes);
203 randpkt_loop(example, produce_count);
206 fprintf(stderr, "Can't set type in random mode\n");
210 produce_type = randpkt_parse_type(NULL);
211 example = randpkt_find_example(produce_type);
214 randpkt_example_init(example, produce_filename, produce_max_bytes);
216 while (produce_count-- > 0) {
217 randpkt_loop(example, 1);
218 produce_type = randpkt_parse_type(NULL);
220 savedump = example->dump;
222 example = randpkt_find_example(produce_type);
225 example->dump = savedump;
228 if (!randpkt_example_close(example))
235 * Editor modelines - http://www.wireshark.org/tools/modelines.html
240 * indent-tabs-mode: t
243 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
244 * :indentSize=8:tabSize=8:noTabs=false: