decrypt drsuapi attributes
[wireshark-sm.git] / captype.c
blobdd97a1cb8c38aba5d8e061d1de5d62d1e5d3c9a7
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");
57 * Report an error in command-line arguments.
59 static void
60 captype_cmdarg_err(const char *msg_format, va_list ap)
62 fprintf(stderr, "captype: ");
63 vfprintf(stderr, msg_format, ap);
64 fprintf(stderr, "\n");
68 * Report additional information for an error in command-line arguments.
70 static void
71 captype_cmdarg_err_cont(const char *msg_format, va_list ap)
73 vfprintf(stderr, msg_format, ap);
74 fprintf(stderr, "\n");
77 int
78 main(int argc, char *argv[])
80 char *configuration_init_error;
81 wtap *wth;
82 int err;
83 char *err_info;
84 int i;
85 int opt;
86 int overall_error_status;
87 static const struct ws_option long_options[] = {
88 {"help", ws_no_argument, NULL, 'h'},
89 {"version", ws_no_argument, NULL, 'v'},
90 {0, 0, 0, 0 }
94 * Set the C-language locale to the native environment and set the
95 * code page to UTF-8 on Windows.
97 #ifdef _WIN32
98 setlocale(LC_ALL, ".UTF-8");
99 #else
100 setlocale(LC_ALL, "");
101 #endif
103 cmdarg_err_init(captype_cmdarg_err, captype_cmdarg_err_cont);
105 /* Initialize log handler early so we can have proper logging during startup. */
106 ws_log_init("captype", vcmdarg_err);
108 /* Early logging command-line initialization. */
109 ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
111 ws_noisy("Finished log init and parsing command line log arguments");
113 /* Initialize the version information. */
114 ws_init_version_info("Captype", NULL, NULL);
116 #ifdef _WIN32
117 create_app_running_mutex();
118 #endif /* _WIN32 */
121 * Get credential information for later use.
123 init_process_policies();
126 * Attempt to get the pathname of the directory containing the
127 * executable file.
129 configuration_init_error = configuration_init(argv[0], NULL);
130 if (configuration_init_error != NULL) {
131 fprintf(stderr,
132 "captype: Can't get pathname of directory containing the captype program: %s.\n",
133 configuration_init_error);
134 g_free(configuration_init_error);
137 init_report_failure_message("captype");
139 wtap_init(true);
141 /* Process the options */
142 while ((opt = ws_getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
144 switch (opt) {
146 case 'h':
147 show_help_header("Print the file types of capture files.");
148 print_usage(stdout);
149 exit(0);
150 break;
152 case 'v':
153 show_version();
154 exit(0);
155 break;
157 case '?': /* Bad flag - print usage message */
158 print_usage(stderr);
159 exit(1);
160 break;
164 if (argc < 2) {
165 print_usage(stderr);
166 return 1;
169 overall_error_status = 0;
171 for (i = 1; i < argc; i++) {
172 wth = wtap_open_offline(argv[i], WTAP_TYPE_AUTO, &err, &err_info, false);
174 if(wth) {
175 printf("%s: %s\n", argv[i], wtap_file_type_subtype_name(wtap_file_type_subtype(wth)));
176 wtap_close(wth);
177 } else {
178 if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT)
179 printf("%s: unknown\n", argv[i]);
180 else {
181 cfile_open_failure_message(argv[i], err, err_info);
182 overall_error_status = 2; /* remember that an error has occurred */
188 wtap_cleanup();
189 free_progdirs();
190 return overall_error_status;