aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2016-03-31 14:08:20 +0200
committerMichael Mann <mmann78@netscape.net>2016-04-01 00:33:09 +0000
commitc119296504b5258f9e44e23b298ea6b6394d6d92 (patch)
tree2b5d552303cf37c7766d1bcf8821e8c75f5c6ff9
parentf4bdaf9d15c2b4a8abd6e73389356af2aaa4bf99 (diff)
randpkt: restyle the list generation to get rid of the const compiler warning.
Change-Id: Id7c62ef18f919ba8a476898bc88c02fd3b6bf5a1 Reviewed-on: https://code.wireshark.org/review/14730 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
-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 663f7d3..da474ce 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 fa6f467..162e692 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 21739b0..85759af 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 f7633fc..b45554f 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);