TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / captype.c
blob10b523e22e1f1d167b500b66dfdff1aeac9e6913
1 /* captype.c
2 * Reports capture file type
4 * Based on capinfos.c
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
14 #include <config.h>
15 #define WS_LOG_DOMAIN LOG_DOMAIN_MAIN
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <stdarg.h>
21 #include <locale.h>
23 #include <wsutil/ws_getopt.h>
25 #include <glib.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>
33 #include <cli_main.h>
34 #include <wsutil/version_info.h>
36 #ifdef HAVE_PLUGINS
37 #include <wsutil/plugins.h>
38 #endif
40 #include <wsutil/str_util.h>
41 #include <wsutil/wslog.h>
43 #include "ui/failure_message.h"
45 static void
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");
56 int
57 main(int argc, char *argv[])
59 char *configuration_init_error;
60 wtap *wth;
61 int err;
62 char *err_info;
63 int i;
64 int opt;
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'},
69 {0, 0, 0, 0 }
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.
79 #ifdef _WIN32
80 setlocale(LC_ALL, ".UTF-8");
81 #else
82 setlocale(LC_ALL, "");
83 #endif
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");
95 #ifdef _WIN32
96 create_app_running_mutex();
97 #endif /* _WIN32 */
100 * Get credential information for later use.
102 init_process_policies();
105 * Attempt to get the pathname of the directory containing the
106 * executable file.
108 configuration_init_error = configuration_init(argv[0]);
109 if (configuration_init_error != NULL) {
110 fprintf(stderr,
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");
121 wtap_init(true);
123 /* Process the options */
124 while ((opt = ws_getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
126 switch (opt) {
128 case 'h':
129 show_help_header("Print the file types of capture files.");
130 print_usage(stdout);
131 exit(0);
132 break;
134 case 'v':
135 show_version();
136 exit(0);
137 break;
139 case '?': /* Bad flag - print usage message */
140 print_usage(stderr);
141 exit(1);
142 break;
146 if (argc < 2) {
147 print_usage(stderr);
148 return 1;
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);
156 if(wth) {
157 printf("%s: %s\n", argv[i], wtap_file_type_subtype_name(wtap_file_type_subtype(wth)));
158 wtap_close(wth);
159 } else {
160 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
161 printf("%s: unknown\n", argv[i]);
162 else {
163 cfile_open_failure_message(argv[i], err, err_info);
164 overall_error_status = 2; /* remember that an error has occurred */
170 wtap_cleanup();
171 free_progdirs();
172 return overall_error_status;