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.
24 #include "randpkt-core.h"
29 #include <wsutil/ws_diag_control.h>
30 #include <wsutil/unicode-utils.h>
31 #include <wsutil/file_util.h>
37 #ifndef HAVE_GETOPT_LONG
38 #include "wsutil/wsgetopt.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;
90 static const struct option long_options[] = {
91 {(char *)"help", no_argument, NULL, 'h'},
97 arg_list_utf_16to8(argc, argv);
98 create_app_running_mutex();
101 while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
103 case 'b': /* max bytes */
104 produce_max_bytes = atoi(optarg);
105 if (produce_max_bytes > 65536) {
106 fprintf(stderr, "randpkt: Max bytes is 65536\n");
111 case 'c': /* count */
112 produce_count = atoi(optarg);
115 case 't': /* type of packet to produce */
116 type = g_strdup(optarg);
133 /* any more command line parameters? */
135 produce_filename = argv[optind];
144 produce_type = randpkt_parse_type(type);
147 example = randpkt_find_example(produce_type);
151 randpkt_example_init(example, produce_filename, produce_max_bytes);
152 randpkt_loop(example, produce_count);
155 fprintf(stderr, "Can't set type in random mode\n");
159 produce_type = randpkt_parse_type(NULL);
160 example = randpkt_find_example(produce_type);
163 randpkt_example_init(example, produce_filename, produce_max_bytes);
165 while (produce_count-- > 0) {
166 randpkt_loop(example, 1);
167 produce_type = randpkt_parse_type(NULL);
169 savedump = example->dump;
171 example = randpkt_find_example(produce_type);
174 example->dump = savedump;
177 if (!randpkt_example_close(example))
184 * Editor modelines - http://www.wireshark.org/tools/modelines.html
189 * indent-tabs-mode: t
192 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
193 * :indentSize=8:tabSize=8:noTabs=false: