summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.c156
-rw-r--r--ui/alert_box.c150
-rw-r--r--ui/alert_box.h13
-rw-r--r--ui/export_pdu_ui_utils.c11
4 files changed, 179 insertions, 151 deletions
diff --git a/file.c b/file.c
index 0434717fde..062b5172c9 100644
--- a/file.c
+++ b/file.c
@@ -132,9 +132,6 @@ static gboolean find_packet(capture_file *cf,
static const char *cf_get_user_packet_comment(capture_file *cf, const frame_data *fd);
-static void cf_open_failure_alert_box(const char *filename, int err,
- gchar *err_info, gboolean for_writing,
- int file_type);
static void cf_rename_failure_alert_box(const char *filename, int err);
static void cf_close_failure_alert_box(const char *filename, int err);
static void ref_time_packets(capture_file *cf);
@@ -376,7 +373,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
return CF_OK;
fail:
- cf_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
+ cfile_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
return CF_ERROR;
}
@@ -1417,13 +1414,13 @@ cf_merge_files_to_tempfile(gpointer pd_window, char **out_filenamep,
break;
case MERGE_ERR_CANT_OPEN_INFILE:
- cf_open_failure_alert_box(in_filenames[err_fileno], err, err_info,
- FALSE, 0);
+ cfile_open_failure_alert_box(in_filenames[err_fileno], err, err_info,
+ FALSE, 0);
break;
case MERGE_ERR_CANT_OPEN_OUTFILE:
- cf_open_failure_alert_box(*out_filenamep, err, err_info, TRUE,
- file_type);
+ cfile_open_failure_alert_box(*out_filenamep, err, err_info, TRUE,
+ file_type);
break;
case MERGE_ERR_CANT_READ_INFILE: /* fall through */
@@ -4313,7 +4310,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
sense for now. */
cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, err, &err_info, TRUE);
if (cf->wth == NULL) {
- cf_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
+ cfile_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
return CF_READ_ERROR;
}
@@ -4622,7 +4619,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format,
idb_inf = NULL;
if (pdh == NULL) {
- cf_open_failure_alert_box(fname, err, NULL, TRUE, save_format);
+ cfile_open_failure_alert_box(fname, err, NULL, TRUE, save_format);
goto fail;
}
@@ -4724,7 +4721,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format,
cf->open_type = WTAP_TYPE_AUTO;
cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
if (cf->wth == NULL) {
- cf_open_failure_alert_box(fname, err, err_info, FALSE, 0);
+ cfile_open_failure_alert_box(fname, err, err_info, FALSE, 0);
cf_close(cf);
} else {
g_free(cf->filename);
@@ -4854,7 +4851,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname,
idb_inf = NULL;
if (pdh == NULL) {
- cf_open_failure_alert_box(fname, err, NULL, TRUE, save_format);
+ cfile_open_failure_alert_box(fname, err, NULL, TRUE, save_format);
goto fail;
}
@@ -4933,141 +4930,6 @@ fail:
return CF_WRITE_ERROR;
}
-static void
-cf_open_failure_alert_box(const char *filename, int err, gchar *err_info,
- gboolean for_writing, int file_type)
-{
- gchar *display_basename;
-
- if (err < 0) {
- /* Wiretap error. */
- display_basename = g_filename_display_basename(filename);
- switch (err) {
-
- case WTAP_ERR_NOT_REGULAR_FILE:
- simple_error_message_box(
- "The file \"%s\" is a \"special file\" or socket or other non-regular file.",
- display_basename);
- break;
-
- case WTAP_ERR_RANDOM_OPEN_PIPE:
- /* Seen only when opening a capture file for reading. */
- simple_error_message_box(
- "The file \"%s\" is a pipe or FIFO; Wireshark can't read pipe or FIFO files.\n"
- "To capture from a pipe or FIFO use wireshark -i -",
- display_basename);
- break;
-
- case WTAP_ERR_FILE_UNKNOWN_FORMAT:
- /* Seen only when opening a capture file for reading. */
- simple_error_message_box(
- "The file \"%s\" isn't a capture file in a format Wireshark understands.",
- display_basename);
- break;
-
- case WTAP_ERR_UNSUPPORTED:
- /* Seen only when opening a capture file for reading. */
- simple_error_message_box(
- "The file \"%s\" contains record data that Wireshark doesn't support.\n"
- "(%s)",
- display_basename,
- err_info != NULL ? err_info : "no information supplied");
- g_free(err_info);
- break;
-
- case WTAP_ERR_CANT_WRITE_TO_PIPE:
- /* Seen only when opening a capture file for writing. */
- simple_error_message_box(
- "The file \"%s\" is a pipe, and %s capture files can't be "
- "written to a pipe.",
- display_basename, wtap_file_type_subtype_string(file_type));
- break;
-
- case WTAP_ERR_UNWRITABLE_FILE_TYPE:
- /* Seen only when opening a capture file for writing. */
- simple_error_message_box(
- "Wireshark doesn't support writing capture files in that format.");
- break;
-
- case WTAP_ERR_UNWRITABLE_ENCAP:
- /* Seen only when opening a capture file for writing. */
- simple_error_message_box("Wireshark can't save this capture in that format.");
- break;
-
- case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
- if (for_writing) {
- simple_error_message_box(
- "Wireshark can't save this capture in that format.");
- } else {
- simple_error_message_box(
- "The file \"%s\" is a capture for a network type that Wireshark doesn't support.",
- display_basename);
- }
- break;
-
- case WTAP_ERR_BAD_FILE:
- /* Seen only when opening a capture file for reading. */
- simple_error_message_box(
- "The file \"%s\" appears to be damaged or corrupt.\n"
- "(%s)",
- display_basename,
- err_info != NULL ? err_info : "no information supplied");
- g_free(err_info);
- break;
-
- case WTAP_ERR_CANT_OPEN:
- if (for_writing) {
- simple_error_message_box(
- "The file \"%s\" could not be created for some unknown reason.",
- display_basename);
- } else {
- simple_error_message_box(
- "The file \"%s\" could not be opened for some unknown reason.",
- display_basename);
- }
- break;
-
- case WTAP_ERR_SHORT_READ:
- simple_error_message_box(
- "The file \"%s\" appears to have been cut short"
- " in the middle of a packet or other data.",
- display_basename);
- break;
-
- case WTAP_ERR_SHORT_WRITE:
- simple_error_message_box(
- "A full header couldn't be written to the file \"%s\".",
- display_basename);
- break;
-
- case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
- simple_error_message_box(
- "This file type cannot be written as a compressed file.");
- break;
-
- case WTAP_ERR_DECOMPRESS:
- simple_error_message_box(
- "The compressed file \"%s\" appears to be damaged or corrupt.\n"
- "(%s)", display_basename,
- err_info != NULL ? err_info : "no information supplied");
- g_free(err_info);
- break;
-
- default:
- simple_error_message_box(
- "The file \"%s\" could not be %s: %s.",
- display_basename,
- for_writing ? "created" : "opened",
- wtap_strerror(err));
- break;
- }
- g_free(display_basename);
- } else {
- /* OS error. */
- open_failure_alert_box(filename, err, for_writing);
- }
-}
-
/*
* XXX - whether we mention the source pathname, the target pathname,
* or both depends on the error and on what we find if we look for
diff --git a/ui/alert_box.c b/ui/alert_box.c
index 865f130781..622b1caa26 100644
--- a/ui/alert_box.c
+++ b/ui/alert_box.c
@@ -59,6 +59,156 @@ vwarning_alert_box(const char *msg_format, va_list ap)
}
/*
+ * Alert box for a failed attempt to open or create a capture file.
+ * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value;
+ * "err_info" is assumed to be a string giving further information for
+ * some WTAP_ERR_ values; "for_writing" is TRUE if the file is being
+ * opened for writing and FALSE if it's being opened for reading;
+ * "file_type" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type of
+ * file being written (it's ignored for opening-for-reading errors).
+ *
+ * XXX - add explanatory secondary text for at least some of the errors;
+ * various HIGs suggest that you should, for example, suggest that the
+ * user remove files if the file system is full. Perhaps that's because
+ * they're providing guidelines for people less sophisticated than the
+ * typical Wireshark user is, but....
+ */
+void
+cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info,
+ gboolean for_writing, int file_type)
+{
+ gchar *display_basename;
+
+ if (err < 0) {
+ /* Wiretap error. */
+ display_basename = g_filename_display_basename(filename);
+ switch (err) {
+
+ case WTAP_ERR_NOT_REGULAR_FILE:
+ simple_error_message_box(
+ "The file \"%s\" is a \"special file\" or socket or other non-regular file.",
+ display_basename);
+ break;
+
+ case WTAP_ERR_RANDOM_OPEN_PIPE:
+ /* Seen only when opening a capture file for reading. */
+ simple_error_message_box(
+ "The file \"%s\" is a pipe or FIFO; Wireshark can't read pipe or FIFO files.\n"
+ "To capture from a pipe or FIFO use wireshark -i -",
+ display_basename);
+ break;
+
+ case WTAP_ERR_FILE_UNKNOWN_FORMAT:
+ /* Seen only when opening a capture file for reading. */
+ simple_error_message_box(
+ "The file \"%s\" isn't a capture file in a format Wireshark understands.",
+ display_basename);
+ break;
+
+ case WTAP_ERR_UNSUPPORTED:
+ /* Seen only when opening a capture file for reading. */
+ simple_error_message_box(
+ "The file \"%s\" contains record data that Wireshark doesn't support.\n"
+ "(%s)",
+ display_basename,
+ err_info != NULL ? err_info : "no information supplied");
+ g_free(err_info);
+ break;
+
+ case WTAP_ERR_CANT_WRITE_TO_PIPE:
+ /* Seen only when opening a capture file for writing. */
+ simple_error_message_box(
+ "The file \"%s\" is a pipe, and %s capture files can't be "
+ "written to a pipe.",
+ display_basename, wtap_file_type_subtype_string(file_type));
+ break;
+
+ case WTAP_ERR_UNWRITABLE_FILE_TYPE:
+ /* Seen only when opening a capture file for writing. */
+ simple_error_message_box(
+ "Wireshark doesn't support writing capture files in that format.");
+ break;
+
+ case WTAP_ERR_UNWRITABLE_ENCAP:
+ /* Seen only when opening a capture file for writing. */
+ simple_error_message_box("Wireshark can't save this capture in that format.");
+ break;
+
+ case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
+ if (for_writing) {
+ simple_error_message_box(
+ "Wireshark can't save this capture in that format.");
+ } else {
+ simple_error_message_box(
+ "The file \"%s\" is a capture for a network type that Wireshark doesn't support.",
+ display_basename);
+ }
+ break;
+
+ case WTAP_ERR_BAD_FILE:
+ /* Seen only when opening a capture file for reading. */
+ simple_error_message_box(
+ "The file \"%s\" appears to be damaged or corrupt.\n"
+ "(%s)",
+ display_basename,
+ err_info != NULL ? err_info : "no information supplied");
+ g_free(err_info);
+ break;
+
+ case WTAP_ERR_CANT_OPEN:
+ if (for_writing) {
+ simple_error_message_box(
+ "The file \"%s\" could not be created for some unknown reason.",
+ display_basename);
+ } else {
+ simple_error_message_box(
+ "The file \"%s\" could not be opened for some unknown reason.",
+ display_basename);
+ }
+ break;
+
+ case WTAP_ERR_SHORT_READ:
+ simple_error_message_box(
+ "The file \"%s\" appears to have been cut short"
+ " in the middle of a packet or other data.",
+ display_basename);
+ break;
+
+ case WTAP_ERR_SHORT_WRITE:
+ simple_error_message_box(
+ "A full header couldn't be written to the file \"%s\".",
+ display_basename);
+ break;
+
+ case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
+ simple_error_message_box(
+ "This file type cannot be written as a compressed file.");
+ break;
+
+ case WTAP_ERR_DECOMPRESS:
+ simple_error_message_box(
+ "The compressed file \"%s\" appears to be damaged or corrupt.\n"
+ "(%s)", display_basename,
+ err_info != NULL ? err_info : "no information supplied");
+ g_free(err_info);
+ break;
+
+ default:
+ simple_error_message_box(
+ "The file \"%s\" could not be %s: %s.",
+ display_basename,
+ for_writing ? "created" : "opened",
+ wtap_strerror(err));
+ break;
+ }
+ g_free(display_basename);
+ } else {
+ /* OS error. */
+ open_failure_alert_box(filename, err, for_writing);
+ }
+}
+
+/*
* Alert box for a failed attempt to open or create a file.
* "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if
* the file is being opened for writing and FALSE if it's being opened
diff --git a/ui/alert_box.h b/ui/alert_box.h
index 9e8c6a64f6..9e19234e20 100644
--- a/ui/alert_box.h
+++ b/ui/alert_box.h
@@ -40,6 +40,19 @@ extern void vfailure_alert_box(const char *msg_format, va_list ap);
extern void vwarning_alert_box(const char *msg_format, va_list ap);
/*
+ * Alert box for a failed attempt to open or create a capture file.
+ * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value;
+ * "err_info" is assumed to be a string giving further information for
+ * some WTAP_ERR_ values; "for_writing" is TRUE if the file is being
+ * opened for writing and FALSE if it's being opened for reading;
+ * "file_type" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type of
+ * file being written (it's ignored for opening-for-reading errors).
+ */
+extern void cfile_open_failure_alert_box(const char *filename, int err,
+ gchar *err_info, gboolean for_writing,
+ int file_type);
+
+/*
* Alert box for a failed attempt to open or create a file.
* "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if
* the file is being opened for writing and FALSE if it's being opened
diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c
index 133e511df8..0f2ee8d4b1 100644
--- a/ui/export_pdu_ui_utils.c
+++ b/ui/export_pdu_ui_utils.c
@@ -46,17 +46,20 @@ static void
exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
{
int import_file_fd;
- char *tmpname, *capfile_name;
+ char *tmpname, *capfile_name, *comment;
int err;
/* Choose a random name for the temporary import buffer */
import_file_fd = create_tempfile(&tmpname, "Wireshark_PDU_", NULL);
capfile_name = g_strdup(tmpname);
- err = exp_pdu_open(exp_pdu_tap_data, import_file_fd,
- g_strdup_printf("Dump of PDUs from %s", cfile.filename));
+ comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename);
+ err = exp_pdu_open(exp_pdu_tap_data, import_file_fd, comment);
if (err != 0) {
- open_failure_alert_box(capfile_name ? capfile_name : "temporary file", err, TRUE);
+ g_free(comment);
+ cfile_open_failure_alert_box(capfile_name ? capfile_name : "temporary file",
+ err, NULL, TRUE,
+ WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
goto end;
}