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 * SPDX-License-Identifier: GPL-2.0-or-later
29 #include <wiretap/wtap.h>
31 #include <wsutil/cmdarg_err.h>
32 #include <wsutil/crash_info.h>
33 #include <wsutil/file_util.h>
34 #include <wsutil/filesystem.h>
35 #include <wsutil/privileges.h>
36 #include <version_info.h>
39 #include <wsutil/plugins.h>
42 #include <wsutil/report_message.h>
43 #include <wsutil/str_util.h>
46 #include <wsutil/unicode-utils.h>
49 #ifndef HAVE_GETOPT_LONG
50 #include "wsutil/wsgetopt.h"
53 #include "ui/failure_message.h"
56 print_usage(FILE *output)
58 fprintf(output, "\n");
59 fprintf(output, "Usage: captype <infile> ...\n");
63 * General errors and warnings are reported with an console message
67 failure_warning_message(const char *msg_format, va_list ap)
69 fprintf(stderr, "captype: ");
70 vfprintf(stderr, msg_format, ap);
71 fprintf(stderr, "\n");
75 * Report additional information for an error in command-line arguments.
78 failure_message_cont(const char *msg_format, va_list ap)
80 vfprintf(stderr, msg_format, ap);
81 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 cmdarg_err_init(failure_warning_message, failure_message_cont);
107 /* Get the compile-time version information string */
108 comp_info_str = get_compiled_version_info(NULL, NULL);
110 /* Get the run-time version information string */
111 runtime_info_str = get_runtime_version_info(NULL);
113 /* Add it to the information to be reported on a crash. */
114 ws_add_crash_info("Captype (Wireshark) %s\n"
119 get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
120 g_string_free(comp_info_str, TRUE);
121 g_string_free(runtime_info_str, TRUE);
124 arg_list_utf_16to8(argc, argv);
125 create_app_running_mutex();
129 * Get credential information for later use.
131 init_process_policies();
134 * Attempt to get the pathname of the directory containing the
137 init_progfile_dir_error = init_progfile_dir(argv[0], main);
138 if (init_progfile_dir_error != NULL) {
140 "captype: Can't get pathname of directory containing the captype program: %s.\n",
141 init_progfile_dir_error);
142 g_free(init_progfile_dir_error);
145 init_report_message(failure_warning_message, failure_warning_message,
150 /* Process the options */
151 while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
156 printf("Captype (Wireshark) %s\n"
157 "Print the file types of capture files.\n"
158 "See https://www.wireshark.org for more information.\n",
159 get_ws_vcs_version_info());
165 comp_info_str = get_compiled_version_info(NULL, NULL);
166 runtime_info_str = get_runtime_version_info(NULL);
167 show_version("Captype (Wireshark)", comp_info_str, runtime_info_str);
168 g_string_free(comp_info_str, TRUE);
169 g_string_free(runtime_info_str, TRUE);
173 case '?': /* Bad flag - print usage message */
185 overall_error_status = 0;
187 for (i = 1; i < argc; i++) {
188 wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
191 printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
194 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
195 printf("%s: unknown\n", argv[i]);
197 cfile_open_failure_message("captype", argv[i], err, err_info);
198 overall_error_status = 2; /* remember that an error has occurred */
206 return overall_error_status;
210 * Editor modelines - http://www.wireshark.org/tools/modelines.html
215 * indent-tabs-mode: nil
218 * vi: set shiftwidth=2 tabstop=8 expandtab:
219 * :indentSize=2:tabSize=8:noTabs=true: