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.
41 #include <wiretap/wtap.h>
43 #include <wsutil/crash_info.h>
44 #include <wsutil/file_util.h>
45 #include <wsutil/filesystem.h>
46 #include <wsutil/privileges.h>
47 #include <ws_version_info.h>
50 #include <wsutil/plugins.h>
53 #include <wsutil/report_err.h>
54 #include <wsutil/str_util.h>
57 #include <wsutil/unicode-utils.h>
60 #ifndef HAVE_GETOPT_LONG
61 #include "wsutil/wsgetopt.h"
65 print_usage(FILE *output)
67 fprintf(output, "\n");
68 fprintf(output, "Usage: captype <infile> ...\n");
73 * General errors are reported with an console message in captype.
76 failure_message(const char *msg_format, va_list ap)
78 fprintf(stderr, "captype: ");
79 vfprintf(stderr, msg_format, ap);
80 fprintf(stderr, "\n");
85 main(int argc, char *argv[])
87 GString *comp_info_str;
88 GString *runtime_info_str;
89 char *init_progfile_dir_error;
95 int overall_error_status;
96 static const struct option long_options[] = {
97 {"help", no_argument, NULL, 'h'},
98 {"version", no_argument, NULL, 'v'},
102 /* Set the C-language locale to the native environment. */
103 setlocale(LC_ALL, "");
105 /* Get the compile-time version information string */
106 comp_info_str = get_compiled_version_info(NULL, NULL);
108 /* Get the run-time version information string */
109 runtime_info_str = get_runtime_version_info(NULL);
111 /* Add it to the information to be reported on a crash. */
112 ws_add_crash_info("Captype (Wireshark) %s\n"
117 get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
118 g_string_free(comp_info_str, TRUE);
119 g_string_free(runtime_info_str, TRUE);
122 arg_list_utf_16to8(argc, argv);
123 create_app_running_mutex();
127 * Get credential information for later use.
129 init_process_policies();
132 * Attempt to get the pathname of the directory containing the
135 init_progfile_dir_error = init_progfile_dir(argv[0], main);
136 if (init_progfile_dir_error != NULL) {
138 "captype: Can't get pathname of directory containing the captype program: %s.\n",
139 init_progfile_dir_error);
140 g_free(init_progfile_dir_error);
146 init_report_err(failure_message,NULL,NULL,NULL);
148 /* Scan for plugins. This does *not* call their registration routines;
151 Don't report failures to load plugins because most (non-wiretap)
152 plugins *should* fail to load (because we're not linked against
153 libwireshark and dissector plugins need libwireshark). */
154 scan_plugins(DONT_REPORT_LOAD_FAILURE);
156 /* Register all libwiretap plugin modules. */
157 register_all_wiretap_modules();
160 /* Process the options */
161 while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
166 printf("Captype (Wireshark) %s\n"
167 "Print the file types of capture files.\n"
168 "See https://www.wireshark.org for more information.\n",
169 get_ws_vcs_version_info());
175 comp_info_str = get_compiled_version_info(NULL, NULL);
176 runtime_info_str = get_runtime_version_info(NULL);
177 show_version("Captype (Wireshark)", comp_info_str, runtime_info_str);
178 g_string_free(comp_info_str, TRUE);
179 g_string_free(runtime_info_str, TRUE);
183 case '?': /* Bad flag - print usage message */
195 overall_error_status = 0;
197 for (i = 1; i < argc; i++) {
198 wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
201 printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
204 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
205 printf("%s: unknown\n", argv[i]);
207 fprintf(stderr, "captype: Can't open %s: %s\n", argv[i],
209 if (err_info != NULL) {
210 fprintf(stderr, "(%s)\n", err_info);
213 overall_error_status = 2; /* remember that an error has occurred */
219 return overall_error_status;
223 * Editor modelines - http://www.wireshark.org/tools/modelines.html
228 * indent-tabs-mode: nil
231 * vi: set shiftwidth=2 tabstop=8 expandtab:
232 * :indentSize=2:tabSize=8:noTabs=true: