3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <zlib.h> /* to get the libz version number */
38 #ifndef HAVE_GETOPT_LONG
39 #include "wsutil/wsgetopt.h"
42 #include <wsutil/clopts_common.h>
43 #include <wsutil/cmdarg_err.h>
44 #include <wsutil/crash_info.h>
45 #include <wsutil/filesystem.h>
46 #include <wsutil/privileges.h>
48 #include <wsutil/plugins.h>
50 #include <wsutil/report_err.h>
51 #include <wsutil/u3.h>
52 #include <wsutil/ws_diag_control.h>
53 #include <wsutil/ws_version_info.h>
55 #include <epan/addr_resolv.h>
56 #include <epan/ex-opt.h>
58 #include <epan/stat_tap_ui.h>
59 #include <epan/column.h>
60 #include <epan/disabled_protos.h>
63 #include <epan/packet.h>
64 #include <epan/asn1.h>
65 #include <epan/dissectors/packet-kerberos.h>
69 #include <codecs/codecs.h>
72 /* general (not Qt specific) */
75 #include "color_filters.h"
79 #include "ui/alert_box.h"
80 #include "ui/console.h"
81 #include "ui/iface_lists.h"
82 #include "ui/language.h"
83 #include "ui/persfilepath_opt.h"
84 #include "ui/recent.h"
85 #include "ui/simple_dialog.h"
87 #include "ui/qt/simple_dialog.h"
88 #include "ui/qt/main_window.h"
89 #include "ui/qt/splash_overlay.h"
90 #include "ui/qt/wireshark_application.h"
92 #include "caputils/capture-pcap-util.h"
95 # include "caputils/capture-wpcap.h"
96 # include "caputils/capture_wpcap_packet.h"
97 # include <tchar.h> /* Needed for Unicode */
98 # include <wsutil/file_util.h>
99 # include <wsutil/os_version_info.h>
103 # include <caputils/airpcap.h>
104 # include <caputils/airpcap_loader.h>
105 //# include "airpcap_dlg.h"
106 //# include "airpcap_gui_utils.h"
109 #include "epan/crypt/airpdcap_ws.h"
111 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
112 #include <QTextCodec>
115 #include "ui/qt/conversation_dialog.h"
116 #include "ui/qt/endpoint_dialog.h"
119 capture_options global_capture_opts;
123 int airpcap_dll_ret_val = -1;
126 GString *comp_info_str, *runtime_info_str;
128 /* update the main window */
129 void main_window_update(void)
131 WiresharkApplication::processEvents();
136 /* quit a nested main window */
137 void main_window_nested_quit(void)
139 // if (gtk_main_level() > 0)
143 /* quit the main window */
144 void main_window_quit(void)
149 #endif /* HAVE_LIBPCAP */
152 // xxx copied from ../gtk/main.c
154 print_usage(gboolean for_help_option) {
161 if (for_help_option) {
163 fprintf(output, "Wireshark %s\n"
164 "Interactively dump and analyze network traffic.\n"
165 "See http://www.wireshark.org for more information.\n",
166 get_ws_vcs_version_info());
170 fprintf(output, "\n");
171 fprintf(output, "Usage: wireshark [options] ... [ <infile> ]\n");
172 fprintf(output, "\n");
175 fprintf(output, "Capture interface:\n");
176 fprintf(output, " -i <interface> name or idx of interface (def: first non-loopback)\n");
177 fprintf(output, " -f <capture filter> packet filter in libpcap filter syntax\n");
178 fprintf(output, " -s <snaplen> packet snapshot length (def: 65535)\n");
179 fprintf(output, " -p don't capture in promiscuous mode\n");
180 fprintf(output, " -k start capturing immediately (def: do nothing)\n");
181 fprintf(output, " -S update packet display when new packets are captured\n");
182 fprintf(output, " -l turn on automatic scrolling while -S is in use\n");
183 #ifdef HAVE_PCAP_CREATE
184 fprintf(output, " -I capture in monitor mode, if available\n");
186 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
187 fprintf(output, " -B <buffer size> size of kernel buffer (def: %dMB)\n", DEFAULT_CAPTURE_BUFFER_SIZE);
189 fprintf(output, " -y <link type> link layer type (def: first appropriate)\n");
190 fprintf(output, " -D print list of interfaces and exit\n");
191 fprintf(output, " -L print list of link-layer types of iface and exit\n");
192 fprintf(output, "\n");
193 fprintf(output, "Capture stop conditions:\n");
194 fprintf(output, " -c <packet count> stop after n packets (def: infinite)\n");
195 fprintf(output, " -a <autostop cond.> ... duration:NUM - stop after NUM seconds\n");
196 fprintf(output, " filesize:NUM - stop this file after NUM KB\n");
197 fprintf(output, " files:NUM - stop after NUM files\n");
198 /*fprintf(output, "\n");*/
199 fprintf(output, "Capture output:\n");
200 fprintf(output, " -b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs\n");
201 fprintf(output, " filesize:NUM - switch to next file after NUM KB\n");
202 fprintf(output, " files:NUM - ringbuffer: replace after NUM files\n");
203 #endif /* HAVE_LIBPCAP */
204 #ifdef HAVE_PCAP_REMOTE
205 fprintf(output, "RPCAP options:\n");
206 fprintf(output, " -A <user>:<password> use RPCAP password authentication\n");
208 /*fprintf(output, "\n");*/
209 fprintf(output, "Input file:\n");
210 fprintf(output, " -r <infile> set the filename to read from (no pipes or stdin!)\n");
212 fprintf(output, "\n");
213 fprintf(output, "Processing:\n");
214 fprintf(output, " -R <read filter> packet filter in Wireshark display filter syntax\n");
215 fprintf(output, " -n disable all name resolutions (def: all enabled)\n");
216 fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mntC\"\n");
218 fprintf(output, "\n");
219 fprintf(output, "User interface:\n");
220 fprintf(output, " -C <config profile> start with specified configuration profile\n");
221 fprintf(output, " -Y <display filter> start with the given display filter\n");
222 fprintf(output, " -g <packet number> go to specified packet number after \"-r\"\n");
223 fprintf(output, " -J <jump filter> jump to the first packet matching the (display)\n");
224 fprintf(output, " filter\n");
225 fprintf(output, " -j search backwards for a matching packet after \"-J\"\n");
226 fprintf(output, " -m <font> set the font name used for most text\n");
227 fprintf(output, " -t a|ad|d|dd|e|r|u|ud output format of time stamps (def: r: rel. to first)\n");
228 fprintf(output, " -u s|hms output format of seconds (def: s: seconds)\n");
229 fprintf(output, " -X <key>:<value> eXtension options, see man page for details\n");
230 fprintf(output, " -z <statistics> show various statistics, see man page for details\n");
232 fprintf(output, "\n");
233 fprintf(output, "Output:\n");
234 fprintf(output, " -w <outfile|-> set the output filename (or '-' for stdout)\n");
236 fprintf(output, "\n");
237 fprintf(output, "Miscellaneous:\n");
238 fprintf(output, " -h display this help and exit\n");
239 fprintf(output, " -v display version info and exit\n");
240 fprintf(output, " -P <key>:<path> persconf:path - personal configuration files\n");
241 fprintf(output, " persdata:path - personal data files\n");
242 fprintf(output, " -o <name>:<value> ... override preference or recent setting\n");
243 fprintf(output, " -K <keytab> keytab file to use for kerberos decryption\n");
245 fprintf(output, " --display=DISPLAY X display to use\n");
247 fprintf(output, "\nNOTE: Not all options are implemented in the Qt port.\n");
255 * Report an error in command-line arguments.
256 * Creates a console on Windows.
258 // xxx copied from ../gtk/main.c
260 wireshark_cmdarg_err(const char *fmt, va_list ap)
265 fprintf(stderr, "wireshark: ");
266 vfprintf(stderr, fmt, ap);
267 fprintf(stderr, "\n");
271 * Report additional information for an error in command-line arguments.
272 * Creates a console on Windows.
273 * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
274 * terminal isn't the standard error?
276 // xxx copied from ../gtk/main.c
278 wireshark_cmdarg_err_cont(const char *fmt, va_list ap)
283 vfprintf(stderr, fmt, ap);
284 fprintf(stderr, "\n");
287 // xxx based from ../gtk/main.c:get_gtk_compiled_info
289 get_wireshark_qt_compiled_info(GString *str)
291 g_string_append(str, "with ");
292 g_string_append_printf(str,
294 "Qt %s", QT_VERSION_STR);
296 "Qt (version unknown)");
299 /* Capture libraries */
300 g_string_append(str, ", ");
301 get_compiled_caplibs_version(str);
304 g_string_append(str, ", ");
306 g_string_append(str, "with libz ");
308 g_string_append(str, ZLIB_VERSION);
309 #else /* ZLIB_VERSION */
310 g_string_append(str, "(version unknown)");
311 #endif /* ZLIB_VERSION */
312 #else /* HAVE_LIBZ */
313 g_string_append(str, "without libz");
314 #endif /* HAVE_LIBZ */
317 // xxx copied from ../gtk/main.c
319 get_gui_compiled_info(GString *str)
321 epan_get_compiled_version_info(str);
323 g_string_append(str, ", ");
324 g_string_append(str, "without PortAudio");
326 g_string_append(str, ", ");
328 get_compiled_airpcap_version(str);
330 g_string_append(str, "without AirPcap");
334 // xxx copied from ../gtk/main.c
336 get_wireshark_runtime_info(GString *str)
339 /* Capture libraries */
340 g_string_append(str, ", ");
341 get_runtime_caplibs_version(str);
345 #if defined(HAVE_LIBZ) && !defined(_WIN32)
346 g_string_append_printf(str, ", with libz %s", zlibVersion());
349 /* stuff used by libwireshark */
350 epan_get_runtime_version_info(str);
353 g_string_append(str, ", ");
354 get_runtime_airpcap_version(str);
358 g_string_append(str, ", ");
359 u3_runtime_info(str);
364 /* Check if there's something important to tell the user during startup.
365 * We want to do this *after* showing the main window so that any windows
366 * we pop up will be above the main window.
369 check_and_warn_user_startup(const QString &cf_name)
374 gchar *cur_user, *cur_group;
376 /* Tell the user not to run as root. */
377 if (running_with_special_privs() && recent.privs_warn_if_elevated) {
378 cur_user = get_cur_username();
379 cur_group = get_cur_groupname();
380 simple_message_box(ESD_TYPE_WARN, &recent.privs_warn_if_elevated,
381 "Running as user \"%s\" and group \"%s\".\n"
382 "This could be dangerous.\n\n"
383 "If you're running Wireshark this way in order to perform live capture, "
384 "you may want to be aware that there is a better way documented at\n"
385 "https://wiki.wireshark.org/CaptureSetup/CapturePrivileges", cur_user, cur_group);
391 /* Warn the user if npf.sys isn't loaded. */
392 if (!get_stdin_capture() && cf_name.isEmpty() && !npf_sys_is_running() && recent.privs_warn_if_no_npf && get_windows_major_version() >= 6) {
393 simple_message_box(ESD_TYPE_WARN, &recent.privs_warn_if_no_npf, "%s",
394 "The NPF driver isn't running. You may have trouble\n"
395 "capturing or listing interfaces.");
403 // Try to avoid library search path collisions. QCoreApplication will
404 // search QT_INSTALL_PREFIX/plugins for platform DLLs before searching
405 // the application directory. If
407 // - You have Qt version 5.x.y installed in the default location
408 // (C:\Qt\5.x) on your machine.
412 // - You install Wireshark that was built on a machine with Qt version
413 // 5.x.z installed in the default location.
415 // Qt5Core.dll will load qwindows.dll from your local C:\Qt\5.x\...\plugins
416 // directory. This may not be compatible with qwindows.dll from that
417 // same path on the build machine. At any rate, loading DLLs from paths
418 // you don't control is ill-advised. We work around this by removing every
419 // path except our application directory.
422 reset_library_path(void)
424 QString app_path = QDir(get_progfile_dir()).path();
425 foreach (QString path, QCoreApplication::libraryPaths()) {
426 QCoreApplication::removeLibraryPath(path);
428 QCoreApplication::addLibraryPath(app_path);
432 /* And now our feature presentation... [ fade to music ] */
433 int main(int argc, char *argv[])
438 gboolean arg_error = FALSE;
446 char *gdp_path, *dp_path;
449 gboolean start_capture = FALSE;
450 gboolean list_link_layer_types = FALSE;
455 gboolean capture_option_specified = FALSE;
464 guint go_to_packet = 0;
466 QString dfilter, read_filter;
468 cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
471 create_app_running_mutex();
475 * Get credential information for later use, and drop privileges
476 * before doing anything else.
477 * Let the user know if anything happened.
479 init_process_policies();
480 relinquish_special_privs_perm();
483 * Attempt to get the pathname of the executable file.
485 /* init_progfile_dir_error = */ init_progfile_dir(argv[0],
486 (void *) get_gui_compiled_info);
487 g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir());
489 /* Get the compile-time version information string */
491 comp_info_str = get_compiled_version_info(get_wireshark_qt_compiled_info,
492 get_gui_compiled_info);
494 /* Assemble the run-time version information string */
496 runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info);
499 * In order to have the -X opts assigned before the wslua machine starts
500 * we need to call getopt_long before epan_init() gets called.
502 * In addition, we process "console only" parameters (ones where we
503 * send output to the console and exit) here, so we don't start Qt
504 * if we're only showing command-line help or version information.
506 * XXX - this pre-scan is done before we start Qt, so we haven't
507 * run WiresharkApplication's constructor on the arguments. That
508 * means that Qt arguments have not been removed from the argument
509 * list; those arguments begin with "-", and may be treated as
510 * errors by getopt_long().
512 * We thus ignore errors - *and* set "opterr" to 0 to suppress the
515 * XXX - is there some way to parse and remove Qt arguments without
516 * starting up the GUI, which we can call before calling this?
518 * In order to handle, for example, -o options, we also need to call it
519 * *after* epan_init() gets called, so that the dissectors have had a
520 * chance to register their preferences, so we have another getopt_long()
523 * XXX - can we do this all with one getopt_long() call, saving the
524 * arguments we can't handle until after initializing libwireshark,
525 * and then process them after initializing libwireshark?
527 * Note that we don't want to initialize libwireshark until after the
528 * GUI is up, as that can take a while, and we want a window of some
529 * sort up to show progress while that's happening.
531 // XXX Should the remaining code be in WiresharkApplcation::WiresharkApplication?
532 #define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:g:Hh" "jJ:kK:lm:nN:o:P:r:R:St:u:vw:X:Y:z:"
534 static const struct option long_options[] = {
535 {(char *)"help", no_argument, NULL, 'h'},
536 {(char *)"read-file", required_argument, NULL, 'r' },
537 {(char *)"read-filter", required_argument, NULL, 'R' },
538 {(char *)"display-filter", required_argument, NULL, 'Y' },
539 {(char *)"version", no_argument, NULL, 'v'},
540 LONGOPT_CAPTURE_COMMON
544 static const char optstring[] = OPTSTRING;
548 while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
550 case 'C': /* Configuration Profile */
551 if (profile_exists (optarg, FALSE)) {
552 set_profile_name (optarg);
554 cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
558 case 'D': /* Print a list of capture devices and exit */
560 if_list = capture_interface_list(&err, &err_str, NULL);
561 if (if_list == NULL) {
563 cmdarg_err("There are no interfaces on which a capture can be done");
565 cmdarg_err("%s", err_str);
573 capture_opts_print_interfaces(if_list);
574 free_interface_list(if_list);
579 #else /* HAVE_LIBPCAP */
580 capture_option_specified = TRUE;
582 #endif /* HAVE_LIBPCAP */
584 case 'h': /* Print help and exit */
590 if (strcmp(optarg, "-") == 0)
591 set_stdin_capture(TRUE);
594 case 'P': /* Personal file directory path settings - change these before the Preferences and alike are processed */
595 if (!persfilepath_opt(opt, optarg)) {
596 cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg);
600 case 'v': /* Show version and exit */
604 show_version("Wireshark", comp_info_str, runtime_info_str);
612 * Extension command line options have to be processed before
613 * we call epan_init() as they are supposed to be used by dissectors
614 * or taps very early in the registration process.
618 case '?': /* Ignore errors - the "real" scan will catch them. */
624 reset_library_path();
627 /* Create The Wireshark app */
628 WiresharkApplication ws_app(argc, argv);
630 /* initialize the funnel mini-api */
632 //initialize_funnel_ops();
634 AirPDcapInitContext(&airpdcap_ctx);
638 /* Load wpcap if possible. Do this before collecting the run-time version information */
641 /* ... and also load the packet.dll from wpcap */
645 /* Load the airpcap.dll. This must also be done before collecting
646 * run-time version information. */
647 airpcap_dll_ret_val = load_airpcap();
649 switch (airpcap_dll_ret_val) {
651 /* load the airpcap interfaces */
652 airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
654 if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){
655 if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) {
656 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters.");
659 airpcap_if_active = NULL;
663 /* select the first ad default (THIS SHOULD BE CHANGED) */
664 airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
669 * XXX - Maybe we need to warn the user if one of the following happens???
671 case AIRPCAP_DLL_OLD:
672 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n");
675 case AIRPCAP_DLL_ERROR:
676 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n");
679 case AIRPCAP_DLL_NOT_FOUND:
680 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n");
684 #endif /* HAVE_AIRPCAP */
689 unsigned int in_file_type = WTAP_TYPE_AUTO;
691 // In Qt 5, C strings are treated always as UTF-8 when converted to
692 // QStrings; in Qt 4, the codec must be set to make that happen
693 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
694 // Hopefully we won't have to use QString::fromUtf8() in as many places.
695 QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8");
696 QTextCodec::setCodecForCStrings(utf8codec);
697 // XXX - QObject doesn't *have* a tr method in 5.0, as far as I can see...
698 QTextCodec::setCodecForTr(utf8codec);
701 /* Add it to the information to be reported on a crash. */
702 ws_add_crash_info("Wireshark %s\n"
707 get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
710 /* Start windows sockets */
711 WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
714 profile_store_persconffiles(TRUE);
716 /* Read the profile independent recent file. We have to do this here so we can */
717 /* set the profile before it can be set from the command line parameter */
718 recent_read_static(&rf_path, &rf_open_errno);
719 if (rf_path != NULL && rf_open_errno != 0) {
720 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
721 "Could not open common recent file\n\"%s\": %s.",
722 rf_path, strerror(rf_open_errno));
725 /* Init the "Open file" dialog directory */
726 /* (do this after the path settings are processed) */
728 /* Read the profile dependent (static part) of the recent file. */
729 /* Only the static part of it will be read, as we don't have the gui now to fill the */
730 /* recent lists which is done in the dynamic part. */
731 /* We have to do this already here, so command line parameters can overwrite these values. */
732 recent_read_profile_static(&rf_path, &rf_open_errno);
733 if (rf_path != NULL && rf_open_errno != 0) {
734 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
735 "Could not open recent file\n\"%s\": %s.",
736 rf_path, g_strerror(rf_open_errno));
739 // Initialize our language
740 read_language_prefs();
741 locale = QString(language);
742 wsApp->loadLanguage(locale);
744 g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Translator %s", locale.toStdString().c_str());
746 // Init the main window (and splash)
747 main_w = new(MainWindow);
749 // We may not need a queued connection here but it would seem to make sense
750 // to force the issue.
751 main_w->connect(&ws_app, SIGNAL(openCaptureFile(QString&,QString&,unsigned int)),
752 main_w, SLOT(openCaptureFile(QString&,QString&,unsigned int)));
754 /* Init the "Open file" dialog directory */
755 /* (do this after the path settings are processed) */
757 /* Read the profile dependent (static part) of the recent file. */
758 /* Only the static part of it will be read, as we don't have the gui now to fill the */
759 /* recent lists which is done in the dynamic part. */
760 /* We have to do this already here, so command line parameters can overwrite these values. */
761 recent_read_profile_static(&rf_path, &rf_open_errno);
762 if (rf_path != NULL && rf_open_errno != 0) {
763 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
764 "Could not open recent file\n\"%s\": %s.",
765 rf_path, g_strerror(rf_open_errno));
768 if (recent.gui_fileopen_remembered_dir &&
769 test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
770 wsApp->setLastOpenDir(recent.gui_fileopen_remembered_dir);
772 wsApp->setLastOpenDir(get_persdatafile_dir());
776 // Replicates behavior in gtk_init();
777 signal(SIGPIPE, SIG_IGN);
780 set_console_log_handler();
783 /* Set the initial values in the capture options. This might be overwritten
784 by preference settings and then again by the command line parameters. */
785 capture_opts_init(&global_capture_opts);
788 init_report_err(failure_alert_box, open_failure_alert_box,
789 read_failure_alert_box, write_failure_alert_box);
791 init_open_routines();
794 /* Register all the plugin types we have. */
795 epan_register_plugin_types(); /* Types known to libwireshark */
796 wtap_register_plugin_types(); /* Types known to libwiretap */
797 codec_register_plugin_types(); /* Types known to libcodec */
799 /* Scan for plugins. This does *not* call their registration routines;
800 that's done later. */
803 /* Register all libwiretap plugin modules. */
804 register_all_wiretap_modules();
806 /* Register all audio codec plugins. */
807 register_all_codecs();
810 /* Register all dissectors; we must do this before checking for the
811 "-G" flag, as the "-G" flag dumps information registered by the
812 dissectors, and we must do it before we read the preferences, in
813 case any dissectors register preferences. */
814 epan_init(register_all_protocols,register_all_protocol_handoffs,
815 splash_update, NULL);
817 splash_update(RA_LISTENERS, NULL, NULL);
819 /* Register all tap listeners; we do this before we parse the arguments,
820 as the "-z" argument can specify a registered tap. */
822 /* we register the plugin taps before the other taps because
823 stats_tree taps plugins will be registered as tap listeners
824 by stats_tree_stat.c and need to registered before that */
826 g_log(NULL, G_LOG_LEVEL_DEBUG, "plugin_dir: %s", get_plugin_dir());
828 register_all_plugin_tap_listeners();
831 register_all_tap_listeners();
832 conversation_table_set_gui_info(init_conversation_table);
833 hostlist_table_set_gui_info(init_endpoint_table);
835 if (ex_opt_count("read_format") > 0) {
836 in_file_type = open_info_name_to_type(ex_opt_get_next("read_format"));
839 splash_update(RA_PREFERENCES, NULL, NULL);
841 prefs_p = ws_app.readConfigurationFiles(&gdp_path, &dp_path);
844 * To reset the options parser, set optreset to 1 on platforms that
845 * have optreset (documented in *BSD and OS X, apparently present but
846 * not documented in Solaris - the Illumos repository seems to
847 * suggest that the first Solaris getopt_long(), at least as of 2004,
848 * was based on the NetBSD one, it had optreset) and set optind to 1,
849 * and set optind to 0 otherwise (documented as working in the GNU
850 * getopt_long(). Setting optind to 0 didn't originally work in the
851 * NetBSD one, but that was added later - we don't want to depend on
852 * it if we have optreset).
854 * Also reset opterr to 1, so that error messages are printed by
857 * XXX - if we want to control all the command-line option errors, so
858 * that we can display them where we choose (e.g., in a window), we'd
859 * want to leave opterr as 0, and produce our own messages using optopt.
860 * We'd have to check the value of optopt to see if it's a valid option
861 * letter, in which case *presumably* the error is "this option requires
862 * an argument but none was specified", or not a valid option letter,
863 * in which case *presumably* the error is "this option isn't valid".
864 * Some versions of getopt() let you supply a option string beginning
865 * with ':', which means that getopt() will return ':' rather than '?'
866 * for "this option requires an argument but none was specified", but
867 * not all do. But we're now using getopt_long() - what does it do?
877 /* Now get our args */
878 while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
880 /*** capture option specific ***/
881 case 'a': /* autostop criteria */
882 case 'b': /* Ringbuffer option */
883 case 'c': /* Capture xxx packets */
884 case 'f': /* capture filter */
885 case 'k': /* Start capture immediately */
886 case 'H': /* Hide capture info dialog box */
887 case 'p': /* Don't capture in promiscuous mode */
888 case 'i': /* Use interface x */
889 #ifdef HAVE_PCAP_CREATE
890 case 'I': /* Capture in monitor mode, if available */
892 #ifdef HAVE_PCAP_REMOTE
893 case 'A': /* Authentication */
895 case 's': /* Set the snapshot (capture) length */
896 case 'S': /* "Sync" mode: used for following file ala tail -f */
897 case 'w': /* Write to capture file xxx */
898 case 'y': /* Set the pcap data link type */
899 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
900 case 'B': /* Buffer size */
901 #endif /* _WIN32 or HAVE_PCAP_CREATE */
903 status = capture_opts_add_opt(&global_capture_opts, opt, optarg,
909 capture_option_specified = TRUE;
914 case 'K': /* Kerberos keytab file */
915 read_keytab_file(optarg);
919 /*** all non capture option specific ***/
921 /* Configuration profile settings were already processed just ignore them this time*/
923 case 'j': /* Search backwards for a matching packet from filter in option J */
924 /* Not supported yet */
926 case 'g': /* Go to packet with the given packet number */
927 go_to_packet = get_positive_int(optarg, "go to packet");
929 case 'J': /* Jump to the first packet which matches the filter criteria */
930 /* Not supported yet */
932 case 'l': /* Automatic scrolling in live capture mode */
934 /* Not supported yet */
936 capture_option_specified = TRUE;
940 case 'L': /* Print list of link-layer types and exit */
942 list_link_layer_types = TRUE;
944 capture_option_specified = TRUE;
948 case 'm': /* Fixed-width font for the display */
949 /* Not supported yet */
951 case 'n': /* No name resolution */
952 gbl_resolv_flags.mac_name = FALSE;
953 gbl_resolv_flags.network_name = FALSE;
954 gbl_resolv_flags.transport_name = FALSE;
955 gbl_resolv_flags.concurrent_dns = FALSE;
957 case 'N': /* Select what types of addresses/port #s to resolve */
958 badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
959 if (badopt != '\0') {
960 cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
965 case 'o': /* Override preference from command line */
966 switch (prefs_set_pref(optarg)) {
969 case PREFS_SET_SYNTAX_ERR:
970 cmdarg_err("Invalid -o flag \"%s\"", optarg);
973 case PREFS_SET_NO_SUCH_PREF:
974 /* not a preference, might be a recent setting */
975 switch (recent_set_arg(optarg)) {
978 case PREFS_SET_SYNTAX_ERR:
979 /* shouldn't happen, checked already above */
980 cmdarg_err("Invalid -o flag \"%s\"", optarg);
983 case PREFS_SET_NO_SUCH_PREF:
984 case PREFS_SET_OBSOLETE:
985 cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
990 g_assert_not_reached();
993 case PREFS_SET_OBSOLETE:
994 cmdarg_err("-o flag \"%s\" specifies obsolete preference",
999 g_assert_not_reached();
1003 /* Path settings were already processed just ignore them this time*/
1008 case 'R': /* Read file filter */
1009 read_filter = QString(optarg);
1011 case 't': /* Time stamp type */
1012 if (strcmp(optarg, "r") == 0)
1013 timestamp_set_type(TS_RELATIVE);
1014 else if (strcmp(optarg, "a") == 0)
1015 timestamp_set_type(TS_ABSOLUTE);
1016 else if (strcmp(optarg, "ad") == 0)
1017 timestamp_set_type(TS_ABSOLUTE_WITH_YMD);
1018 else if (strcmp(optarg, "adoy") == 0)
1019 timestamp_set_type(TS_ABSOLUTE_WITH_YDOY);
1020 else if (strcmp(optarg, "d") == 0)
1021 timestamp_set_type(TS_DELTA);
1022 else if (strcmp(optarg, "dd") == 0)
1023 timestamp_set_type(TS_DELTA_DIS);
1024 else if (strcmp(optarg, "e") == 0)
1025 timestamp_set_type(TS_EPOCH);
1026 else if (strcmp(optarg, "u") == 0)
1027 timestamp_set_type(TS_UTC);
1028 else if (strcmp(optarg, "ud") == 0)
1029 timestamp_set_type(TS_UTC_WITH_YMD);
1030 else if (strcmp(optarg, "udoy") == 0)
1031 timestamp_set_type(TS_UTC_WITH_YDOY);
1033 cmdarg_err("Invalid time stamp type \"%s\"", optarg);
1035 "It must be \"a\" for absolute, \"ad\" for absolute with YYYY-MM-DD date,");
1037 "\"adoy\" for absolute with YYYY/DOY date, \"d\" for delta,");
1039 "\"dd\" for delta displayed, \"e\" for epoch, \"r\" for relative,");
1041 "\"u\" for absolute UTC, \"ud\" for absolute UTC with YYYY-MM-DD date,");
1043 "or \"udoy\" for absolute UTC with YYYY/DOY date.");
1047 case 'u': /* Seconds type */
1048 if (strcmp(optarg, "s") == 0)
1049 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
1050 else if (strcmp(optarg, "hms") == 0)
1051 timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
1053 cmdarg_err("Invalid seconds type \"%s\"", optarg);
1055 "It must be \"s\" for seconds or \"hms\" for hours, minutes and seconds.");
1060 /* ext ops were already processed just ignore them this time*/
1063 dfilter = QString(optarg);
1066 /* We won't call the init function for the stat this soon
1067 as it would disallow MATE's fields (which are registered
1068 by the preferences set callback) from being used as
1069 part of a tap filter. Instead, we just add the argument
1070 to a list of stat arguments. */
1071 if (strcmp("help", optarg) == 0) {
1072 fprintf(stderr, "wireshark: The available statistics for the \"-z\" option are:\n");
1073 list_stat_cmd_args();
1076 if (!process_stat_cmd_arg(optarg)) {
1077 cmdarg_err("Invalid -z argument.");
1078 cmdarg_err_cont(" -z argument must be one of :");
1079 list_stat_cmd_args();
1084 case '?': /* Bad flag - print usage message */
1095 if (!cf_name.isEmpty()) {
1097 * Input file name specified with "-r" *and* specified as a regular
1098 * command-line argument.
1100 cmdarg_err("File name specified both with -r and regular argument");
1104 * Input file name not specified with "-r", and a command-line argument
1105 * was specified; treat it as the input file name.
1107 * Yes, this is different from tshark, where non-flag command-line
1108 * arguments are a filter, but this works better on GUI desktops
1109 * where a command can be specified to be run to open a particular
1110 * file - yes, you could have "-r" as the last part of the command,
1111 * but that's a bit ugly.
1122 * Extra command line arguments were specified; complain.
1124 cmdarg_err("Invalid argument: %s", argv[0]);
1129 #ifndef HAVE_LIBPCAP
1130 if (capture_option_specified) {
1131 cmdarg_err("This version of Wireshark was not built with support for capturing packets.");
1138 /* Removed thread code:
1139 * https://code.wireshark.org/review/gitweb?p=wireshark.git;a=commit;h=9e277ae6154fd04bf6a0a34ec5655a73e5a736a3
1142 // XXX Is there a better place to set the timestamp format & precision?
1143 timestamp_set_type(recent.gui_time_format);
1144 timestamp_set_precision(recent.gui_time_precision);
1145 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
1148 fill_in_local_interfaces(main_window_update);
1150 if (start_capture && list_link_layer_types) {
1151 /* Specifying *both* is bogus. */
1152 cmdarg_err("You can't specify both -L and a live capture.");
1156 if (list_link_layer_types) {
1157 /* We're supposed to list the link-layer types for an interface;
1158 did the user also specify a capture file to be read? */
1159 if (!cf_name.isEmpty()) {
1160 /* Yes - that's bogus. */
1161 cmdarg_err("You can't specify -L and a capture file to be read.");
1164 /* No - did they specify a ring buffer option? */
1165 if (global_capture_opts.multi_files_on) {
1166 cmdarg_err("Ring buffer requested, but a capture isn't being done.");
1170 /* We're supposed to do a live capture; did the user also specify
1171 a capture file to be read? */
1172 if (start_capture && !cf_name.isEmpty()) {
1173 /* Yes - that's bogus. */
1174 cmdarg_err("You can't specify both a live capture and a capture file to be read.");
1178 /* No - was the ring buffer option specified and, if so, does it make
1180 if (global_capture_opts.multi_files_on) {
1181 /* Ring buffer works only under certain conditions:
1182 a) ring buffer does not work with temporary files;
1183 b) real_time_mode and multi_files_on are mutually exclusive -
1184 real_time_mode takes precedence;
1185 c) it makes no sense to enable the ring buffer if the maximum
1186 file size is set to "infinite". */
1187 if (global_capture_opts.save_file == NULL) {
1188 cmdarg_err("Ring buffer requested, but capture isn't being saved to a permanent file.");
1189 global_capture_opts.multi_files_on = FALSE;
1191 if (!global_capture_opts.has_autostop_filesize && !global_capture_opts.has_file_duration) {
1192 cmdarg_err("Ring buffer requested, but no maximum capture file size or duration were specified.");
1193 /* XXX - this must be redesigned as the conditions changed */
1198 if (start_capture || list_link_layer_types) {
1199 /* We're supposed to do a live capture or get a list of link-layer
1200 types for a live capture device; if the user didn't specify an
1201 interface to use, pick a default. */
1202 status = capture_opts_default_iface_if_necessary(&global_capture_opts,
1203 ((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
1209 if (list_link_layer_types) {
1210 /* Get the list of link-layer types for the capture devices. */
1211 if_capabilities_t *caps;
1214 for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
1216 device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
1217 if (device.selected) {
1218 #if defined(HAVE_PCAP_CREATE)
1219 caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, &err_str, main_window_update);
1221 caps = capture_get_if_capabilities(device.name, FALSE, &err_str,main_window_update);
1224 cmdarg_err("%s", err_str);
1228 if (caps->data_link_types == NULL) {
1229 cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
1235 #if defined(HAVE_PCAP_CREATE)
1236 capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
1238 capture_opts_print_if_capabilities(caps, device.name, FALSE);
1243 free_if_capabilities(caps);
1249 capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
1250 capture_opts_trim_ring_num_files(&global_capture_opts);
1251 #endif /* HAVE_LIBPCAP */
1253 /* Notify all registered modules that have had any of their preferences
1254 changed either from one of the preferences file or from the command
1255 line that their preferences have changed. */
1257 wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged);
1260 if ((global_capture_opts.num_selected == 0) &&
1261 (prefs.capture_device != NULL)) {
1264 for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
1265 device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
1266 if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) {
1267 device.selected = TRUE;
1268 global_capture_opts.num_selected++;
1269 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
1270 g_array_insert_val(global_capture_opts.all_ifaces, i, device);
1277 /* disabled protocols as per configuration file */
1278 if (gdp_path == NULL && dp_path == NULL) {
1279 set_disabled_protos_list();
1282 build_column_format_array(&CaptureFile::globalCapFile()->cinfo, prefs_p->num_cols, TRUE);
1283 wsApp->emitAppSignal(WiresharkApplication::ColumnsChanged); // We read "recent" widths above.
1284 wsApp->emitAppSignal(WiresharkApplication::RecentFilesRead); // Must be emitted after PreferencesChanged.
1286 wsApp->setMonospaceFont(prefs.gui_qt_font_name);
1290 /* Read the dynamic part of the recent file, as we have the gui now ready for
1292 recent_read_dynamic(&rf_path, &rf_open_errno);
1293 if (rf_path != NULL && rf_open_errno != 0) {
1294 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1295 "Could not open recent file\n\"%s\": %s.",
1296 rf_path, g_strerror(rf_open_errno));
1299 color_filters_enable(recent.packet_list_colorize);
1301 g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings");
1302 color_filters_enable(TRUE);
1308 color_filters_init();
1313 /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
1314 if (!start_capture && !global_capture_opts.default_options.cfilter) {
1315 global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
1317 #else /* HAVE_LIBPCAP */
1319 #endif /* HAVE_LIBPCAP */
1321 // w->setEnabled(true);
1322 wsApp->allSystemsGo();
1323 g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "Wireshark is up and ready to go");
1324 SimpleDialog::displayQueuedMessages(main_w);
1326 /* user could specify filename, or display filter, or both */
1327 if (!cf_name.isEmpty()) {
1329 /* Open stat windows; we do so after creating the main window,
1330 to avoid Qt warnings, and after successfully opening the
1331 capture file, so we know we have something to compute stats
1332 on, and after registering all dissectors, so that MATE will
1333 have registered its field array and we can have a tap filter
1334 with one of MATE's late-registered fields as part of the
1336 start_requested_stats();
1338 // XXX The GTK+ UI does error checking here.
1339 main_w->openCaptureFile(cf_name, read_filter, in_file_type);
1340 if (!dfilter.isEmpty())
1341 main_w->filterPackets(dfilter, false);
1342 if(go_to_packet != 0) {
1343 /* Jump to the specified frame number, kept for backward
1345 cf_goto_frame(CaptureFile::globalCapFile(), go_to_packet);
1350 if (start_capture) {
1351 if (global_capture_opts.save_file != NULL) {
1352 /* Save the directory name for future file dialogs. */
1353 /* (get_dirname overwrites filename) */
1354 gchar *s = get_dirname(g_strdup(global_capture_opts.save_file));
1355 set_last_open_dir(s);
1358 /* "-k" was specified; start a capture. */
1359 // show_main_window(FALSE);
1360 check_and_warn_user_startup(cf_name);
1362 /* If no user interfaces were specified on the command line,
1363 copy the list of selected interfaces to the set of interfaces
1364 to use for this capture. */
1365 if (global_capture_opts.ifaces->len == 0)
1366 collect_ifaces(&global_capture_opts);
1367 CaptureFile::globalCapFile()->window = main_w;
1368 if (capture_start(&global_capture_opts, main_w->captureSession(), main_window_update)) {
1369 /* The capture started. Open stat windows; we do so after creating
1370 the main window, to avoid GTK warnings, and after successfully
1371 opening the capture file, so we know we have something to compute
1372 stats on, and after registering all dissectors, so that MATE will
1373 have registered its field array and we can have a tap filter with
1374 one of MATE's late-registered fields as part of the filter. */
1375 start_requested_stats();
1378 /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
1379 if (!start_capture && !global_capture_opts.default_options.cfilter) {
1380 global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
1383 #endif /* HAVE_LIBPCAP */
1385 g_main_loop_new(NULL, FALSE);
1386 return wsApp->exec();
1395 * indent-tabs-mode: nil
1398 * ex: set shiftwidth=4 tabstop=8 expandtab:
1399 * :indentSize=4:tabSize=8:noTabs=true: