sec_vt_bitmask
[metze/wireshark/wip.git] / captype.c
index 0065f83b6fb3d7b269be5c511a921fdbe0bfb8fc..1aed705f0201bbcd52d6bd772b2a8ba9ef6b8e2d 100644 (file)
--- a/captype.c
+++ b/captype.c
@@ -46,6 +46,7 @@
 
 #include <wsutil/privileges.h>
 #include <wsutil/filesystem.h>
+#include <wsutil/file_util.h>
 
 #ifdef HAVE_PLUGINS
 #include <wsutil/plugins.h>
@@ -114,7 +115,7 @@ main(int argc, char *argv[])
 
 #ifdef HAVE_PLUGINS
   if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
-    g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
+    g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error);
     g_free(init_progfile_dir_error);
   } else {
     /* Register all the plugin types we have. */
@@ -134,7 +135,7 @@ main(int argc, char *argv[])
   /* Set the C-language locale to the native environment. */
   setlocale(LC_ALL, "");
 
-  if ((argc - optind) < 1) {
+  if (argc < 2) {
     usage();
     return 1;
   }
@@ -144,10 +145,16 @@ main(int argc, char *argv[])
   for (i = 1; i < argc; i++) {
     wth = wtap_open_offline(argv[i], &err, &err_info, FALSE);
 
-    if (!wth) {
-      fprintf(stderr, "capinfos: Can't open %s: %s\n", argv[i],
-          wtap_strerror(err));
-      switch (err) {
+    if(wth) {
+      printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
+      wtap_close(wth);
+    } else {
+      if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
+        printf("%s: unknown\n", argv[i]);
+      else {
+        fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
+                wtap_strerror(err));
+        switch (err) {
 
         case WTAP_ERR_UNSUPPORTED:
         case WTAP_ERR_UNSUPPORTED_ENCAP:
@@ -155,14 +162,11 @@ main(int argc, char *argv[])
           fprintf(stderr, "(%s)\n", err_info);
           g_free(err_info);
           break;
+        }
+        overall_error_status = 1; /* remember that an error has occurred */
       }
-      overall_error_status = 1; /* remember that an error has occurred */
     }
 
-    if(wth) {
-      printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
-      wtap_close(wth);
-    }
   }
 
   return overall_error_status;