diff options
Diffstat (limited to 'randpkt_core')
-rw-r--r-- | randpkt_core/CMakeLists.txt | 10 | ||||
-rw-r--r-- | randpkt_core/randpkt_core.c | 52 | ||||
-rw-r--r-- | randpkt_core/randpkt_core.h | 9 |
3 files changed, 49 insertions, 22 deletions
diff --git a/randpkt_core/CMakeLists.txt b/randpkt_core/CMakeLists.txt index 7f17f3dc37..61c50f47f9 100644 --- a/randpkt_core/CMakeLists.txt +++ b/randpkt_core/CMakeLists.txt @@ -27,12 +27,16 @@ add_library(randpkt_core STATIC set_target_properties(randpkt_core PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}" FOLDER "Libs") +if(MSVC) + set_target_properties(randpkt_core PROPERTIES LINK_FLAGS_DEBUG "${WS_MSVC_DEBUG_LINK_FLAGS}") +endif() + +target_link_libraries(randpkt_core PUBLIC ui) CHECKAPI( NAME randpkt_core-base SWITCHES - -g deprecated-gtk SOURCES ${RANDPKT_CORE_SRC} ${RANDPKT_CORE_HEADERS} @@ -41,14 +45,14 @@ CHECKAPI( NAME randpkt_core-todo SWITCHES - -M -g deprecated-gtk-todo + -M SOURCES ${RANDPKT_CORE_SRC} ${RANDPKT_CORE_HEADERS} ) # -# Editor modelines - http://www.wireshark.org/tools/modelines.html +# Editor modelines - https://www.wireshark.org/tools/modelines.html # # Local variables: # c-basic-offset: 8 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, ¶ms, &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, ¶ms, &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 diff --git a/randpkt_core/randpkt_core.h b/randpkt_core/randpkt_core.h index 53dc042687..3a061465bc 100644 --- a/randpkt_core/randpkt_core.h +++ b/randpkt_core/randpkt_core.h @@ -1,4 +1,5 @@ -/* +/** @file + * * randpkt_core.h * --------- * Creates random packet traces. Useful for debugging sniffers by testing @@ -43,10 +44,10 @@ int randpkt_parse_type(char *string); randpkt_example* randpkt_find_example(int type); /* Init a new example */ -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); /* 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); @@ -54,7 +55,7 @@ gboolean randpkt_example_close(randpkt_example* example); #endif /* - * Editor modelines - http://www.wireshark.org/tools/modelines.html + * Editor modelines - https://www.wireshark.org/tools/modelines.html * * Local variables: * c-basic-offset: 8 |