aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--capinfos.c30
-rw-r--r--capture_info.c6
-rw-r--r--captype.c6
-rw-r--r--editcap.c12
-rw-r--r--file.c58
-rw-r--r--mergecap.c14
-rw-r--r--randpkt.c9
-rw-r--r--rawshark.c9
-rw-r--r--reordercap.c33
-rw-r--r--tshark.c24
-rw-r--r--wiretap/file_access.c5
-rw-r--r--wiretap/wtap.c2
12 files changed, 92 insertions, 116 deletions
diff --git a/capinfos.c b/capinfos.c
index 785818741d..59056267a1 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -896,22 +896,17 @@ process_cap_file(wtap *wth, const char *filename)
fprintf(stderr,
"capinfos: An error occurred after reading %u packets from \"%s\": %s.\n",
packet, filename, wtap_strerror(err));
- switch (err) {
-
- case WTAP_ERR_SHORT_READ:
+ if (err == WTAP_ERR_SHORT_READ) {
+ /* Don't give up completely with this one. */
status = 1;
fprintf(stderr,
" (will continue anyway, checksums might be incorrect)\n");
- break;
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
- case WTAP_ERR_DECOMPRESS:
- fprintf(stderr, "(%s)\n", err_info);
- g_free(err_info);
- /* fallthrough */
+ } else {
+ if (err_info != NULL) {
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
+ }
- default:
g_free(cf_info.encap_counts);
return 1;
}
@@ -1481,14 +1476,9 @@ main(int argc, char *argv[])
if (!wth) {
fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[opt],
wtap_strerror(err));
- switch (err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
- case WTAP_ERR_DECOMPRESS:
- fprintf(stderr, "(%s)\n", err_info);
- g_free(err_info);
- break;
+ if (err_info != NULL) {
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
}
overall_error_status = 1; /* remember that an error has occurred */
if (!continue_after_wtap_open_offline_failure)
diff --git a/capture_info.c b/capture_info.c
index 753bba0e80..3989d00faa 100644
--- a/capture_info.c
+++ b/capture_info.c
@@ -125,7 +125,7 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
/* Seen only when opening a capture file for reading. */
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The file \"%%s\" contains record data that Wireshark doesn't support.\n"
- "(%s)", err_info);
+ "(%s)", err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
errmsg = errmsg_errno;
break;
@@ -159,7 +159,7 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
/* Seen only when opening a capture file for reading. */
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The file \"%%s\" appears to be damaged or corrupt.\n"
- "(%s)", err_info);
+ "(%s)", err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
errmsg = errmsg_errno;
break;
@@ -183,7 +183,7 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
case WTAP_ERR_DECOMPRESS:
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The compressed file \"%%s\" appears to be damaged or corrupt.\n"
- "(%s)", err_info);
+ "(%s)", err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
errmsg = errmsg_errno;
break;
diff --git a/captype.c b/captype.c
index e06236130e..0864ba6222 100644
--- a/captype.c
+++ b/captype.c
@@ -254,13 +254,9 @@ main(int argc, char *argv[])
else {
fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
wtap_strerror(err));
- switch (err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
overall_error_status = 1; /* remember that an error has occurred */
}
diff --git a/editcap.c b/editcap.c
index 91ed791b95..78338618e4 100644
--- a/editcap.c
+++ b/editcap.c
@@ -1249,12 +1249,9 @@ main(int argc, char *argv[])
if (!wth) {
fprintf(stderr, "editcap: Can't open %s: %s\n", argv[optind],
wtap_strerror(err));
- switch (err) {
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
exit(2);
}
@@ -1689,7 +1686,7 @@ main(int argc, char *argv[])
"editcap: Record %u of \"%s\" has data that can't be saved in a \"%s\" file.\n(%s)\n",
read_count, argv[optind],
wtap_file_type_subtype_string(out_file_type_subtype),
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -1714,12 +1711,9 @@ main(int argc, char *argv[])
fprintf(stderr,
"editcap: An error occurred while reading \"%s\": %s.\n",
argv[optind], wtap_strerror(err));
- switch (err) {
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
}
diff --git a/file.c b/file.c
index 757997cb82..6657ca7401 100644
--- a/file.c
+++ b/file.c
@@ -743,7 +743,7 @@ cf_read(capture_file *cf, gboolean reloading)
case WTAP_ERR_UNSUPPORTED:
simple_error_message_box(
"The capture file contains record data that Wireshark doesn't support.\n(%s)",
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -756,14 +756,14 @@ cf_read(capture_file *cf, gboolean reloading)
case WTAP_ERR_BAD_FILE:
simple_error_message_box(
"The capture file appears to be damaged or corrupt.\n(%s)",
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESS:
simple_error_message_box(
- "The compressed capture file appears to be damaged or corrupt.\n"
- "(%s)", err_info);
+ "The compressed capture file appears to be damaged or corrupt.\n",
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -887,10 +887,14 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
} else if (*err != 0) {
/* We got an error reading the capture file.
XXX - pop up a dialog box instead? */
- g_warning("Error \"%s\" while reading: \"%s\" (\"%s\")",
- wtap_strerror(*err), err_info, cf->filename);
- g_free(err_info);
-
+ if (err_info != NULL) {
+ g_warning("Error \"%s\" while reading \"%s\" (\"%s\")",
+ wtap_strerror(*err), cf->filename, err_info);
+ g_free(err_info);
+ } else {
+ g_warning("Error \"%s\" while reading \"%s\"",
+ wtap_strerror(*err), cf->filename);
+ }
return CF_READ_ERROR;
} else
return CF_READ_OK;
@@ -992,10 +996,14 @@ cf_finish_tail(capture_file *cf, int *err)
if (*err != 0) {
/* We got an error reading the capture file.
XXX - pop up a dialog box? */
-
- g_warning("Error \"%s\" while reading: \"%s\" (\"%s\")",
- wtap_strerror(*err), err_info, cf->filename);
- g_free(err_info);
+ if (err_info != NULL) {
+ g_warning("Error \"%s\" while reading \"%s\" (\"%s\")",
+ wtap_strerror(*err), cf->filename, err_info);
+ g_free(err_info);
+ } else {
+ g_warning("Error \"%s\" while reading \"%s\"",
+ wtap_strerror(*err), cf->filename);
+ }
return CF_READ_ERROR;
} else {
return CF_READ_OK;
@@ -1535,7 +1543,8 @@ cf_merge_files(char **out_filenamep, int in_file_count,
case WTAP_ERR_DECOMPRESS:
simple_error_message_box(
"The compressed capture file %s appears to be damaged or corrupt.\n"
- "(%s)", display_basename, err_info);
+ "(%s)", display_basename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -1610,7 +1619,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
"Record %u of \"%s\" has data that can't be saved in a \"%s\" file.\n(%s)",
in_file ? in_file->packet_num : 0, display_basename,
wtap_file_type_subtype_string(file_type),
- write_err_info);
+ write_err_info != NULL ? write_err_info : "no information supplied");
g_free(write_err_info);
g_free(display_basename);
break;
@@ -1746,7 +1755,8 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata,
case WTAP_ERR_BAD_FILE:
simple_error_message_box("An error occurred while reading from the file \"%s\": %s.\n(%s)",
- display_basename, wtap_strerror(err), err_info);
+ display_basename, wtap_strerror(err),
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -4203,7 +4213,7 @@ save_record(capture_file *cf, frame_data *fdata,
simple_error_message_box(
"Record %u has data that can't be saved in a \"%s\" file.\n(%s)",
fdata->num, wtap_file_type_subtype_string(args->file_type),
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -4519,7 +4529,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
case WTAP_ERR_UNSUPPORTED:
simple_error_message_box(
"The capture file contains record data that Wireshark doesn't support.\n(%s)",
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -4532,14 +4542,15 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
case WTAP_ERR_BAD_FILE:
simple_error_message_box(
"The capture file appears to be damaged or corrupt.\n(%s)",
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESS:
simple_error_message_box(
"The compressed capture file appears to be damaged or corrupt.\n"
- "(%s)", err_info);
+ "(%s)",
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -5036,7 +5047,8 @@ cf_open_failure_alert_box(const char *filename, int err, gchar *err_info,
simple_error_message_box(
"The file \"%s\" contains record data that Wireshark doesn't support.\n",
"(%s)",
- display_basename, err_info);
+ display_basename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -5075,7 +5087,8 @@ cf_open_failure_alert_box(const char *filename, int err, gchar *err_info,
simple_error_message_box(
"The file \"%s\" appears to be damaged or corrupt.\n"
"(%s)",
- display_basename, err_info);
+ display_basename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -5112,7 +5125,8 @@ cf_open_failure_alert_box(const char *filename, int err, gchar *err_info,
case WTAP_ERR_DECOMPRESS:
simple_error_message_box(
"The compressed file \"%s\" appears to be damaged or corrupt.\n"
- "(%s)", display_basename, err_info);
+ "(%s)", display_basename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
diff --git a/mergecap.c b/mergecap.c
index 82b26403e7..7bcada4f99 100644
--- a/mergecap.c
+++ b/mergecap.c
@@ -374,13 +374,9 @@ main(int argc, char *argv[])
&open_err, &err_info, &err_fileno)) {
fprintf(stderr, "mergecap: Can't open %s: %s\n", argv[optind + err_fileno],
wtap_strerror(open_err));
- switch (open_err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
return 2;
}
@@ -542,13 +538,9 @@ main(int argc, char *argv[])
if (in_files[i].state == GOT_ERROR) {
fprintf(stderr, "mergecap: Error reading %s: %s\n",
in_files[i].filename, wtap_strerror(read_err));
- switch (read_err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
}
}
@@ -599,7 +591,7 @@ main(int argc, char *argv[])
fprintf(stderr, "mergecap: Record %u of \"%s\" has data that can't be saved in a \"%s\" file.\n(%s)\n",
in_file ? in_file->packet_num : 0, in_file ? in_file->filename : "UNKNOWN",
wtap_file_type_subtype_string(file_type),
- write_err_info);
+ write_err_info != NULL ? write_err_info : "no information supplied");
g_free(write_err_info);
break;
diff --git a/randpkt.c b/randpkt.c
index 1ec7d18baa..d19545987f 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -622,15 +622,8 @@ main(int argc, char **argv)
/* XXX - report errors! */
if (!wtap_dump(dump, &pkthdr, &buffer[0], &err, &err_info)) {
- switch (err) {
-
- case WTAP_ERR_UNWRITABLE_REC_DATA:
+ if (err_info != NULL)
g_free(err_info);
- break;
-
- default:
- break;
- }
}
}
diff --git a/rawshark.c b/rawshark.c
index 0fc46c05c4..f70c418526 100644
--- a/rawshark.c
+++ b/rawshark.c
@@ -1008,7 +1008,8 @@ load_cap_file(capture_file *cf)
case WTAP_ERR_UNSUPPORTED:
cmdarg_err("The file \"%s\" contains record data that Rawshark doesn't support.\n(%s)",
- cf->filename, err_info);
+ cf->filename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -1019,13 +1020,15 @@ load_cap_file(capture_file *cf)
case WTAP_ERR_BAD_FILE:
cmdarg_err("The file \"%s\" appears to be damaged or corrupt.\n(%s)",
- cf->filename, err_info);
+ cf->filename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESS:
cmdarg_err("The compressed file \"%s\" appears to be damaged or corrupt.\n(%s)",
- cf->filename, err_info);
+ cf->filename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
diff --git a/reordercap.c b/reordercap.c
index b36bc58b40..9ac0b6738f 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -121,13 +121,9 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
fprintf(stderr,
"reordercap: An error occurred while re-reading \"%s\": %s.\n",
infile, wtap_strerror(err));
- switch (err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
exit(1);
}
@@ -140,18 +136,11 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
/* Dump frame to outfile */
if (!wtap_dump(pdh, phdr, ws_buffer_start_ptr(buf), &err, &err_info)) {
- switch (err) {
-
- case WTAP_ERR_UNWRITABLE_REC_DATA:
- fprintf(stderr, "reordercap: Error (%s) writing frame to outfile (%s)\n",
- wtap_strerror(err), err_info);
+ fprintf(stderr, "reordercap: Error (%s) writing frame to outfile\n",
+ wtap_strerror(err));
+ if (err_info != NULL) {
+ fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
-
- default:
- fprintf(stderr, "reordercap: Error (%s) writing frame to outfile\n",
- wtap_strerror(err));
- break;
}
exit(1);
}
@@ -293,13 +282,9 @@ main(int argc, char *argv[])
if (wth == NULL) {
fprintf(stderr, "reordercap: Can't open %s: %s\n", infile,
wtap_strerror(err));
- switch (err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
exit(1);
}
@@ -349,13 +334,9 @@ main(int argc, char *argv[])
fprintf(stderr,
"reordercap: An error occurred while reading \"%s\": %s.\n",
infile, wtap_strerror(err));
- switch (err) {
-
- case WTAP_ERR_UNSUPPORTED:
- case WTAP_ERR_BAD_FILE:
+ if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
- break;
}
}
diff --git a/tshark.c b/tshark.c
index cc2cdb3d2d..f96f49b930 100644
--- a/tshark.c
+++ b/tshark.c
@@ -3300,7 +3300,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
"Record %u of \"%s\" has data that can't be saved in a \"%s\" file.\n(%s)\n",
framenum, cf->filename,
wtap_file_type_subtype_short_string(out_file_type),
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -3403,7 +3403,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
"Record %u of \"%s\" has data that can't be saved in a \"%s\" file.\n(%s)\n",
framenum, cf->filename,
wtap_file_type_subtype_short_string(out_file_type),
- err_info);
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -3465,7 +3465,8 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
case WTAP_ERR_UNSUPPORTED:
cmdarg_err("The file \"%s\" contains record data that TShark doesn't support.\n(%s)",
- cf->filename, err_info);
+ cf->filename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -3476,13 +3477,15 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
case WTAP_ERR_BAD_FILE:
cmdarg_err("The file \"%s\" appears to be damaged or corrupt.\n(%s)",
- cf->filename, err_info);
+ cf->filename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
case WTAP_ERR_DECOMPRESS:
cmdarg_err("The compressed file \"%s\" appears to be damaged or corrupt.\n"
- "(%s)", cf->filename, err_info);
+ "(%s)", cf->filename,
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -4199,7 +4202,8 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
/* Seen only when opening a capture file for reading. */
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The file \"%%s\" contains record data that TShark doesn't support.\n"
- "(%s)", err_info);
+ "(%s)",
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
errmsg = errmsg_errno;
break;
@@ -4238,8 +4242,9 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
case WTAP_ERR_BAD_FILE:
/* Seen only when opening a capture file for reading. */
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
- "The file \"%%s\" appears to be damaged or corrupt.\n"
- "(%s)", err_info);
+ "The file \"%%s\" appears to be damaged or corrupt.\n"
+ "(%s)",
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
errmsg = errmsg_errno;
break;
@@ -4268,7 +4273,8 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
/* Seen only when opening a capture file for reading. */
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
"The compressed file \"%%s\" appears to be damaged or corrupt.\n"
- "(%s)", err_info);
+ "(%s)",
+ err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
errmsg = errmsg_errno;
break;
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index c475ffd6a6..730698b919 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -726,6 +726,9 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
gboolean use_stdin = FALSE;
gchar *extension;
+ *err = 0;
+ *err_info = NULL;
+
init_open_routines();
/* open standard input if filename is '-' */
@@ -2318,6 +2321,8 @@ gboolean
wtap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err, gchar **err_info)
{
+ *err = 0;
+ *err_info = NULL;
return (wdh->subtype_write)(wdh, phdr, pd, err, err_info);
}
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 731ab26091..dd7d5aed9c 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -1050,6 +1050,8 @@ wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
wth->phdr.pkt_encap = wth->file_encap;
wth->phdr.pkt_tsprec = wth->file_tsprec;
+ *err = 0;
+ *err_info = NULL;
if (!wth->subtype_read(wth, err, err_info, data_offset)) {
/*
* If we didn't get an error indication, we read