aboutsummaryrefslogtreecommitdiffstats
path: root/randpkt_core/randpkt_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'randpkt_core/randpkt_core.c')
-rw-r--r--randpkt_core/randpkt_core.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c
index 628b941c23..9cced12714 100644
--- a/randpkt_core/randpkt_core.c
+++ b/randpkt_core/randpkt_core.c
@@ -10,14 +10,15 @@
*/
#include <config.h>
+#define WS_LOG_DOMAIN "randpkt"
#include "randpkt_core.h"
#include <time.h>
-#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <wsutil/file_util.h>
+#include <wsutil/wslog.h>
#include <wiretap/wtap_opttypes.h>
#include "ui/failure_message.h"
@@ -555,7 +556,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;
@@ -593,6 +594,13 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count)
}
len_this_pkt = example->sample_length + len_random;
+ if (len_this_pkt > WTAP_MAX_PACKET_SIZE_STANDARD) {
+ /*
+ * Wiretap will fail when trying to read packets
+ * bigger than WTAP_MAX_PACKET_SIZE_STANDARD.
+ */
+ len_this_pkt = WTAP_MAX_PACKET_SIZE_STANDARD;
+ }
rec->rec_header.packet_header.caplen = len_this_pkt;
rec->rec_header.packet_header.len = len_this_pkt;
@@ -613,9 +621,17 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count)
}
if (!wtap_dump(example->dump, rec, buffer, &err, &err_info)) {
- cfile_write_failure_message("randpkt", NULL,
+ cfile_write_failure_message(NULL,
example->filename, err, err_info, 0,
- WTAP_FILE_TYPE_SUBTYPE_PCAP);
+ wtap_dump_file_type_subtype(example->dump));
+ }
+ if (packet_delay_ms) {
+ g_usleep(1000 * (gulong)packet_delay_ms);
+ if (!wtap_dump_flush(example->dump, &err)) {
+ cfile_write_failure_message(NULL,
+ example->filename, err, NULL, 0,
+ wtap_dump_file_type_subtype(example->dump));
+ }
}
}
@@ -626,10 +642,11 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count)
gboolean randpkt_example_close(randpkt_example* example)
{
int err;
+ gchar *err_info;
gboolean ok = TRUE;
- if (!wtap_dump_close(example->dump, &err)) {
- cfile_close_failure_message(example->filename, err);
+ if (!wtap_dump_close(example->dump, NULL, &err, &err_info)) {
+ cfile_close_failure_message(example->filename, err, err_info);
ok = FALSE;
}
@@ -641,27 +658,32 @@ gboolean randpkt_example_close(randpkt_example* example)
return ok;
}
-int randpkt_example_init(randpkt_example* example, char* produce_filename, int produce_max_bytes)
+int randpkt_example_init(randpkt_example* example, char* produce_filename, int produce_max_bytes, int file_type_subtype)
{
int err;
+ gchar *err_info;
if (pkt_rand == NULL) {
pkt_rand = g_rand_new();
}
+ const wtap_dump_params params = {
+ .encap = example->sample_wtap_encap,
+ .snaplen = produce_max_bytes,
+ };
if (strcmp(produce_filename, "-") == 0) {
/* Write to the standard output. */
- example->dump = wtap_dump_open_stdout(WTAP_FILE_TYPE_SUBTYPE_PCAP,
- example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, &err);
+ example->dump = wtap_dump_open_stdout(file_type_subtype,
+ WTAP_UNCOMPRESSED, &params, &err, &err_info);
example->filename = "the standard output";
} else {
- example->dump = wtap_dump_open(produce_filename, WTAP_FILE_TYPE_SUBTYPE_PCAP,
- example->sample_wtap_encap, produce_max_bytes, FALSE /* compressed */, &err);
+ example->dump = wtap_dump_open(produce_filename, file_type_subtype,
+ WTAP_UNCOMPRESSED, &params, &err, &err_info);
example->filename = produce_filename;
}
if (!example->dump) {
- cfile_dump_open_failure_message("randpkt", produce_filename,
- err, WTAP_FILE_TYPE_SUBTYPE_PCAP);
+ cfile_dump_open_failure_message(produce_filename,
+ err, err_info, file_type_subtype);
return WRITE_ERROR;
}
@@ -696,7 +718,7 @@ int randpkt_parse_type(char *string)
}
/* Complain */
- g_error("randpkt: Type %s not known.\n", string);
+ ws_error("randpkt: Type %s not known.\n", string);
return -1;
}
@@ -714,7 +736,7 @@ void randpkt_example_list(char*** abbrev_list, char*** longname_list)
}
/*
- * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ * Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8