Move some command-line-oriented routines from wsutil to ui.
[metze/wireshark/wip.git] / ui / cli / tap-diameter-avp.c
index 02106cd9f4aecabb5f6f1ec4547aeaa83c5150a2..f607ae23690fac0bf4291180daeba63bcfb1c1d8 100644 (file)
@@ -5,19 +5,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
  */
 
 /*
@@ -42,6 +30,9 @@
 
 #include <glib.h>
 
+#include <wsutil/strtoi.h>
+#include <ui/cmdarg_err.h>
+
 #include <epan/packet_info.h>
 #include <epan/tap.h>
 #include <epan/epan_dissect.h>
@@ -238,8 +229,16 @@ diameteravp_init(const char *opt_arg, void *userdata _U_)
        opt_count = 0;
        while (tokens[opt_count])
                opt_count++;
-       if (opt_count > 2)
-               ds->cmd_code = (guint32)atoi(tokens[2]);
+       if (opt_count > 2) {
+               /* if the token is a not-null string and it's not *, the conversion must succeeed */
+               if (strlen(tokens[2]) > 0 && tokens[2][0] != '*') {
+                       if (!ws_strtou32(tokens[2], NULL, &ds->cmd_code)) {
+                               fprintf(stderr, "Invalid integer token: %s\n", tokens[2]);
+                               g_strfreev(tokens);
+                               exit(1);
+                       }
+               }
+       }
 
        /* Loop over diameter field names. */
        for (opt_idx=3; opt_idx<opt_count; opt_idx++)
@@ -257,12 +256,12 @@ diameteravp_init(const char *opt_arg, void *userdata _U_)
        g_strfreev(tokens);
        ds->filter = g_string_free(filter, FALSE);
 
-       error_string = register_tap_listener("diameter", ds, ds->filter, 0, NULL, diameteravp_packet, diameteravp_draw);
+       error_string = register_tap_listener("diameter", ds, ds->filter, 0, NULL, diameteravp_packet, diameteravp_draw, NULL);
        if (error_string) {
                /* error, we failed to attach to the tap. clean up */
                g_free(ds);
 
-               fprintf(stderr, "tshark: Couldn't register diam,csv tap: %s\n",
+               cmdarg_err("Couldn't register diam,csv tap: %s",
                                error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);