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/ws_version_info.h>
60 #include <wsutil/plugins.h>
64 #include <wsutil/report_err.h>
65 #include <wsutil/str_util.h>
68 #include <wsutil/unicode-utils.h>
71 #ifndef HAVE_GETOPT_LONG
72 #include "wsutil/wsgetopt.h"
76 print_usage(FILE *output)
78 fprintf(output, "\n");
79 fprintf(output, "Usage: captype <infile> ...\n");
84 * Don't report failures to load plugins because most (non-wiretap) plugins
85 * *should* fail to load (because we're not linked against libwireshark and
86 * dissector plugins need libwireshark).
89 failure_message(const char *msg_format _U_, va_list ap _U_)
96 get_captype_compiled_info(GString *str)
99 g_string_append(str, ", ");
101 g_string_append(str, "with libz ");
103 g_string_append(str, ZLIB_VERSION);
104 #else /* ZLIB_VERSION */
105 g_string_append(str, "(version unknown)");
106 #endif /* ZLIB_VERSION */
107 #else /* HAVE_LIBZ */
108 g_string_append(str, "without libz");
109 #endif /* HAVE_LIBZ */
113 get_captype_runtime_info(GString *str)
116 #if defined(HAVE_LIBZ) && !defined(_WIN32)
117 g_string_append_printf(str, ", with libz %s", zlibVersion());
122 main(int argc, char *argv[])
124 GString *comp_info_str;
125 GString *runtime_info_str;
131 int overall_error_status;
132 static const struct option long_options[] = {
133 {(char *)"help", no_argument, NULL, 'h'},
134 {(char *)"version", no_argument, NULL, 'v'},
139 char *init_progfile_dir_error;
142 /* Get the compile-time version information string */
143 comp_info_str = get_compiled_version_info(NULL, get_captype_compiled_info);
145 /* Get the run-time version information string */
146 runtime_info_str = get_runtime_version_info(get_captype_runtime_info);
148 /* Add it to the information to be reported on a crash. */
149 ws_add_crash_info("Captype (Wireshark) %s\n"
154 get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
157 arg_list_utf_16to8(argc, argv);
158 create_app_running_mutex();
162 * Get credential information for later use.
164 init_process_policies();
165 init_open_routines();
168 if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) {
169 g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error);
170 g_free(init_progfile_dir_error);
172 /* Register all the plugin types we have. */
173 wtap_register_plugin_types(); /* Types known to libwiretap */
175 init_report_err(failure_message,NULL,NULL,NULL);
177 /* Scan for plugins. This does *not* call their registration routines;
178 that's done later. */
181 /* Register all libwiretap plugin modules. */
182 register_all_wiretap_modules();
186 /* Process the options */
187 while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
192 printf("Captype (Wireshark) %s\n"
193 "Print the file types of capture files.\n"
194 "See http://www.wireshark.org for more information.\n",
195 get_ws_vcs_version_info());
201 show_version("Captype (Wireshark)", comp_info_str, runtime_info_str);
202 g_string_free(comp_info_str, TRUE);
203 g_string_free(runtime_info_str, TRUE);
207 case '?': /* Bad flag - print usage message */
214 /* Set the C-language locale to the native environment. */
215 setlocale(LC_ALL, "");
222 overall_error_status = 0;
224 for (i = 1; i < argc; i++) {
225 wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
228 printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
231 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
232 printf("%s: unknown\n", argv[i]);
234 fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
236 if (err_info != NULL) {
237 fprintf(stderr, "(%s)\n", err_info);
240 overall_error_status = 1; /* remember that an error has occurred */
246 return overall_error_status;
250 * Editor modelines - http://www.wireshark.org/tools/modelines.html
255 * indent-tabs-mode: nil
258 * vi: set shiftwidth=2 tabstop=8 expandtab:
259 * :indentSize=2:tabSize=8:noTabs=true: