aboutsummaryrefslogtreecommitdiffstats
path: root/captype.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-03-15 11:29:43 -0700
committerGuy Harris <gharris@sonic.net>2021-03-15 12:17:59 -0700
commitc33e2f7b51f9e14f99f6b6d9018ac41b7e97d5a6 (patch)
tree4e02fee80e16cfd08afc9d555e4612399c72d69b /captype.c
parent89ae76d3008719f6b797eb201794dfe0de294640 (diff)
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.
Diffstat (limited to 'captype.c')
-rw-r--r--captype.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/captype.c b/captype.c
index 0a620af0c4..37f81ff443 100644
--- a/captype.c
+++ b/captype.c
@@ -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 */
}
}