randpktdump: add --delay option
[metze/wireshark/wip.git] / extcap / extcap-base.c
index 0e854d7c0cf7121cebe904dfeb19869c7525abfa..7d47aa41e5a46086a51c067ccf5911941dfa4b38 100644 (file)
@@ -7,19 +7,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
@@ -38,6 +26,7 @@
 #ifndef HAVE_GETOPT_LONG
     #include "wsutil/wsgetopt.h"
 #endif
+#include "ws_attributes.h"
 
 enum extcap_options {
     EXTCAP_BASE_OPTIONS_ENUM
@@ -182,6 +171,7 @@ uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char *
             extcap->do_list_interfaces = 1;
             break;
         case EXTCAP_OPT_VERSION:
+            extcap->ws_version = g_strdup(optargument);
             extcap->do_version = 1;
             break;
         case EXTCAP_OPT_LIST_DLTS:
@@ -299,22 +289,20 @@ static void extcap_help_option_free(gpointer option)
 
 void extcap_base_cleanup(extcap_parameters ** extcap)
 {
-    /* g_list_free_full() only exists since 2.28. g_list_free_full((*extcap)->interfaces, extcap_iface_free);*/
-    g_list_foreach((*extcap)->interfaces, (GFunc)extcap_iface_free, NULL);
-    g_list_free((*extcap)->interfaces);
+    g_list_free_full((*extcap)->interfaces, extcap_iface_free);
     g_free((*extcap)->exename);
     g_free((*extcap)->fifo);
     g_free((*extcap)->interface);
     g_free((*extcap)->version);
     g_free((*extcap)->helppage);
     g_free((*extcap)->help_header);
-    g_list_foreach((*extcap)->help_options, (GFunc)extcap_help_option_free, NULL);
-    g_list_free((*extcap)->help_options);
+    g_free((*extcap)->ws_version);
+    g_list_free_full((*extcap)->help_options, extcap_help_option_free);
     g_free(*extcap);
     *extcap = NULL;
 }
 
-static void extcap_print_option(gpointer option)
+static void extcap_print_option(gpointer option, gpointer user_data _U_)
 {
     extcap_option_t* o = (extcap_option_t*)option;
     printf("\t%s: %s\n", o->optname, o->optdesc);
@@ -327,7 +315,7 @@ void extcap_help_print(extcap_parameters * extcap)
     printf("%s", extcap->help_header);
     printf("\n");
     printf("Options:\n");
-    g_list_foreach(extcap->help_options, (GFunc)extcap_print_option, NULL);
+    g_list_foreach(extcap->help_options, extcap_print_option, NULL);
     printf("\n");
 }
 
@@ -357,6 +345,8 @@ void extcap_help_add_header(extcap_parameters * extcap, char * help_header)
 
 void extcap_init_custom_log(const char* filename)
 {
+    if (!filename || strlen(filename) == 0)
+        return;
     custom_log = fopen(filename, "w");
     if (!custom_log)
         g_error("Can't open custom log file: %s (%s)", filename, strerror(errno));
@@ -365,11 +355,11 @@ void extcap_init_custom_log(const char* filename)
 void extcap_config_debug(unsigned* count)
 {
     printf("arg {number=%u}{call=--debug}{display=Run in debug mode}"
-    "{type=boolean}{default=false}{tooltip=Print debug messages}\n",
-    (*count)++);
+    "{type=boolean}{default=false}{tooltip=Print debug messages}{required=false}"
+    "{group=Debug}\n", (*count)++);
     printf("arg {number=%u}{call=--debug-file}{display=Use a file for debug}"
-    "{type=string}{tooltip=Set a file where the debug messages are written}\n",
-    (*count)++);
+    "{type=string}{tooltip=Set a file where the debug messages are written}{required=false}"
+    "{group=Debug}\n", (*count)++);
 }
 
 void extcap_cmdline_debug(char** ar, const unsigned n)