summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extcap/randpktdump.c33
-rw-r--r--randpkt.c18
-rw-r--r--randpkt_core/randpkt_core.c15
-rw-r--r--randpkt_core/randpkt_core.h2
4 files changed, 36 insertions, 32 deletions
diff --git a/extcap/randpktdump.c b/extcap/randpktdump.c
index 663f7d3444..da474ce930 100644
--- a/extcap/randpktdump.c
+++ b/extcap/randpktdump.c
@@ -65,10 +65,9 @@ static struct option longopts[] = {
static void help(const char* binname)
{
- unsigned i;
- const char** abbrev_list;
- const char** longname_list;
- unsigned list_num;
+ unsigned i = 0;
+ char** abbrev_list;
+ char** longname_list;
printf("Help\n");
printf(" Usage:\n");
@@ -94,22 +93,23 @@ static void help(const char* binname)
printf(" --all-random: a random type is chosen for each packet\n");
printf(" --type <type>: the packet type\n");
printf("\n\nPacket types:\n");
- randpkt_example_list(&abbrev_list, &longname_list, &list_num);
- for (i = 0; i < list_num; i++) {
+ randpkt_example_list(&abbrev_list, &longname_list);
+ while (abbrev_list[i] && longname_list[i]) {
printf("\t%-16s%s\n", abbrev_list[i], longname_list[i]);
+ i++;
}
- g_free((char**)abbrev_list);
- g_free((char**)longname_list);
+ printf("\n");
+ g_strfreev(abbrev_list);
+ g_strfreev(longname_list);
}
static int list_config(char *interface)
{
unsigned inc = 0;
- unsigned i;
- const char** abbrev_list;
- const char** longname_list;
- unsigned list_num;
+ unsigned i = 0;
+ char** abbrev_list;
+ char** longname_list;
if (!interface) {
errmsg_print("ERROR: No interface specified.");
@@ -138,12 +138,13 @@ static int list_config(char *interface)
printf("arg {number=%u}{call=--type}{display=Type of packet}"
"{type=selector}{tooltip=Type of packet to generate}\n",
inc);
- randpkt_example_list(&abbrev_list, &longname_list, &list_num);
- for (i = 0; i < list_num; i++) {
+ randpkt_example_list(&abbrev_list, &longname_list);
+ while (abbrev_list[i] && longname_list[i]) {
printf("value {arg=%u}{value=%s}{display=%s}\n", inc, abbrev_list[i], longname_list[i]);
+ i++;
}
- g_free((char**)abbrev_list);
- g_free((char**)longname_list);
+ g_strfreev(abbrev_list);
+ g_strfreev(longname_list);
inc++;
return EXIT_SUCCESS;
diff --git a/randpkt.c b/randpkt.c
index fa6f467eba..162e692e66 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -22,6 +22,7 @@
*/
#include <glib.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <wsutil/ws_diag_control.h>
@@ -63,10 +64,9 @@ static void
usage(gboolean is_error)
{
FILE *output;
- const char** abbrev_list;
- const char** longname_list;
- unsigned list_num;
- unsigned i;
+ char** abbrev_list;
+ char** longname_list;
+ unsigned i = 0;
if (!is_error) {
output = stdout;
@@ -83,12 +83,14 @@ usage(gboolean is_error)
fprintf(output, "Types:\n");
/* Get the examples list */
- randpkt_example_list(&abbrev_list, &longname_list, &list_num);
- for (i = 0; i < list_num; i++) {
+ randpkt_example_list(&abbrev_list, &longname_list);
+ while (abbrev_list[i] && longname_list[i]) {
fprintf(output, "\t%-16s%s\n", abbrev_list[i], longname_list[i]);
+ i++;
}
- g_free((char**)abbrev_list);
- g_free((char**)longname_list);
+
+ g_strfreev(abbrev_list);
+ g_strfreev(longname_list);
fprintf(output, "\nIf type is not specified, a random packet will be chosen\n\n");
diff --git a/randpkt_core/randpkt_core.c b/randpkt_core/randpkt_core.c
index 21739b082a..85759afb52 100644
--- a/randpkt_core/randpkt_core.c
+++ b/randpkt_core/randpkt_core.c
@@ -779,15 +779,16 @@ int randpkt_parse_type(char *string)
return -1;
}
-void randpkt_example_list(const char*** abbrev_list, const char*** longname_list, unsigned* list_num)
+void randpkt_example_list(char*** abbrev_list, char*** longname_list)
{
unsigned i;
- *list_num = randpkt_example_count();
- *abbrev_list = g_new0(const char*, *list_num);
- *longname_list = g_new0(const char*, *list_num);
- for (i = 0; i < *list_num; i++) {
- (*abbrev_list)[i] = examples[i].abbrev;
- (*longname_list)[i] = examples[i].longname;
+ unsigned list_num;
+ list_num = randpkt_example_count();
+ *abbrev_list = g_new0(char*, list_num + 1);
+ *longname_list = g_new0(char*, list_num + 1);
+ for (i = 0; i < list_num; i++) {
+ (*abbrev_list)[i] = g_strdup(examples[i].abbrev);
+ (*longname_list)[i] = g_strdup(examples[i].longname);
}
}
diff --git a/randpkt_core/randpkt_core.h b/randpkt_core/randpkt_core.h
index f7633fc048..b45554f5c1 100644
--- a/randpkt_core/randpkt_core.h
+++ b/randpkt_core/randpkt_core.h
@@ -48,7 +48,7 @@ typedef struct {
guint randpkt_example_count(void);
/* Return the list of the active examples */
-void randpkt_example_list(const char*** abbrev_list, const char*** longname_list, unsigned* list_num);
+void randpkt_example_list(char*** abbrev_list, char*** longname_list);
/* Seed the random-number generator */
void randpkt_seed(void);