Use cmdarg_err() to report errors in CLI taps.

Change-Id: Ic6b35220e394f8c67848ed067e4bbddb980d5bc0
Reviewed-on: https://code.wireshark.org/review/31253
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
This commit is contained in:
Guy Harris 2018-12-29 18:24:56 -08:00
parent b0da9cf6d4
commit aaf709da67
21 changed files with 68 additions and 37 deletions

View File

@ -24,6 +24,7 @@
#include "epan/timestats.h"
#include "epan/stat_tap_ui.h"
#include <wsutil/cmdarg_err.h>
void register_tap_listener_camelsrt(void);
@ -222,8 +223,7 @@ static void camelsrt_init(const char *opt_arg, void *userdata _U_)
g_free(p_camelsrt->filter);
g_free(p_camelsrt);
fprintf(stderr, "tshark: Couldn't register camel,srt tap: %s\n",
error_string->str);
cmdarg_err("Couldn't register camel,srt tap: %s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}

View File

@ -31,6 +31,7 @@
#include <glib.h>
#include <wsutil/strtoi.h>
#include <wsutil/cmdarg_err.h>
#include <epan/packet_info.h>
#include <epan/tap.h>
@ -260,7 +261,7 @@ diameteravp_init(const char *opt_arg, void *userdata _U_)
/* 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);

View File

@ -18,6 +18,7 @@
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <epan/conversation_table.h>
#include <wsutil/cmdarg_err.h>
#include <ui/cli/tshark-tap.h>
typedef struct _endpoints_t {
@ -111,7 +112,7 @@ void init_hostlists(struct register_ct *ct, const char *filter)
error_string = register_tap_listener(proto_get_protocol_filter_name(get_conversation_proto_id(ct)), &iu->hash, filter, 0, NULL, get_hostlist_packet_func(ct), endpoints_draw, NULL);
if (error_string) {
g_free(iu);
fprintf(stderr, "tshark: Couldn't register endpoint tap: %s\n",
cmdarg_err("Couldn't register endpoint tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -18,6 +18,7 @@
#include <string.h>
#include <wsutil/file_util.h>
#include <wsutil/cmdarg_err.h>
#include <epan/packet_info.h>
#include <epan/packet.h>
@ -125,7 +126,7 @@ gboolean eo_tap_opt_add(const char *option_string)
}
else
{
fprintf(stderr, "tshark: \"--export-objects\" already specified protocol '%s'\n", splitted[0]);
cmdarg_err("\"--export-objects\" already specified protocol '%s'", splitted[0]);
}
}
@ -220,7 +221,7 @@ exportobject_handler(gpointer key, gpointer value _U_, gpointer user_data _U_)
eo = get_eo_by_name((const char*)key);
if (eo == NULL)
{
fprintf(stderr, "tshark: \"--export-objects\" INTERNAL ERROR '%s' protocol not found\n", (const char*)key);
cmdarg_err("\"--export-objects\" INTERNAL ERROR '%s' protocol not found", (const char*)key);
return;
}
@ -238,7 +239,7 @@ exportobject_handler(gpointer key, gpointer value _U_, gpointer user_data _U_)
NULL, get_eo_packet_func(eo), eo_draw, NULL);
if (error_msg) {
fprintf(stderr, "tshark: Can't register %s tap: %s\n", (const char*)key, error_msg->str);
cmdarg_err("Can't register %s tap: %s", (const char*)key, error_msg->str);
g_string_free(error_msg, TRUE);
g_free(tap_data);
g_free(object_list);

View File

@ -21,6 +21,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/addr_resolv.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_hosts(void);
static gboolean dump_v4 = FALSE;
@ -104,7 +106,7 @@ hosts_init(const char *opt_arg, void *userdata _U_)
} else if (strcmp("ipv6", tokens[opt_count]) == 0) {
dump_v6 = TRUE;
} else if (opt_count > 0) {
fprintf(stderr, "tshark: invalid \"-z " TAP_NAME "[,ipv4|ipv6]\" argument\n");
cmdarg_err("invalid \"-z " TAP_NAME "[,ipv4|ipv6]\" argument");
exit(1);
}
opt_count++;
@ -116,7 +118,7 @@ hosts_init(const char *opt_arg, void *userdata _U_)
NULL, NULL, hosts_draw, NULL);
if (error_string) {
/* error, we failed to attach to the tap. clean up */
fprintf(stderr, "tshark: Couldn't register " TAP_NAME " tap: %s\n",
cmdarg_err("Couldn't register " TAP_NAME " tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -22,6 +22,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-http.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_httpstat(void);
/* used to keep track of the statictics for an entire program interface */
@ -318,7 +320,7 @@ httpstat_init(const char *opt_arg, void *userdata _U_)
/* error, we failed to attach to the tap. clean up */
g_free(sp->filter);
g_free(sp);
fprintf (stderr, "tshark: Couldn't register http,stat tap: %s\n",
cmdarg_err("Couldn't register http,stat tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -28,6 +28,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-icmp.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_icmpstat(void);
/* used to keep track of the ICMP statistics */
@ -265,7 +267,7 @@ icmpstat_init(const char *opt_arg, void *userdata _U_)
icmpstat = (icmpstat_t *)g_try_malloc(sizeof(icmpstat_t));
if (icmpstat == NULL) {
fprintf(stderr, "tshark: g_try_malloc() fatal error.\n");
cmdarg_err("Couldn't register icmp,srt tap: Out of memory");
exit(1);
}
memset(icmpstat, 0, sizeof(icmpstat_t));
@ -291,8 +293,7 @@ icmpstat_init(const char *opt_arg, void *userdata _U_)
g_free(icmpstat->filter);
g_free(icmpstat);
fprintf(stderr, "tshark: Couldn't register icmp,srt tap: %s\n",
error_string->str);
cmdarg_err("Couldn't register icmp,srt tap: %s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}

View File

@ -29,6 +29,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-icmp.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_icmpv6stat(void);
/* used to keep track of the ICMPv6 statistics */
@ -266,7 +268,7 @@ icmpv6stat_init(const char *opt_arg, void *userdata _U_)
icmpv6stat = (icmpv6stat_t *)g_try_malloc(sizeof(icmpv6stat_t));
if (icmpv6stat == NULL) {
fprintf(stderr, "tshark: g_try_malloc() fatal error.\n");
cmdarg_err("Couldn't register icmpv6,srt tap: Out of memory");
exit(1);
}
memset(icmpv6stat, 0, sizeof(icmpv6stat_t));
@ -291,8 +293,7 @@ icmpv6stat_init(const char *opt_arg, void *userdata _U_)
g_free(icmpv6stat->filter);
g_free(icmpv6stat);
fprintf(stderr, "tshark: Couldn't register icmpv6,srt tap: %s\n",
error_string->str);
cmdarg_err("Couldn't register icmpv6,srt tap: %s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}

View File

@ -16,6 +16,7 @@
#include <string.h>
#include <epan/packet.h>
#include <epan/timestamp.h>
#include <wsutil/cmdarg_err.h>
#include <ui/cli/tshark-tap.h>
typedef struct _io_users_t {
@ -225,7 +226,7 @@ void init_iousers(struct register_ct *ct, const char *filter)
error_string = register_tap_listener(proto_get_protocol_filter_name(get_conversation_proto_id(ct)), &iu->hash, filter, 0, NULL, get_conversation_packet_func(ct), iousers_draw, NULL);
if (error_string) {
g_free(iu);
fprintf(stderr, "tshark: Couldn't register conversations tap: %s\n",
cmdarg_err("Couldn't register conversations tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -21,6 +21,8 @@
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_protocolinfo(void);
typedef struct _pci_t {
@ -48,7 +50,7 @@ protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const vo
* and, if not, we report that error and exit.
*/
if (!col_get_writable(pinfo->cinfo, COL_INFO)) {
fprintf(stderr, "tshark: the proto,colinfo tap doesn't work if the INFO column isn't being printed.\n");
cmdarg_err("the proto,colinfo tap doesn't work if the INFO column isn't being printed.");
exit(1);
}
gp = proto_get_finfo_ptr_array(edt->tree, rs->hf_index);
@ -85,13 +87,13 @@ protocolinfo_init(const char *opt_arg, void *userdata _U_)
}
}
if (!field) {
fprintf(stderr, "tshark: invalid \"-z proto,colinfo,<filter>,<field>\" argument\n");
cmdarg_err("invalid \"-z proto,colinfo,<filter>,<field>\" argument");
exit(1);
}
hfi = proto_registrar_get_byname(field);
if (!hfi) {
fprintf(stderr, "tshark: Field \"%s\" doesn't exist.\n", field);
cmdarg_err("Field \"%s\" doesn't exist.", field);
exit(1);
}
@ -107,7 +109,7 @@ protocolinfo_init(const char *opt_arg, void *userdata _U_)
error_string = register_tap_listener("frame", rs, rs->filter, TL_REQUIRES_PROTO_TREE, NULL, protocolinfo_packet, NULL, NULL);
if (error_string) {
/* error, we failed to attach to the tap. complain and clean up */
fprintf(stderr, "tshark: Couldn't register proto,colinfo tap: %s\n",
cmdarg_err("Couldn't register proto,colinfo tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
g_free(rs->filter);

View File

@ -20,6 +20,8 @@
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_protohierstat(void);
typedef struct _phs_t {
@ -167,7 +169,7 @@ protohierstat_init(const char *opt_arg, void *userdata _U_)
filter = opt_arg+pos;
}
} else {
fprintf(stderr, "tshark: invalid \"-z io,phs[,<filter>]\" argument\n");
cmdarg_err("invalid \"-z io,phs[,<filter>]\" argument");
exit(1);
}
@ -180,7 +182,7 @@ protohierstat_init(const char *opt_arg, void *userdata _U_)
g_free(rs->filter);
g_free(rs);
fprintf(stderr, "tshark: Couldn't register io,phs tap: %s\n",
cmdarg_err("Couldn't register io,phs tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -25,6 +25,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-rpc.h>
#include <wsutil/cmdarg_err.h>
#define MICROSECS_PER_SEC 1000000
#define NANOSECS_PER_SEC 1000000000
@ -208,7 +210,7 @@ rpcprogs_init(const char *opt_arg _U_, void *userdata _U_)
error_string = register_tap_listener("rpc", NULL, NULL, 0, NULL, rpcprogs_packet, rpcprogs_draw, NULL);
if (error_string) {
fprintf(stderr, "tshark: Couldn't register rpc,programs tap: %s\n",
cmdarg_err("Couldn't register rpc,programs tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -19,6 +19,7 @@
#include <epan/rtd_table.h>
#include <epan/timestamp.h>
#include <epan/stat_tap_ui.h>
#include <wsutil/cmdarg_err.h>
#include <ui/cli/tshark-tap.h>
typedef struct _rtd_t {
@ -104,7 +105,7 @@ init_rtd_tables(register_rtd_t* rtd, const char *filter)
error_string = register_tap_listener(get_rtd_tap_listener_name(rtd), &ui->rtd, filter, 0, NULL, get_rtd_packet_func(rtd), rtd_draw, NULL);
if (error_string) {
free_rtd_table(&ui->rtd.stat_table);
fprintf(stderr, "tshark: Couldn't register srt tap: %s\n", error_string->str);
cmdarg_err("Couldn't register srt tap: %s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
@ -120,7 +121,7 @@ dissector_rtd_init(const char *opt_arg, void* userdata)
rtd_table_get_filter(rtd, opt_arg, &filter, &err);
if (err != NULL)
{
fprintf(stderr, "tshark: %s\n", err);
cmdarg_err("%s", err);
g_free(err);
exit(1);
}

View File

@ -25,6 +25,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-rtsp.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_rtspstat(void);
/* used to keep track of the statictics for an entire program interface */
@ -247,7 +249,7 @@ rtspstat_init(const char *opt_arg, void *userdata _U_)
/* error, we failed to attach to the tap. clean up */
g_free(sp->filter);
g_free(sp);
fprintf (stderr, "tshark: Couldn't register rtsp,stat tap: %s\n",
cmdarg_err("Couldn't register rtsp,stat tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -24,6 +24,8 @@
#include <epan/dissectors/packet-sctp.h>
#include <epan/to_str.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_sctpstat(void);
typedef struct sctp_ep {
@ -205,7 +207,7 @@ sctpstat_init(const char *opt_arg, void *userdata _U_)
g_free(hs->filter);
g_free(hs);
fprintf(stderr, "tshark: Couldn't register sctp,stat tap: %s\n",
cmdarg_err("Couldn't register sctp,stat tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -16,6 +16,7 @@
#include <epan/packet.h>
#include <epan/timestamp.h>
#include <epan/stat_tap_ui.h>
#include <wsutil/cmdarg_err.h>
#include <ui/cli/tshark-tap.h>
typedef struct _table_stat_t {
@ -104,7 +105,7 @@ init_stat_table(stat_tap_table_ui *stat_tap, const char *filter)
error_string = register_tap_listener(stat_tap->tap_name, &ui->stats, filter, 0, NULL, stat_tap->packet_func, simple_draw, NULL);
if (error_string) {
/* free_rtd_table(&ui->rtd.stat_table); */
fprintf(stderr, "tshark: Couldn't register tap: %s\n", error_string->str);
cmdarg_err("Couldn't register tap: %s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
@ -120,7 +121,7 @@ simple_stat_init(const char *opt_arg, void* userdata)
stat_tap_get_filter(stat_tap, opt_arg, &filter, &err);
if (err != NULL)
{
fprintf(stderr, "tshark: %s\n", err);
cmdarg_err("%s", err);
g_free(err);
exit(1);
}

View File

@ -24,6 +24,8 @@
#include <epan/value_string.h>
#include <epan/dissectors/packet-sip.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_sipstat(void);
/* used to keep track of the statictics for an entire program interface */
@ -427,7 +429,7 @@ sipstat_init(const char *opt_arg, void *userdata _U_)
/* error, we failed to attach to the tap. clean up */
g_free(sp->filter);
g_free(sp);
fprintf (stderr, "tshark: Couldn't register sip,stat tap: %s\n",
cmdarg_err("Couldn't register sip,stat tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -23,6 +23,8 @@
#include <epan/value_string.h>
#include <epan/dissectors/packet-smb.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_smbsids(void);
static int
@ -68,7 +70,7 @@ smbsids_init(const char *opt_arg _U_, void *userdata _U_)
error_string = register_tap_listener("smb", NULL, NULL, 0, NULL, smbsids_packet, smbsids_draw, NULL);
if (error_string) {
fprintf(stderr, "tshark: Couldn't register smb,sids tap:%s\n",
cmdarg_err("Couldn't register smb,sids tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -17,6 +17,7 @@
#include <epan/srt_table.h>
#include <epan/timestamp.h>
#include <epan/stat_tap_ui.h>
#include <wsutil/cmdarg_err.h>
#include <ui/cli/tshark-tap.h>
#define NANOSECS_PER_SEC 1000000000
@ -118,7 +119,7 @@ init_srt_tables(register_srt_t* srt, const char *filter)
if (error_string) {
free_srt_table(srt, global_srt_array);
g_free(ui);
fprintf(stderr, "tshark: Couldn't register srt tap: %s\n", error_string->str);
cmdarg_err("Couldn't register srt tap: %s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
@ -135,7 +136,7 @@ dissector_srt_init(const char *opt_arg, void* userdata)
if (err != NULL)
{
gchar* cmd_str = srt_table_get_tap_string(srt);
fprintf(stderr, "tshark: invalid \"-z %s,%s\" argument\n", cmd_str, err);
cmdarg_err("invalid \"-z %s,%s\" argument", cmd_str, err);
g_free(cmd_str);
g_free(err);
exit(1);

View File

@ -22,6 +22,8 @@
#include <epan/stat_tap_ui.h>
#include <epan/dissectors/packet-sv.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_sv(void);
static int
@ -57,7 +59,7 @@ svstat_init(const char *opt_arg _U_, void *userdata _U_)
NULL);
if (error_string) {
/* error, we failed to attach to the tap. clean up */
fprintf(stderr, "tshark: Couldn't register sv,stat tap: %s\n",
cmdarg_err("Couldn't register sv,stat tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);

View File

@ -1,4 +1,4 @@
/* tap-rpcstat.c
/* tap-wspstat.c
* wspstat 2003 Jean-Michel FAYARD
*
* Wireshark - Network traffic analyzer
@ -27,6 +27,8 @@
#include <epan/value_string.h>
#include <epan/dissectors/packet-wsp.h>
#include <wsutil/cmdarg_err.h>
void register_tap_listener_wspstat(void);
/* used to keep track of the stats for a specific PDU type*/
@ -255,7 +257,7 @@ wspstat_init(const char *opt_arg, void *userdata _U_)
g_hash_table_foreach( sp->hash, (GHFunc) wsp_free_hash_table, NULL ) ;
g_hash_table_destroy( sp->hash );
g_free(sp);
fprintf(stderr, "tshark: Couldn't register wsp,stat tap: %s\n",
cmdarg_err("Couldn't register wsp,stat tap: %s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);