Add more error-reporting routines that call through a function pointer.

Have routines to report capture-file errors, using libwireshark error
codes and strings, that call through a pointer, so they can pop up
dialogs in GUI apps, print a message to the standard error on
command-line apps, and possibly do something different on server
programs.

Have init_report_message() take a pointer to structure containing those
function pointers, rather than the function pointers themselves, as
arguments.

Make other API changes to make that work.
pespin/rlcmac
Guy Harris 2021-03-15 11:29:43 -07:00
parent 89ae76d300
commit c33e2f7b51
23 changed files with 521 additions and 421 deletions

View File

@ -1193,7 +1193,7 @@ process_cap_file(const char *filename, gboolean need_separator)
cf_info.wth = wtap_open_offline(filename, WTAP_TYPE_AUTO, &err, &err_info, FALSE);
if (!cf_info.wth) {
cfile_open_failure_message("capinfos", filename, err, err_info);
cfile_open_failure_message(filename, err, err_info);
return 2;
}
@ -1352,7 +1352,7 @@ process_cap_file(const char *filename, gboolean need_separator)
fprintf(stderr,
"capinfos: An error occurred after reading %u packets from \"%s\".\n",
packet, filename);
cfile_read_failure_message("capinfos", filename, err, err_info);
cfile_read_failure_message(filename, err, err_info);
if (err == WTAP_ERR_SHORT_READ) {
/* Don't give up completely with this one. */
status = 1;
@ -1511,11 +1511,10 @@ print_usage(FILE *output)
}
/*
* General errors and warnings are reported with an console message
* in capinfos.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
capinfos_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "capinfos: ");
vfprintf(stderr, msg_format, ap);
@ -1526,7 +1525,7 @@ failure_warning_message(const char *msg_format, va_list ap)
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
capinfos_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
@ -1545,6 +1544,18 @@ int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines capinfos_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
gboolean need_separator = FALSE;
int opt;
int overall_error_status = EXIT_SUCCESS;
@ -1570,7 +1581,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(capinfos_cmdarg_err, capinfos_cmdarg_err_cont);
/* Get the decimal point. */
decimal_point = g_strdup(localeconv()->decimal_point);
@ -1599,8 +1610,7 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
NULL, NULL, NULL);
init_report_message("capinfos", &capinfos_report_routines);
wtap_init(TRUE);

View File

@ -61,11 +61,10 @@ print_usage(FILE *output)
}
/*
* General errors and warnings are reported with an console message
* in captype.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
captype_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "captype: ");
vfprintf(stderr, msg_format, ap);
@ -76,7 +75,7 @@ failure_warning_message(const char *msg_format, va_list ap)
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
captype_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
@ -86,6 +85,18 @@ int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines captype_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
wtap *wth;
int err;
gchar *err_info;
@ -108,7 +119,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(captype_cmdarg_err, captype_cmdarg_err_cont);
/* Initialize the version information. */
ws_init_version_info("Captype (Wireshark)", NULL, NULL, NULL);
@ -134,8 +145,7 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
NULL, NULL, NULL);
init_report_message("captype", &captype_report_routines);
wtap_init(TRUE);
@ -179,7 +189,7 @@ main(int argc, char *argv[])
if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
printf("%s: unknown\n", argv[i]);
else {
cfile_open_failure_message("captype", argv[i], err, err_info);
cfile_open_failure_message(argv[i], err, err_info);
overall_error_status = 2; /* remember that an error has occurred */
}
}

View File

@ -80,6 +80,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
get_datafile_path@Base 1.12.0~rc1
get_dirname@Base 1.12.0~rc1
get_extcap_dir@Base 1.99.0
get_friendly_program_name@Base 3.5.0
get_global_profiles_dir@Base 1.12.0~rc1
get_os_version_info@Base 1.99.0
get_persconffile_path@Base 1.12.0~rc1
@ -160,6 +161,11 @@ libwsutil.so.0 libwsutil0 #MINVER#
register_codec@Base 3.1.0
relinquish_special_privs_perm@Base 1.10.0
rename_persconffile_profile@Base 1.12.0~rc1
report_cfile_close_failure@Base 3.5.0
report_cfile_dump_open_failure@Base 3.5.0
report_cfile_open_failure@Base 3.5.0
report_cfile_read_failure@Base 3.5.0
report_cfile_write_failure@Base 3.5.0
report_failure@Base 1.12.0~rc1
report_open_failure@Base 1.12.0~rc1
report_read_failure@Base 1.12.0~rc1

View File

@ -33,21 +33,34 @@
#include <wiretap/wtap.h>
#include "ui/util.h"
#include "ui/cmdarg_err.h"
#include "ui/failure_message.h"
static void failure_warning_message(const char *msg_format, va_list ap);
static void open_failure_message(const char *filename, int err,
gboolean for_writing);
static void read_failure_message(const char *filename, int err);
static void write_failure_message(const char *filename, int err);
static void dftest_cmdarg_err(const char *fmt, va_list ap);
static void dftest_cmdarg_err_cont(const char *fmt, va_list ap);
int
main(int argc, char **argv)
{
char *init_progfile_dir_error;
static const struct report_message_routines dftest_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
char *text;
dfilter_t *df;
gchar *err_msg;
cmdarg_err_init(dftest_cmdarg_err, dftest_cmdarg_err_cont);
/*
* Get credential information for later use.
*/
@ -64,9 +77,7 @@ main(int argc, char **argv)
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
open_failure_message, read_failure_message,
write_failure_message);
init_report_message("dftest", &dftest_report_routines);
timestamp_set_type(TS_RELATIVE);
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
@ -137,48 +148,26 @@ main(int argc, char **argv)
}
/*
* General errors and warnings are reported with an console message
* in "dftest".
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
dftest_cmdarg_err(const char *fmt, va_list ap)
{
fprintf(stderr, "dftest: ");
vfprintf(stderr, msg_format, ap);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
/*
* Open/create errors are reported with an console message in "dftest".
* Report additional information for an error in command-line arguments.
*/
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
dftest_cmdarg_err_cont(const char *fmt, va_list ap)
{
fprintf(stderr, "dftest: ");
fprintf(stderr, file_open_error_message(err, for_writing), filename);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
/*
* Read errors are reported with an console message in "dftest".
*/
static void
read_failure_message(const char *filename, int err)
{
fprintf(stderr, "dftest: An error occurred while reading from the file \"%s\": %s.\n",
filename, g_strerror(err));
}
/*
* Write errors are reported with an console message in "dftest".
*/
static void
write_failure_message(const char *filename, int err)
{
fprintf(stderr, "dftest: An error occurred while writing to the file \"%s\": %s.\n",
filename, g_strerror(err));
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*

View File

@ -970,11 +970,10 @@ framenum_compare(gconstpointer a, gconstpointer b, gpointer user_data _U_)
}
/*
* General errors and warnings are reported with an console message
* in editcap.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
editcap_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "editcap: ");
vfprintf(stderr, msg_format, ap);
@ -985,7 +984,7 @@ failure_warning_message(const char *msg_format, va_list ap)
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
editcap_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
@ -1078,6 +1077,18 @@ int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines editcap_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
wtap *wth = NULL;
int i, j, read_err, write_err;
gchar *read_err_info, *write_err_info;
@ -1141,7 +1152,7 @@ main(int argc, char *argv[])
gboolean valid_seed = FALSE;
unsigned int seed = 0;
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(editcap_cmdarg_err, editcap_cmdarg_err_cont);
#ifdef _WIN32
create_app_running_mutex();
@ -1167,8 +1178,7 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
NULL, NULL, NULL);
init_report_message("editcap", &editcap_report_routines);
wtap_init(TRUE);
@ -1546,8 +1556,7 @@ main(int argc, char *argv[])
wth = wtap_open_offline(argv[optind], WTAP_TYPE_AUTO, &read_err, &read_err_info, FALSE);
if (!wth) {
cfile_open_failure_message("editcap", argv[optind], read_err,
read_err_info);
cfile_open_failure_message(argv[optind], read_err, read_err_info);
ret = INVALID_FILE;
goto clean_exit;
}
@ -1733,7 +1742,7 @@ main(int argc, char *argv[])
&write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
cfile_dump_open_failure_message(filename,
write_err, write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;
@ -1745,8 +1754,7 @@ main(int argc, char *argv[])
* Process whatever IDBs we haven't seen yet.
*/
if (!process_new_idbs(wth, pdh, idbs_seen, &write_err, &write_err_info)) {
cfile_write_failure_message("editcap", argv[optind],
filename,
cfile_write_failure_message(argv[optind], filename,
write_err, write_err_info,
read_count,
out_file_type_subtype);
@ -1786,7 +1794,7 @@ main(int argc, char *argv[])
&write_err, &write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
cfile_dump_open_failure_message(filename,
write_err,
write_err_info,
out_file_type_subtype);
@ -1817,7 +1825,7 @@ main(int argc, char *argv[])
pdh = editcap_dump_open(filename, &params, idbs_seen,
&write_err, &write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
cfile_dump_open_failure_message(filename,
write_err, write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;
@ -2191,8 +2199,7 @@ main(int argc, char *argv[])
/* Attempt to dump out current frame to the output file */
if (!wtap_dump(pdh, rec, buf, &write_err, &write_err_info)) {
cfile_write_failure_message("editcap", argv[optind],
filename,
cfile_write_failure_message(argv[optind], filename,
write_err, write_err_info,
read_count,
out_file_type_subtype);
@ -2212,8 +2219,7 @@ main(int argc, char *argv[])
if (read_err != 0) {
/* Print a message noting that the read failed somewhere along the
* line. */
cfile_read_failure_message("editcap", argv[optind], read_err,
read_err_info);
cfile_read_failure_message(argv[optind], read_err, read_err_info);
}
if (!pdh) {
@ -2225,7 +2231,7 @@ main(int argc, char *argv[])
pdh = editcap_dump_open(filename, &params, idbs_seen, &write_err,
&write_err_info);
if (pdh == NULL) {
cfile_dump_open_failure_message("editcap", filename,
cfile_dump_open_failure_message(filename,
write_err, write_err_info,
out_file_type_subtype);
ret = INVALID_FILE;

View File

@ -21,6 +21,7 @@
#include <wsutil/strtoi.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
#include <wsutil/report_message.h>
#include <wsutil/please_report_bug.h>
#include <ui/cmdarg_err.h>
#include <wsutil/inet_addr.h>
@ -359,7 +360,7 @@ static const char* interface_to_logbuf(char* interface)
* g_logv() with the appropriate arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
androiddump_cmdarg_err(const char *msg_format, va_list ap)
{
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, msg_format, ap);
}
@ -459,12 +460,12 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
file_type_subtype = wtap_pcap_nsec_file_type_subtype();
extcap_dumper.dumper.wtap = wtap_dump_open(fifo, file_type_subtype, WTAP_UNCOMPRESSED, &params, &err, &err_info);
if (!extcap_dumper.dumper.wtap) {
cfile_dump_open_failure_message("androiddump", fifo, err, err_info, file_type_subtype);
cfile_dump_open_failure_message(fifo, err, err_info, file_type_subtype);
exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
}
extcap_dumper.encap = encap;
if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
cfile_dump_open_failure_message("androiddump", fifo, err, NULL, file_type_subtype);
cfile_dump_open_failure_message(fifo, err, NULL, file_type_subtype);
exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
}
#endif
@ -522,13 +523,13 @@ static gboolean extcap_dumper_dump(struct extcap_dumper extcap_dumper,
rec.rec_header.packet_header.pkt_encap = extcap_dumper.encap;
if (!wtap_dump(extcap_dumper.dumper.wtap, &rec, (const guint8 *) buffer, &err, &err_info)) {
cfile_write_failure_message("androiddump", NULL, fifo, err, err_info, 0,
cfile_write_failure_message(NULL, fifo, err, err_info, 0,
wtap_dump_file_type_subtype(extcap_dumper.dumper.wtap));
return FALSE;
}
if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
cfile_write_failure_message("androiddump", NULL, fifo, err, NULL, 0,
cfile_write_failure_message(NULL, fifo, err, NULL, 0,
wtap_dump_file_type_subtype(extcap_dumper.dumper.wtap));
return FALSE;
}
@ -2490,6 +2491,18 @@ static int capture_android_tcpdump(char *interface, char *fifo,
int main(int argc, char *argv[]) {
char *err_msg;
static const struct report_message_routines androiddummp_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
int ret = EXIT_CODE_GENERIC;
int option_idx = 0;
int result;
@ -2514,7 +2527,7 @@ int main(int argc, char *argv[]) {
char *help_url;
char *help_header = NULL;
cmdarg_err_init(failure_warning_message, failure_warning_message);
cmdarg_err_init(androiddump_cmdarg_err, androiddump_cmdarg_err);
/*
* Get credential information for later use.
@ -2532,6 +2545,8 @@ int main(int argc, char *argv[]) {
g_free(err_msg);
}
init_report_message("androiddump", &androiddummp_report_routines);
extcap_conf = g_new0(extcap_parameters, 1);
help_url = data_file_url("androiddump.html");

View File

@ -125,7 +125,7 @@ static int list_config(char *interface)
return EXIT_SUCCESS;
}
static void failure_warning_message(const char *msg_format, va_list ap)
static void randpktdump_cmdarg_err(const char *msg_format, va_list ap)
{
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, msg_format, ap);
}
@ -150,7 +150,7 @@ int main(int argc, char *argv[])
char* help_url;
char* help_header = NULL;
cmdarg_err_init(failure_warning_message, failure_warning_message);
cmdarg_err_init(randpktdump_cmdarg_err, randpktdump_cmdarg_err);
/*
* Get credential information for later use.

View File

@ -1,4 +1,4 @@
/* oss-fuzzshark.c
/* fuzzshark.c
*
* Fuzzer variant of Wireshark for oss-fuzz
*
@ -21,6 +21,7 @@
#include <epan/epan.h>
#include <ui/cmdarg_err.h>
#include <ui/failure_message.h>
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
#include <wsutil/report_message.h>
@ -49,51 +50,21 @@ static epan_t *fuzz_epan;
static epan_dissect_t *fuzz_edt;
/*
* General errors and warnings are reported with an console message
* in oss-fuzzshark.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
fuzzshark_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "oss-fuzzshark: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
/*
* Open/create errors are reported with an console message in oss-fuzzshark.
*/
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
{
fprintf(stderr, "oss-fuzzshark: ");
fprintf(stderr, file_open_error_message(err, for_writing), filename);
fprintf(stderr, "\n");
}
/*
* Read errors are reported with an console message in oss-fuzzshark.
*/
static void
read_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while reading from the file \"%s\": %s.", filename, g_strerror(err));
}
/*
* Write errors are reported with an console message in oss-fuzzshark.
*/
static void
write_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while writing to the file \"%s\": %s.", filename, g_strerror(err));
}
/*
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
fuzzshark_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
@ -181,6 +152,19 @@ fuzz_init(int argc _U_, char **argv)
{
char *init_progfile_dir_error;
static const struct report_message_routines fuzzshark_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
char *err_msg = NULL;
e_prefs *prefs_p;
int ret = EXIT_SUCCESS;
@ -250,7 +234,7 @@ fuzz_init(int argc _U_, char **argv)
g_setenv("WIRESHARK_DEBUG_WMEM_OVERRIDE", "simple", 0);
g_setenv("G_SLICE", "always-malloc", 0);
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(fuzzshark_cmdarg_err, fuzzshark_cmdarg_err_cont);
/*
* Get credential information for later use, and drop privileges
@ -273,8 +257,7 @@ fuzz_init(int argc _U_, char **argv)
ws_init_version_info("OSS Fuzzshark (Wireshark)", NULL,
epan_get_compiled_version_info, epan_get_runtime_version_info);
init_report_message(failure_warning_message, failure_warning_message,
open_failure_message, read_failure_message, write_failure_message);
init_report_message("fuzzshark", &fuzzshark_report_routines);
timestamp_set_type(TS_RELATIVE);
timestamp_set_precision(TS_PREC_AUTO);

View File

@ -101,18 +101,6 @@ mergecap_cmdarg_err_cont(const char *fmt, va_list ap)
fprintf(stderr, "\n");
}
/*
* General errors and warnings are reported with an console message
* in mergecap.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
{
fprintf(stderr, "mergecap: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
static void
list_capture_types(void) {
GArray *writable_type_subtypes;
@ -206,6 +194,18 @@ int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines mergecap_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
int opt;
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
@ -252,8 +252,7 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
NULL, NULL, NULL);
init_report_message("mergecap", &mergecap_report_routines);
wtap_init(TRUE);
@ -393,18 +392,15 @@ main(int argc, char *argv[])
break;
case MERGE_ERR_CANT_OPEN_INFILE:
cfile_open_failure_message("mergecap", argv[optind + err_fileno],
err, err_info);
cfile_open_failure_message(argv[optind + err_fileno], err, err_info);
break;
case MERGE_ERR_CANT_OPEN_OUTFILE:
cfile_dump_open_failure_message("mergecap", out_filename, err, err_info,
file_type);
cfile_dump_open_failure_message(out_filename, err, err_info, file_type);
break;
case MERGE_ERR_CANT_READ_INFILE:
cfile_read_failure_message("mergecap", argv[optind + err_fileno],
err, err_info);
cfile_read_failure_message(argv[optind + err_fileno], err, err_info);
break;
case MERGE_ERR_BAD_PHDR_INTERFACE_ID:
@ -413,9 +409,8 @@ main(int argc, char *argv[])
break;
case MERGE_ERR_CANT_WRITE_OUTFILE:
cfile_write_failure_message("mergecap", argv[optind + err_fileno],
out_filename, err, err_info, err_framenum,
file_type);
cfile_write_failure_message(argv[optind + err_fileno], out_filename,
err, err_info, err_framenum, file_type);
break;
case MERGE_ERR_CANT_CLOSE_OUTFILE:

View File

@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ui/clopts_common.h>
#include <ui/failure_message.h>
#include <ui/cmdarg_err.h>
#include <wsutil/file_util.h>
#include <wsutil/filesystem.h>
@ -48,11 +49,10 @@
#define CLOSE_ERROR 2
/*
* General errors and warnings are reported with an console message
* in randpkt.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
randpkt_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "randpkt: ");
vfprintf(stderr, msg_format, ap);
@ -63,7 +63,7 @@ failure_warning_message(const char *msg_format, va_list ap)
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
randpkt_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
@ -109,6 +109,18 @@ int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines randpkt_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
int opt;
int produce_type = -1;
char *produce_filename = NULL;
@ -141,12 +153,11 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
NULL, NULL, NULL);
init_report_message("randpkt", &randpkt_report_routines);
wtap_init(TRUE);
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(randpkt_cmdarg_err, randpkt_cmdarg_err_cont);
#ifdef _WIN32
create_app_running_mutex();

View File

@ -620,14 +620,14 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count, guint64 packe
}
if (!wtap_dump(example->dump, rec, buffer, &err, &err_info)) {
cfile_write_failure_message("randpkt", NULL,
cfile_write_failure_message(NULL,
example->filename, err, err_info, 0,
wtap_dump_file_type_subtype(example->dump));
}
if (packet_delay_ms) {
g_usleep(1000 * (gulong)packet_delay_ms);
if (!wtap_dump_flush(example->dump, &err)) {
cfile_write_failure_message("randpkt", NULL,
cfile_write_failure_message(NULL,
example->filename, err, NULL, 0,
wtap_dump_file_type_subtype(example->dump));
}
@ -683,7 +683,7 @@ int randpkt_example_init(randpkt_example* example, char* produce_filename, int p
example->filename = produce_filename;
}
if (!example->dump) {
cfile_dump_open_failure_message("randpkt", produce_filename,
cfile_dump_open_failure_message(produce_filename,
err, err_info, file_type_subtype);
return WRITE_ERROR;
}

View File

@ -144,11 +144,6 @@ static gboolean process_packet(capture_file *cf, epan_dissect_t *edt, gint64 off
wtap_rec *rec, Buffer *buf);
static void show_print_file_io_error(int err);
static void failure_warning_message(const char *msg_format, va_list ap);
static void open_failure_message(const char *filename, int err,
gboolean for_writing);
static void read_failure_message(const char *filename, int err);
static void write_failure_message(const char *filename, int err);
static void rawshark_cmdarg_err(const char *fmt, va_list ap);
static void rawshark_cmdarg_err_cont(const char *fmt, va_list ap);
static void protocolinfo_init(char *field);
@ -437,6 +432,18 @@ main(int argc, char *argv[])
#define OPTSTRING_INIT "d:F:hlm:nN:o:pr:R:sS:t:v"
static const char optstring[] = OPTSTRING_INIT;
static const struct report_message_routines rawshark_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
/*
* Set the C-language locale to the native environment and set the
@ -501,9 +508,7 @@ main(int argc, char *argv[])
(GLogLevelFlags)log_flags,
log_func_ignore, NULL /* user_data */);
init_report_message(failure_warning_message, failure_warning_message,
open_failure_message, read_failure_message,
write_failure_message);
init_report_message("rawshark", &rawshark_report_routines);
timestamp_set_type(TS_RELATIVE);
timestamp_set_precision(TS_PREC_AUTO);
@ -966,7 +971,7 @@ load_cap_file(capture_file *cf)
ws_buffer_free(&buf);
if (err != 0) {
/* Print a message noting that the read failed somewhere along the line. */
cfile_read_failure_message("Rawshark", cf->filename, err, err_info);
cfile_read_failure_message(cf->filename, err, err_info);
return FALSE;
}
@ -1431,29 +1436,6 @@ show_print_file_io_error(int err)
}
}
/*
* General errors and warnings are reported with an console message
* in Rawshark.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
{
fprintf(stderr, "rawshark: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
/*
* Open/create errors are reported with an console message in Rawshark.
*/
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
{
fprintf(stderr, "rawshark: ");
fprintf(stderr, file_open_error_message(err, for_writing), filename);
fprintf(stderr, "\n");
}
static const nstime_t *
raw_get_frame_ts(struct packet_provider_data *prov, guint32 frame_num)
{
@ -1522,26 +1504,6 @@ raw_cf_open(capture_file *cf, const char *fname)
return CF_OK;
}
/*
* Read errors are reported with an console message in Rawshark.
*/
static void
read_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while reading from the file \"%s\": %s.",
filename, g_strerror(err));
}
/*
* Write errors are reported with an console message in Rawshark.
*/
static void
write_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while writing to the file \"%s\": %s.",
filename, g_strerror(err));
}
/*
* Report an error in command-line arguments.
*/

View File

@ -105,7 +105,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
fprintf(stderr,
"reordercap: An error occurred while re-reading \"%s\".\n",
infile);
cfile_read_failure_message("reordercap", infile, err, err_info);
cfile_read_failure_message(infile, err, err_info);
exit(1);
}
}
@ -117,8 +117,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
/* Dump frame to outfile */
if (!wtap_dump(pdh, rec, ws_buffer_start_ptr(buf), &err, &err_info)) {
cfile_write_failure_message("reordercap", infile, outfile, err,
err_info, frame->num,
cfile_write_failure_message(infile, outfile, err, err_info, frame->num,
wtap_file_type_subtype(wth));
exit(1);
}
@ -146,7 +145,7 @@ frames_compare(gconstpointer a, gconstpointer b)
* in reordercap.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
reordercap_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "reordercap: ");
vfprintf(stderr, msg_format, ap);
@ -157,7 +156,7 @@ failure_warning_message(const char *msg_format, va_list ap)
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
reordercap_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
@ -170,6 +169,18 @@ int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
static const struct report_message_routines reordercap_message_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
wtap *wth = NULL;
wtap_dumper *pdh = NULL;
wtap_rec rec;
@ -196,7 +207,7 @@ main(int argc, char *argv[])
char *infile;
const char *outfile;
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(reordercap_cmdarg_err, reordercap_cmdarg_err_cont);
/* Initialize the version information. */
ws_init_version_info("Reordercap (Wireshark)", NULL, NULL, NULL);
@ -218,8 +229,7 @@ main(int argc, char *argv[])
g_free(init_progfile_dir_error);
}
init_report_message(failure_warning_message, failure_warning_message,
NULL, NULL, NULL);
init_report_message("reordercap", &reordercap_message_routines);
wtap_init(TRUE);
@ -260,7 +270,7 @@ main(int argc, char *argv[])
open_routine reader to use, then the following needs to change. */
wth = wtap_open_offline(infile, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
if (wth == NULL) {
cfile_open_failure_message("reordercap", infile, err, err_info);
cfile_open_failure_message(infile, err, err_info);
ret = OPEN_ERROR;
goto clean_exit;
}
@ -280,7 +290,7 @@ main(int argc, char *argv[])
params.idb_inf = NULL;
if (pdh == NULL) {
cfile_dump_open_failure_message("reordercap", outfile, err, err_info,
cfile_dump_open_failure_message(outfile, err, err_info,
wtap_file_type_subtype(wth));
wtap_dump_params_cleanup(&params);
ret = OUTPUT_FILE_ERROR;
@ -316,7 +326,7 @@ main(int argc, char *argv[])
ws_buffer_free(&buf);
if (err != 0) {
/* Print a message noting that the read failed somewhere along the line. */
cfile_read_failure_message("reordercap", infile, err, err_info);
cfile_read_failure_message(infile, err, err_info);
}
printf("%u frames, %u out of order\n", frames->len, wrong_order_count);

View File

@ -74,12 +74,8 @@ capture_file cfile;
static guint32 cum_bytes;
static frame_data ref_frame;
static void failure_warning_message(const char *msg_format, va_list ap);
static void open_failure_message(const char *filename, int err,
gboolean for_writing);
static void read_failure_message(const char *filename, int err);
static void write_failure_message(const char *filename, int err);
static void failure_message_cont(const char *msg_format, va_list ap);
static void sharkd_cmdarg_err(const char *msg_format, va_list ap);
static void sharkd_cmdarg_err_cont(const char *msg_format, va_list ap);
static void
print_current_user(void) {
@ -107,8 +103,20 @@ main(int argc, char *argv[])
char *err_msg = NULL;
e_prefs *prefs_p;
int ret = EXIT_SUCCESS;
static const struct report_message_routines sharkd_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(sharkd_cmdarg_err, sharkd_cmdarg_err_cont);
/*
* Get credential information for later use, and drop privileges
@ -140,9 +148,7 @@ main(int argc, char *argv[])
goto clean_exit;
}
init_report_message(failure_warning_message, failure_warning_message,
open_failure_message, read_failure_message,
write_failure_message);
init_report_message("sharkd", &sharkd_report_routines);
timestamp_set_type(TS_RELATIVE);
timestamp_set_precision(TS_PREC_AUTO);
@ -392,7 +398,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
}
if (err != 0) {
cfile_read_failure_message("sharkd", cf->filename, err, err_info);
cfile_read_failure_message(cf->filename, err, err_info);
}
return err;
@ -448,58 +454,26 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
return CF_OK;
fail:
cfile_open_failure_message("sharkd", fname, *err, err_info);
cfile_open_failure_message(fname, *err, err_info);
return CF_ERROR;
}
/*
* General errors and warnings are reported with an console message
* in sharkd.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
sharkd_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "sharkd: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
/*
* Open/create errors are reported with an console message in sharkd.
*/
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
{
fprintf(stderr, "sharkd: ");
fprintf(stderr, file_open_error_message(err, for_writing), filename);
fprintf(stderr, "\n");
}
/*
* Read errors are reported with an console message in sharkd.
*/
static void
read_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while reading from the file \"%s\": %s.",
filename, g_strerror(err));
}
/*
* Write errors are reported with an console message in sharkd.
*/
static void
write_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while writing to the file \"%s\": %s.",
filename, g_strerror(err));
}
/*
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)
sharkd_cmdarg_err_cont(const char *msg_format, va_list ap)
{
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");

View File

@ -63,6 +63,7 @@
#include "ui/util.h"
#include "ui/decode_as_utils.h"
#include "ui/dissect_opts.h"
#include "ui/failure_message.h"
#include <epan/epan_dissect.h>
#include <epan/tap.h>
#include <epan/stat_tap_ui.h>
@ -134,12 +135,8 @@ static gboolean write_finale(void);
static const char *cf_open_error_message(int err, gchar *err_info,
gboolean for_writing, int file_type);
static void failure_warning_message(const char *msg_format, va_list ap);
static void open_failure_message(const char *filename, int err,
gboolean for_writing);
static void read_failure_message(const char *filename, int err);
static void write_failure_message(const char *filename, int err);
static void failure_message_cont(const char *msg_format, va_list ap);
static void tfshark_cmdarg_err(const char *msg_format, va_list ap);
static void tfshark_cmdarg_err_cont(const char *msg_format, va_list ap);
static GHashTable *output_only_tables = NULL;
@ -353,6 +350,18 @@ main(int argc, char *argv[])
#define OPTSTRING "+2C:d:e:E:hK:lo:O:qQr:R:S:t:T:u:vVxX:Y:z:"
static const char optstring[] = OPTSTRING;
static const struct report_message_routines tfshark_report_routines = {
failure_message,
failure_message,
open_failure_message,
read_failure_message,
write_failure_message,
cfile_open_failure_message,
cfile_dump_open_failure_message,
cfile_read_failure_message,
cfile_write_failure_message,
cfile_close_failure_message
};
/*
* Set the C-language locale to the native environment and set the
@ -364,7 +373,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif
cmdarg_err_init(failure_warning_message, failure_message_cont);
cmdarg_err_init(tfshark_cmdarg_err, tfshark_cmdarg_err_cont);
#ifdef _WIN32
create_app_running_mutex();
@ -471,9 +480,7 @@ main(int argc, char *argv[])
(GLogLevelFlags)log_flags,
tfshark_log_handler, NULL /* user_data */);
init_report_message(failure_warning_message, failure_warning_message,
open_failure_message, read_failure_message,
write_failure_message);
init_report_message("tfshark", &tfshark_report_routines);
timestamp_set_type(TS_RELATIVE);
timestamp_set_precision(TS_PREC_AUTO);
@ -2236,53 +2243,21 @@ cf_open_error_message(int err, gchar *err_info _U_, gboolean for_writing,
}
/*
* General errors and warnings are reported with an console message
* in TFShark.
* Report an error in command-line arguments.
*/
static void
failure_warning_message(const char *msg_format, va_list ap)
tfshark_cmdarg_err(const char *msg_format, va_list ap)
{
fprintf(stderr, "tfshark: ");
vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
}
/*
* Open/create errors are reported with an console message in TFShark.
*/
static void
open_failure_message(const char *filename, int err, gboolean for_writing)
{
fprintf(stderr, "tfshark: ");
fprintf(stderr, file_open_error_message(err, for_writing), filename);
fprintf(stderr, "\n");
}
/*
* Read errors are reported with an console message in TFShark.
*/
static void
read_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while reading from the file \"%s\": %s.",
filename, g_strerror(err));
}
/*
* Write errors are reported with an console message in TFShark.
*/
static void
write_failure_message(const char *filename, int err)
{
cmdarg_err("An error occurred while writing to the file \"%s\": %s.",
filename, g_strerror(err));
}
/*
* Report additional information for an error in command-line arguments.
*/
static void
failure_message_cont(const char *msg_format, va_list ap)