aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-06-29 21:22:09 -0700
committerAnders Broman <a.broman58@gmail.com>2018-07-01 06:57:23 +0000
commitf7b91633c447fb313f299392500eb12fda0e5612 (patch)
tree71451f239fc1ee491a763ccd64ce6e081aa78585
parent61656dd2e62f91b194b803f15c6faf0a647dcdf9 (diff)
randpktdump: add --delay option
For testing live capture mode in the Qt UI, it is useful to have a continous capture source with some dummy packets. Change-Id: Id76ecbf24828dd3212b208c96679524e4c25b00f Reviewed-on: https://code.wireshark.org/review/28537 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <lomato@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--doc/randpktdump.pod21
-rw-r--r--extcap/randpktdump.c18
-rw-r--r--randpkt.c4
-rw-r--r--randpkt_core/randpkt_core.c6
-rw-r--r--randpkt_core/randpkt_core.h2
5 files changed, 40 insertions, 11 deletions
diff --git a/doc/randpktdump.pod b/doc/randpktdump.pod
index aa193e83fb..1ea4a879a0 100644
--- a/doc/randpktdump.pod
+++ b/doc/randpktdump.pod
@@ -15,6 +15,8 @@ S<[ B<--extcap-config> ]>
S<[ B<--capture> ]>
S<[ B<--fifo>=E<lt>path to file or pipeE<gt> ]>
S<[ B<--maxbytes>=E<lt>bytesE<gt> ]>
+S<[ B<--count>=E<lt>numE<gt> ]>
+S<[ B<--delay>=E<lt>msE<gt> ]>
S<[ B<--random-type>=E<lt>true|falseE<gt> ]>
S<[ B<--all-random>=E<lt>true|falseE<gt> ]>
S<[ B<--type>=E<lt>packet typeE<gt> ]>
@@ -65,6 +67,14 @@ Save captured packet to file or send it through pipe.
Set the max number of bytes per packet.
+=item --count=E<lt>numE<gt>
+
+Number of packets to generate (-1 for infinite).
+
+=item --delay=E<lt>msE<gt>
+
+Wait a number of milliseconds after writing each packet.
+
=item --random-type
Choose a random packet type for all packets if set to true.
@@ -110,12 +120,13 @@ To see interface configuration options:
Example output:
arg {number=0}{call=--maxbytes}{display=Max bytes in a packet}{type=unsigned}{range=1,5000}{default=5000}{tooltip=The max number of bytes in a packet}
arg {number=1}{call=--count}{display=Number of packets}{type=long}{default=1000}{tooltip=Number of packets to generate (-1 for infinite)}
- arg {number=2}{call=--random-type}{display=Random type}{type=boolean}{default=false}{tooltip=The packets type is randomly choosen}
- arg {number=3}{call=--all-random}{display=All random packets}{type=boolean}{default=false}{tooltip=Packet type for each packet is randomly choosen}
- arg {number=4}{call=--type}{display=Type of packet}{type=selector}{tooltip=Type of packet to generate}
- value {arg=4}{value=arp}{display=Address Resolution Protocol}
+ arg {number=2}{call=--delay}{display=Packet delay (ms)}{type=long}{default=0}{tooltip=Milliseconds to wait after writing each packet}
+ arg {number=3}{call=--random-type}{display=Random type}{type=boolflag}{default=false}{tooltip=The packets type is randomly chosen}
+ arg {number=4}{call=--all-random}{display=All random packets}{type=boolflag}{default=false}{tooltip=Packet type for each packet is randomly chosen}
+ arg {number=5}{call=--type}{display=Type of packet}{type=selector}{tooltip=Type of packet to generate}
+ value {arg=5}{value=arp}{display=Address Resolution Protocol}
[...]
- value {arg=4}{value=usb-linux}{display=Universal Serial Bus with Linux specific header}
+ value {arg=5}{value=usb-linux}{display=Universal Serial Bus with Linux specific header}
To capture:
diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c
index a977a455e9..4fa76e3526 100644
--- a/extcap/randpktdump.c
+++ b/extcap/randpktdump.c
@@ -29,6 +29,7 @@ enum {
OPT_VERSION,
OPT_MAXBYTES,
OPT_COUNT,
+ OPT_DELAY,
OPT_RANDOM_TYPE,
OPT_ALL_RANDOM,
OPT_TYPE
@@ -40,6 +41,7 @@ static struct option longopts[] = {
{ "version", no_argument, NULL, OPT_VERSION},
{ "maxbytes", required_argument, NULL, OPT_MAXBYTES},
{ "count", required_argument, NULL, OPT_COUNT},
+ { "delay", required_argument, NULL, OPT_DELAY},
{ "random-type", no_argument, NULL, OPT_RANDOM_TYPE},
{ "all-random", no_argument, NULL, OPT_ALL_RANDOM},
{ "type", required_argument, NULL, OPT_TYPE},
@@ -89,6 +91,9 @@ static int list_config(char *interface)
printf("arg {number=%u}{call=--count}{display=Number of packets}"
"{type=long}{default=1000}{tooltip=Number of packets to generate (-1 for infinite)}\n",
inc++);
+ printf("arg {number=%u}{call=--delay}{display=Packet delay (ms)}"
+ "{type=long}{default=0}{tooltip=Milliseconds to wait after writing each packet}\n",
+ inc++);
printf("arg {number=%u}{call=--random-type}{display=Random type}"
"{type=boolflag}{default=false}{tooltip=The packets type is randomly chosen}\n",
inc++);
@@ -120,6 +125,7 @@ int main(int argc, char *argv[])
int result;
guint16 maxbytes = 5000;
guint64 count = 1000;
+ guint64 packet_delay_ms = 0;
int random_type = FALSE;
int all_random = FALSE;
char* type = NULL;
@@ -156,6 +162,7 @@ int main(int argc, char *argv[])
extcap_help_add_option(extcap_conf, "--version", "print the version");
extcap_help_add_option(extcap_conf, "--maxbytes <bytes>", "max bytes per pack");
extcap_help_add_option(extcap_conf, "--count <num>", "number of packets to generate");
+ extcap_help_add_option(extcap_conf, "--delay <ms>", "milliseconds to wait after writing each packet");
extcap_help_add_option(extcap_conf, "--random-type", "one random type is chosen for all packets");
extcap_help_add_option(extcap_conf, "--all-random", "a random type is chosen for each packet");
extcap_help_add_option(extcap_conf, "--type <type>", "the packet type");
@@ -196,6 +203,13 @@ int main(int argc, char *argv[])
}
break;
+ case OPT_DELAY:
+ if (!ws_strtou64(optarg, NULL, &packet_delay_ms)) {
+ g_warning("Invalid packet delay: %s", optarg);
+ goto end;
+ }
+ break;
+
case OPT_RANDOM_TYPE:
random_type = TRUE;
break;
@@ -275,7 +289,7 @@ int main(int argc, char *argv[])
g_debug("Generating packets: %s", example->abbrev);
randpkt_example_init(example, extcap_conf->fifo, maxbytes);
- randpkt_loop(example, count);
+ randpkt_loop(example, count, packet_delay_ms);
randpkt_example_close(example);
} else {
produce_type = randpkt_parse_type(NULL);
@@ -285,7 +299,7 @@ int main(int argc, char *argv[])
randpkt_example_init(example, extcap_conf->fifo, maxbytes);
while (count-- > 0) {
- randpkt_loop(example, 1);
+ randpkt_loop(example, 1, packet_delay_ms);
produce_type = randpkt_parse_type(NULL);
savedump = example->dump;
diff --git a/randpkt.c b/randpkt.c
index ff36dec77e..2a2ce08d89 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -206,7 +206,7 @@ main(int argc, char **argv)
ret = randpkt_example_init(example, produce_filename, produce_max_bytes);
if (ret != EXIT_SUCCESS)
goto clean_exit;
- randpkt_loop(example, produce_count);
+ randpkt_loop(example, produce_count, 0);
} else {
if (type) {
fprintf(stderr, "Can't set type in random mode\n");
@@ -225,7 +225,7 @@ main(int argc, char **argv)
goto clean_exit;
while (produce_count-- > 0) {
- randpkt_loop(example, 1);
+ randpkt_loop(example, 1, 0);
produce_type = randpkt_parse_type(NULL);
savedump = example->dump;
diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c
index b156fb9b67..738395fbd1 100644
--- a/randpkt_core/randpkt_core.c
+++ b/randpkt_core/randpkt_core.c
@@ -555,7 +555,7 @@ randpkt_example* randpkt_find_example(int type)
return NULL;
}
-void randpkt_loop(randpkt_example* example, guint64 produce_count)
+void randpkt_loop(randpkt_example* example, guint64 produce_count, guint64 packet_delay_ms)
{
guint i, j;
int err;
@@ -624,6 +624,10 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count)
example->filename, err, err_info, 0,
WTAP_FILE_TYPE_SUBTYPE_PCAP);
}
+ if (packet_delay_ms) {
+ g_usleep(1000 * (gulong)packet_delay_ms);
+ wtap_dump_flush(example->dump);
+ }
}
g_free(rec);
diff --git a/randpkt_core/randpkt_core.h b/randpkt_core/randpkt_core.h
index 53dc042687..9ec811c0d8 100644
--- a/randpkt_core/randpkt_core.h
+++ b/randpkt_core/randpkt_core.h
@@ -46,7 +46,7 @@ randpkt_example* randpkt_find_example(int type);
int randpkt_example_init(randpkt_example* example, char* produce_filename, int produce_max_bytes);
/* Loop the packet generation */
-void randpkt_loop(randpkt_example* example, guint64 produce_count);
+void randpkt_loop(randpkt_example* example, guint64 produce_count, guint64 packet_delay_ms);
/* Close the current example */
gboolean randpkt_example_close(randpkt_example* example);