packet-iwarp-mpa: give more information if the ULPDU length doesn't match
[metze/wireshark/wip.git] / captype.c
1 /* captype.c
2  * Reports capture file type
3  *
4  * Based on capinfos.c
5  * Copyright 2004 Ian Schorr
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 #include "config.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34 #include <locale.h>
35 #include <errno.h>
36
37 #ifdef HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif
40
41 #ifdef HAVE_SYS_TIME_H
42 #include <sys/time.h>
43 #endif
44
45 #include <glib.h>
46
47 #include <wsutil/privileges.h>
48 #include <wsutil/filesystem.h>
49 #include <wsutil/file_util.h>
50
51 #ifdef HAVE_PLUGINS
52 #include <wsutil/plugins.h>
53 #endif
54
55 #include "wtap.h"
56 #include <wsutil/report_err.h>
57 #include <wsutil/privileges.h>
58 #include <wsutil/str_util.h>
59
60 #ifdef _WIN32
61 #include <wsutil/unicode-utils.h>
62 #endif /* _WIN32 */
63
64 #include "svnversion.h"
65
66 static void
67 usage(void)
68 {
69   fprintf(stderr, "Captype %s"
70 #ifdef SVNVERSION
71       " (" SVNVERSION " from " SVNPATH ")"
72 #endif
73       "\n", VERSION);
74   fprintf(stderr, "Prints the file types of capture files.\n");
75   fprintf(stderr, "See http://www.wireshark.org for more information.\n");
76   fprintf(stderr, "\n");
77   fprintf(stderr, "Usage: captype <infile> ...\n");
78 }
79
80 #ifdef HAVE_PLUGINS
81 /*
82  *  Don't report failures to load plugins because most (non-wiretap) plugins
83  *  *should* fail to load (because we're not linked against libwireshark and
84  *  dissector plugins need libwireshark).
85  */
86 static void
87 failure_message(const char *msg_format _U_, va_list ap _U_)
88 {
89   return;
90 }
91 #endif
92
93 int
94 main(int argc, char *argv[])
95 {
96   wtap  *wth;
97   int    err;
98   gchar *err_info;
99   int    i;
100   int    overall_error_status;
101
102 #ifdef HAVE_PLUGINS
103   char  *init_progfile_dir_error;
104 #endif
105
106 #ifdef _WIN32
107   arg_list_utf_16to8(argc, argv);
108   create_app_running_mutex();
109 #endif /* _WIN32 */
110
111   /*
112    * Get credential information for later use.
113    */
114   init_process_policies();
115
116 #ifdef HAVE_PLUGINS
117   if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
118     g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error);
119     g_free(init_progfile_dir_error);
120   } else {
121     /* Register all the plugin types we have. */
122     wtap_register_plugin_types(); /* Types known to libwiretap */
123
124     init_report_err(failure_message,NULL,NULL,NULL);
125
126     /* Scan for plugins.  This does *not* call their registration routines;
127        that's done later. */
128     scan_plugins();
129
130     /* Register all libwiretap plugin modules. */
131     register_all_wiretap_modules();
132   }
133 #endif
134
135   /* Set the C-language locale to the native environment. */
136   setlocale(LC_ALL, "");
137
138   if (argc < 2) {
139     usage();
140     return 1;
141   }
142
143   overall_error_status = 0;
144
145   for (i = 1; i < argc; i++) {
146     wth = wtap_open_offline(argv[i], &err, &err_info, FALSE);
147
148     if(wth) {
149       printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
150       wtap_close(wth);
151     } else {
152       if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
153         printf("%s: unknown\n", argv[i]);
154       else {
155         fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
156                 wtap_strerror(err));
157         switch (err) {
158
159         case WTAP_ERR_UNSUPPORTED:
160         case WTAP_ERR_UNSUPPORTED_ENCAP:
161         case WTAP_ERR_BAD_FILE:
162           fprintf(stderr, "(%s)\n", err_info);
163           g_free(err_info);
164           break;
165         }
166         overall_error_status = 1; /* remember that an error has occurred */
167       }
168     }
169
170   }
171
172   return overall_error_status;
173 }
174
175 /*
176  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
177  *
178  * Local variables:
179  * c-basic-offset: 2
180  * tab-width: 2
181  * indent-tabs-mode: nil
182  * End:
183  *
184  * vi: set shiftwidth=2 tabstop=2 expandtab:
185  * :indentSize=2:tabSize=2:noTabs=true:
186  */