diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2005-01-11 00:13:42 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2005-01-11 00:13:42 +0000 |
commit | 2a292b303076a5b7ec0d74f05c0e5db1f9eaea17 (patch) | |
tree | bd38b1f6e5844bca345db9963e147850af11e437 /capinfos.c | |
parent | dc4b4398db36ecf367058f93ccad7b4b4b379e15 (diff) |
Improve the error reporting.
Remove a duplicate #include, and shuffle the includes a bit to put OS
includes before other includes.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13003 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'capinfos.c')
-rw-r--r-- | capinfos.c | 40 |
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) |