2 * Reports capture file type
5 * Copyright 2004 Ian Schorr
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
43 #ifdef HAVE_SYS_TIME_H
48 #include <zlib.h> /* to get the libz version number */
53 #include <wsutil/privileges.h>
54 #include <wsutil/filesystem.h>
55 #include <wsutil/file_util.h>
56 #include <wsutil/crash_info.h>
57 #include <wsutil/copyright_info.h>
58 #include <wsutil/os_version_info.h>
59 #include <wsutil/ws_version_info.h>
62 #include <wsutil/plugins.h>
66 #include <wsutil/report_err.h>
67 #include <wsutil/privileges.h>
68 #include <wsutil/str_util.h>
71 #include <wsutil/unicode-utils.h>
75 #include "wsutil/wsgetopt.h"
78 #include "version_info.h"
81 show_version(GString *comp_info_str, GString *runtime_info_str)
83 printf("Captype (Wireshark) %s\n"
90 get_ws_vcs_version_info(), get_copyright_info(),
91 comp_info_str->str, runtime_info_str->str);
95 print_usage(FILE *output)
97 fprintf(output, "\n");
98 fprintf(output, "Usage: captype <infile> ...\n");
103 * Don't report failures to load plugins because most (non-wiretap) plugins
104 * *should* fail to load (because we're not linked against libwireshark and
105 * dissector plugins need libwireshark).
108 failure_message(const char *msg_format _U_, va_list ap _U_)
115 get_captype_compiled_info(GString *str)
118 g_string_append(str, ", ");
120 g_string_append(str, "with libz ");
122 g_string_append(str, ZLIB_VERSION);
123 #else /* ZLIB_VERSION */
124 g_string_append(str, "(version unknown)");
125 #endif /* ZLIB_VERSION */
126 #else /* HAVE_LIBZ */
127 g_string_append(str, "without libz");
128 #endif /* HAVE_LIBZ */
132 get_captype_runtime_info(GString *str)
135 #if defined(HAVE_LIBZ) && !defined(_WIN32)
136 g_string_append_printf(str, ", with libz %s", zlibVersion());
141 main(int argc, char *argv[])
143 GString *comp_info_str;
144 GString *runtime_info_str;
150 int overall_error_status;
151 static const struct option long_options[] = {
152 {(char *)"help", no_argument, NULL, 'h'},
153 {(char *)"version", no_argument, NULL, 'v'},
158 char *init_progfile_dir_error;
161 /* Assemble the compile-time version information string */
162 comp_info_str = g_string_new("Compiled ");
163 get_compiled_version_info(comp_info_str, NULL, get_captype_compiled_info);
165 /* Assemble the run-time version information string */
166 runtime_info_str = g_string_new("Running ");
167 get_runtime_version_info(runtime_info_str, get_captype_runtime_info);
169 /* Add it to the information to be reported on a crash. */
170 ws_add_crash_info("Captype (Wireshark) %s\n"
175 get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
178 arg_list_utf_16to8(argc, argv);
179 create_app_running_mutex();
183 * Get credential information for later use.
185 init_process_policies();
186 init_open_routines();
189 if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
190 g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error);
191 g_free(init_progfile_dir_error);
193 /* Register all the plugin types we have. */
194 wtap_register_plugin_types(); /* Types known to libwiretap */
196 init_report_err(failure_message,NULL,NULL,NULL);
198 /* Scan for plugins. This does *not* call their registration routines;
199 that's done later. */
202 /* Register all libwiretap plugin modules. */
203 register_all_wiretap_modules();
207 /* Process the options */
208 while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
213 printf("Captype (Wireshark) %s\n"
214 "Print the file types of capture files.\n"
215 "See http://www.wireshark.org for more information.\n",
216 get_ws_vcs_version_info());
222 show_version(comp_info_str, runtime_info_str);
223 g_string_free(comp_info_str, TRUE);
224 g_string_free(runtime_info_str, TRUE);
228 case '?': /* Bad flag - print usage message */
235 /* Set the C-language locale to the native environment. */
236 setlocale(LC_ALL, "");
243 overall_error_status = 0;
245 for (i = 1; i < argc; i++) {
246 wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
249 printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
252 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
253 printf("%s: unknown\n", argv[i]);
255 fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
259 case WTAP_ERR_UNSUPPORTED:
260 case WTAP_ERR_UNSUPPORTED_ENCAP:
261 case WTAP_ERR_BAD_FILE:
262 fprintf(stderr, "(%s)\n", err_info);
266 overall_error_status = 1; /* remember that an error has occurred */
272 return overall_error_status;
276 * Editor modelines - http://www.wireshark.org/tools/modelines.html
281 * indent-tabs-mode: nil
284 * vi: set shiftwidth=2 tabstop=8 expandtab:
285 * :indentSize=2:tabSize=8:noTabs=true: