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
15 #define WS_LOG_DOMAIN LOG_DOMAIN_MAIN
23 #include <wsutil/ws_getopt.h>
27 #include <wiretap/wtap.h>
29 #include <wsutil/cmdarg_err.h>
30 #include <wsutil/file_util.h>
31 #include <wsutil/filesystem.h>
32 #include <wsutil/privileges.h>
34 #include <wsutil/version_info.h>
37 #include <wsutil/plugins.h>
40 #include <wsutil/str_util.h>
41 #include <wsutil/wslog.h>
43 #include "ui/failure_message.h"
46 print_usage(FILE *output
)
48 fprintf(output
, "\n");
49 fprintf(output
, "Usage: captype [options] <infile> ...\n");
50 fprintf(output
, "\n");
51 fprintf(output
, "Miscellaneous:\n");
52 fprintf(output
, " -h, --help display this help and exit\n");
53 fprintf(output
, " -v, --version display version info and exit\n");
57 main(int argc
, char *argv
[])
59 char *configuration_init_error
;
65 int overall_error_status
;
66 static const struct ws_option long_options
[] = {
67 {"help", ws_no_argument
, NULL
, 'h'},
68 {"version", ws_no_argument
, NULL
, 'v'},
72 /* Set the program name. */
73 g_set_prgname("captype");
76 * Set the C-language locale to the native environment and set the
77 * code page to UTF-8 on Windows.
80 setlocale(LC_ALL
, ".UTF-8");
82 setlocale(LC_ALL
, "");
85 cmdarg_err_init(stderr_cmdarg_err
, stderr_cmdarg_err_cont
);
87 /* Initialize log handler early so we can have proper logging during startup. */
88 ws_log_init(vcmdarg_err
);
90 /* Early logging command-line initialization. */
91 ws_log_parse_args(&argc
, argv
, vcmdarg_err
, 1);
93 ws_noisy("Finished log init and parsing command line log arguments");
96 create_app_running_mutex();
100 * Get credential information for later use.
102 init_process_policies();
105 * Attempt to get the pathname of the directory containing the
108 configuration_init_error
= configuration_init(argv
[0]);
109 if (configuration_init_error
!= NULL
) {
111 "captype: Can't get pathname of directory containing the captype program: %s.\n",
112 configuration_init_error
);
113 g_free(configuration_init_error
);
116 /* Initialize the version information. */
117 ws_init_version_info("Captype", NULL
, NULL
);
119 init_report_failure_message("captype");
123 /* Process the options */
124 while ((opt
= ws_getopt_long(argc
, argv
, "hv", long_options
, NULL
)) !=-1) {
129 show_help_header("Print the file types of capture files.");
139 case '?': /* Bad flag - print usage message */
151 overall_error_status
= 0;
153 for (i
= 1; i
< argc
; i
++) {
154 wth
= wtap_open_offline(argv
[i
], WTAP_TYPE_AUTO
, &err
, &err_info
, false);
157 printf("%s: %s\n", argv
[i
], wtap_file_type_subtype_name(wtap_file_type_subtype(wth
)));
160 if (err
== WTAP_ERR_FILE_UNKNOWN_FORMAT
)
161 printf("%s: unknown\n", argv
[i
]);
163 cfile_open_failure_message(argv
[i
], err
, err_info
);
164 overall_error_status
= 2; /* remember that an error has occurred */
172 return overall_error_status
;