summaryrefslogtreecommitdiff
path: root/capinfos.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-01-11 00:13:42 +0000
committerGuy Harris <guy@alum.mit.edu>2005-01-11 00:13:42 +0000
commit7f796b174f3e12cf3d5ec45fdb557a6e3ef5486f (patch)
treebd38b1f6e5844bca345db9963e147850af11e437 /capinfos.c
parente136ee34a4e1ef9bfd0a25a1f797757cd4d48aa0 (diff)
downloadwireshark-7f796b174f3e12cf3d5ec45fdb557a6e3ef5486f.tar.gz
Improve the error reporting.
Remove a duplicate #include, and shuffle the includes a bit to put OS includes before other includes. svn path=/trunk/; revision=13003
Diffstat (limited to 'capinfos.c')
-rw-r--r--capinfos.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/capinfos.c b/capinfos.c
index 060e9b3b9d..fc398bf41e 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -30,8 +30,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include <glib.h>
#include <string.h>
+#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -41,7 +41,12 @@
#include <sys/time.h>
#endif
-#include <string.h>
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include <glib.h>
+
#include <epan/packet.h>
#include "wtap.h"
@@ -49,11 +54,6 @@
#include "getopt.h"
#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-
static gboolean cap_file_type = FALSE; /* Do not report capture type */
static gboolean cap_packet_count = FALSE; /* Do not produce packet count */
static gboolean cap_file_size = FALSE; /* Do not report file size */
@@ -117,7 +117,7 @@ print_stats(capture_info *cf_info)
}
static int
-process_cap_file(wtap *wth)
+process_cap_file(wtap *wth, const char *filename)
{
int err;
gchar *err_info;
@@ -151,13 +151,25 @@ process_cap_file(wtap *wth)
}
if (err != 0) {
- fprintf(stderr, "Error after reading %i packets\n", packet);
- exit(1);
+ fprintf(stderr,
+ "capinfos: An error occurred after reading %u packets from \"%s\": %s.\n",
+ packet, filename, wtap_strerror(err));
+ switch (err) {
+
+ case WTAP_ERR_UNSUPPORTED:
+ case WTAP_ERR_UNSUPPORTED_ENCAP:
+ case WTAP_ERR_BAD_RECORD:
+ fprintf(stderr, "(%s)\n", err_info);
+ break;
+ }
+ return 1;
}
/* File size */
if (fstat(wtap_fd(wth), &cf_stat) < 0) {
- wtap_close(wth);
+ fprintf(stderr,
+ "capinfos: Can't fstat \"%s\": %s.\n",
+ filename, strerror(errno));
return 1;
}
@@ -183,9 +195,10 @@ process_cap_file(wtap *wth)
/* Avg packet size */
cf_info.packet_size = (double)bytes/packet;
+ printf("File name: %s\n", filename);
print_stats(&cf_info);
-return 0;
+ return 0;
}
static void usage(gboolean is_error)
@@ -328,8 +341,7 @@ int main(int argc, char *argv[])
if (opt > optind)
printf("\n");
- printf("File name: %s\n", argv[opt]);
- status = process_cap_file(wth);
+ status = process_cap_file(wth, argv[opt]);
wtap_close(wth);
if (status)