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 <ui/cmdarg_err.h>
32 #include <wsutil/file_util.h>
33 #include <wsutil/filesystem.h>
34 #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>
45 #ifndef HAVE_GETOPT_LONG
46 #include "wsutil/wsgetopt.h"
49 #include "ui/failure_message.h"
52 print_usage(FILE *output)
54 fprintf(output, "\n");
55 fprintf(output, "Usage: captype <infile> ...\n");
59 * General errors and warnings are reported with an console message
63 failure_warning_message(const char *msg_format, va_list ap)
65 fprintf(stderr, "captype: ");
66 vfprintf(stderr, msg_format, ap);
67 fprintf(stderr, "\n");
71 * Report additional information for an error in command-line arguments.
74 failure_message_cont(const char *msg_format, va_list ap)
76 vfprintf(stderr, msg_format, ap);
77 fprintf(stderr, "\n");
81 main(int argc, char *argv[])
83 char *init_progfile_dir_error;
89 int overall_error_status;
90 static const struct option long_options[] = {
91 {"help", no_argument, NULL, 'h'},
92 {"version", no_argument, NULL, 'v'},
96 /* Set the C-language locale to the native environment. */
97 setlocale(LC_ALL, "");
99 cmdarg_err_init(failure_warning_message, failure_message_cont);
101 /* Initialize the version information. */
102 ws_init_version_info("Captype (Wireshark)", NULL, NULL, NULL);
105 create_app_running_mutex();
109 * Get credential information for later use.
111 init_process_policies();
114 * Attempt to get the pathname of the directory containing the
117 init_progfile_dir_error = init_progfile_dir(argv[0]);
118 if (init_progfile_dir_error != NULL) {
120 "captype: Can't get pathname of directory containing the captype program: %s.\n",
121 init_progfile_dir_error);
122 g_free(init_progfile_dir_error);
125 init_report_message(failure_warning_message, failure_warning_message,
130 /* Process the options */
131 while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
136 show_help_header("Print the file types of capture files.");
146 case '?': /* Bad flag - print usage message */
158 overall_error_status = 0;
160 for (i = 1; i < argc; i++) {
161 wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, FALSE);
164 printf("%s: %s\n", argv[i], wtap_file_type_subtype_short_string(wtap_file_type_subtype(wth)));
167 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
168 printf("%s: unknown\n", argv[i]);
170 cfile_open_failure_message("captype", argv[i], err, err_info);
171 overall_error_status = 2; /* remember that an error has occurred */
179 return overall_error_status;
183 * Editor modelines - http://www.wireshark.org/tools/modelines.html
188 * indent-tabs-mode: nil
191 * vi: set shiftwidth=2 tabstop=8 expandtab:
192 * :indentSize=2:tabSize=8:noTabs=true: