GSM_A-BCC: dissector for BCC Protocol
[metze/wireshark/wip.git] / wireshark-qt.cpp
1 /* wireshark-qt.cpp
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include <config.h>
23
24 #include <glib.h>
25
26 #ifdef Q_OS_UNIX
27 #include <signal.h>
28 #endif
29
30 #ifdef HAVE_LIBZ
31 #include <zlib.h>       /* to get the libz version number */
32 #endif
33
34 #ifdef HAVE_GETOPT_H
35 #include <getopt.h>
36 #endif
37
38 #ifndef HAVE_GETOPT_LONG
39 #include "wsutil/wsgetopt.h"
40 #endif
41
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>
47 #ifdef HAVE_PLUGINS
48 #include <wsutil/plugins.h>
49 #endif
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>
54
55 #include <epan/addr_resolv.h>
56 #include <epan/ex-opt.h>
57 #include <epan/tap.h>
58 #include <epan/stat_tap_ui.h>
59 #include <epan/column.h>
60 #include <epan/disabled_protos.h>
61
62 #ifdef HAVE_KERBEROS
63 #include <epan/packet.h>
64 #include <epan/asn1.h>
65 #include <epan/dissectors/packet-kerberos.h>
66 #endif
67
68 #ifdef HAVE_PLUGINS
69 #include <codecs/codecs.h>
70 #endif
71
72 /* general (not Qt specific) */
73 #include "file.h"
74 #include "color.h"
75 #include "color_filters.h"
76 #include "ui/util.h"
77 #include "log.h"
78
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"
86
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"
91
92 #include "caputils/capture-pcap-util.h"
93
94 #ifdef _WIN32
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>
100 #endif /* _WIN32 */
101
102 #ifdef HAVE_AIRPCAP
103 #  include <caputils/airpcap.h>
104 #  include <caputils/airpcap_loader.h>
105 //#  include "airpcap_dlg.h"
106 //#  include "airpcap_gui_utils.h"
107 #endif
108
109 #include "epan/crypt/airpdcap_ws.h"
110
111 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
112 #include <QTextCodec>
113 #endif
114
115 #include "ui/qt/conversation_dialog.h"
116 #include "ui/qt/endpoint_dialog.h"
117
118 #ifdef HAVE_LIBPCAP
119 capture_options global_capture_opts;
120 #endif
121
122 #ifdef HAVE_AIRPCAP
123 int    airpcap_dll_ret_val = -1;
124 #endif
125
126 GString *comp_info_str, *runtime_info_str;
127
128 /* update the main window */
129 void main_window_update(void)
130 {
131     WiresharkApplication::processEvents();
132 }
133
134 #ifdef HAVE_LIBPCAP
135
136 /* quit a nested main window */
137 void main_window_nested_quit(void)
138 {
139 //    if (gtk_main_level() > 0)
140     wsApp->quit();
141 }
142
143 /* quit the main window */
144 void main_window_quit(void)
145 {
146     wsApp->quit();
147 }
148
149 #endif /* HAVE_LIBPCAP */
150
151
152 // xxx copied from ../gtk/main.c
153 static void
154 print_usage(gboolean for_help_option) {
155     FILE *output;
156
157 #ifdef _WIN32
158     create_console();
159 #endif
160
161     if (for_help_option) {
162         output = stdout;
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());
167     } else {
168         output = stderr;
169     }
170     fprintf(output, "\n");
171     fprintf(output, "Usage: wireshark [options] ... [ <infile> ]\n");
172     fprintf(output, "\n");
173
174 #ifdef HAVE_LIBPCAP
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");
185 #endif
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);
188 #endif
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");
207 #endif
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");
211
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");
217
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");
231
232     fprintf(output, "\n");
233     fprintf(output, "Output:\n");
234     fprintf(output, "  -w <outfile|->           set the output filename (or '-' for stdout)\n");
235
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");
244 #ifndef _WIN32
245     fprintf(output, "  --display=DISPLAY        X display to use\n");
246 #endif
247     fprintf(output, "\nNOTE: Not all options are implemented in the Qt port.\n");
248
249 #ifdef _WIN32
250     destroy_console();
251 #endif
252 }
253
254 /*
255  * Report an error in command-line arguments.
256  * Creates a console on Windows.
257  */
258 // xxx copied from ../gtk/main.c
259 static void
260 wireshark_cmdarg_err(const char *fmt, va_list ap)
261 {
262 #ifdef _WIN32
263     create_console();
264 #endif
265     fprintf(stderr, "wireshark: ");
266     vfprintf(stderr, fmt, ap);
267     fprintf(stderr, "\n");
268 }
269
270 /*
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?
275  */
276 // xxx copied from ../gtk/main.c
277 static void
278 wireshark_cmdarg_err_cont(const char *fmt, va_list ap)
279 {
280 #ifdef _WIN32
281     create_console();
282 #endif
283     vfprintf(stderr, fmt, ap);
284     fprintf(stderr, "\n");
285 }
286
287 // xxx based from ../gtk/main.c:get_gtk_compiled_info
288 static void
289 get_wireshark_qt_compiled_info(GString *str)
290 {
291     g_string_append(str, "with ");
292     g_string_append_printf(str,
293 #ifdef QT_VERSION
294                     "Qt %s", QT_VERSION_STR);
295 #else
296                     "Qt (version unknown)");
297 #endif
298
299     /* Capture libraries */
300     g_string_append(str, ", ");
301     get_compiled_caplibs_version(str);
302
303     /* LIBZ */
304     g_string_append(str, ", ");
305 #ifdef HAVE_LIBZ
306     g_string_append(str, "with libz ");
307 #ifdef ZLIB_VERSION
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 */
315 }
316
317 // xxx copied from ../gtk/main.c
318 static void
319 get_gui_compiled_info(GString *str)
320 {
321     epan_get_compiled_version_info(str);
322
323     g_string_append(str, ", ");
324     g_string_append(str, "without PortAudio");
325
326     g_string_append(str, ", ");
327 #ifdef HAVE_AIRPCAP
328     get_compiled_airpcap_version(str);
329 #else
330     g_string_append(str, "without AirPcap");
331 #endif
332 }
333
334 // xxx copied from ../gtk/main.c
335 static void
336 get_wireshark_runtime_info(GString *str)
337 {
338 #ifdef HAVE_LIBPCAP
339     /* Capture libraries */
340     g_string_append(str, ", ");
341     get_runtime_caplibs_version(str);
342 #endif
343
344     /* zlib */
345 #if defined(HAVE_LIBZ) && !defined(_WIN32)
346     g_string_append_printf(str, ", with libz %s", zlibVersion());
347 #endif
348
349     /* stuff used by libwireshark */
350     epan_get_runtime_version_info(str);
351
352 #ifdef HAVE_AIRPCAP
353     g_string_append(str, ", ");
354     get_runtime_airpcap_version(str);
355 #endif
356
357     if(u3_active()) {
358         g_string_append(str, ", ");
359         u3_runtime_info(str);
360     }
361 }
362
363 #ifdef HAVE_LIBPCAP
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.
367  */
368 static void
369 check_and_warn_user_startup(const QString &cf_name)
370 {
371 #ifndef _WIN32
372     Q_UNUSED(cf_name)
373 #endif
374     gchar               *cur_user, *cur_group;
375
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);
386         g_free(cur_user);
387         g_free(cur_group);
388     }
389
390 #ifdef _WIN32
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.");
396     }
397 #endif
398
399 }
400 #endif
401
402 #ifdef _WIN32
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
406 //
407 // - You have Qt version 5.x.y installed in the default location
408 //   (C:\Qt\5.x) on your machine.
409 //
410 // and
411 //
412 // - You install Wireshark that was built on a machine with Qt version
413 //   5.x.z installed in the default location.
414 //
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.
420
421 static inline void
422 reset_library_path(void)
423 {
424     QString app_path = QDir(get_progfile_dir()).path();
425     foreach (QString path, QCoreApplication::libraryPaths()) {
426         QCoreApplication::removeLibraryPath(path);
427     }
428     QCoreApplication::addLibraryPath(app_path);
429 }
430 #endif
431
432 /* And now our feature presentation... [ fade to music ] */
433 int main(int argc, char *argv[])
434 {
435     MainWindow *main_w;
436
437     int                  opt;
438     gboolean             arg_error = FALSE;
439
440 #ifdef _WIN32
441     WSADATA            wsaData;
442 #endif  /* _WIN32 */
443
444     char                *rf_path;
445     int                  rf_open_errno;
446     char                *gdp_path, *dp_path;
447 #ifdef HAVE_LIBPCAP
448     int                  err;
449     gboolean             start_capture = FALSE;
450     gboolean             list_link_layer_types = FALSE;
451     GList               *if_list;
452     gchar               *err_str;
453     int                  status;
454 #else
455     gboolean             capture_option_specified = FALSE;
456 #ifdef _WIN32
457 #ifdef HAVE_AIRPCAP
458     gchar               *err_str;
459 #endif
460 #endif
461 #endif
462     e_prefs             *prefs_p;
463     char                 badopt;
464     guint                go_to_packet = 0;
465
466     QString              dfilter, read_filter;
467
468     cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
469
470 #ifdef _WIN32
471     create_app_running_mutex();
472 #endif
473
474     /*
475      * Get credential information for later use, and drop privileges
476      * before doing anything else.
477      * Let the user know if anything happened.
478      */
479     init_process_policies();
480     relinquish_special_privs_perm();
481
482     /*
483      * Attempt to get the pathname of the executable file.
484      */
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());
488
489     /* Get the compile-time version information string */
490     // XXX qtshark
491     comp_info_str = get_compiled_version_info(get_wireshark_qt_compiled_info,
492                                               get_gui_compiled_info);
493
494     /* Assemble the run-time version information string */
495     // xxx qtshark
496     runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info);
497
498     /*
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.
501      *
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.
505      *
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().
511      *
512      * We thus ignore errors - *and* set "opterr" to 0 to suppress the
513      * error messages.
514      *
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?
517      *
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()
521      * call later.
522      *
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?
526      *
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.
530      */
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:"
533 DIAG_OFF(cast-qual)
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
541         {0, 0, 0, 0 }
542     };
543 DIAG_ON(cast-qual)
544     static const char optstring[] = OPTSTRING;
545
546     opterr = 0;
547
548     while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
549         switch (opt) {
550             case 'C':        /* Configuration Profile */
551                 if (profile_exists (optarg, FALSE)) {
552                     set_profile_name (optarg);
553                 } else {
554                     cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
555                     exit(1);
556                 }
557                 break;
558             case 'D':        /* Print a list of capture devices and exit */
559 #ifdef HAVE_LIBPCAP
560                 if_list = capture_interface_list(&err, &err_str, NULL);
561                 if (if_list == NULL) {
562                     if (err == 0)
563                         cmdarg_err("There are no interfaces on which a capture can be done");
564                     else {
565                         cmdarg_err("%s", err_str);
566                         g_free(err_str);
567                     }
568                     exit(2);
569                 }
570 #ifdef _WIN32
571                 create_console();
572 #endif /* _WIN32 */
573                 capture_opts_print_interfaces(if_list);
574                 free_interface_list(if_list);
575 #ifdef _WIN32
576                 destroy_console();
577 #endif /* _WIN32 */
578                 exit(0);
579 #else /* HAVE_LIBPCAP */
580                 capture_option_specified = TRUE;
581                 arg_error = TRUE;
582 #endif /* HAVE_LIBPCAP */
583                 break;
584             case 'h':        /* Print help and exit */
585                 print_usage(TRUE);
586                 exit(0);
587                 break;
588 #ifdef _WIN32
589             case 'i':
590                 if (strcmp(optarg, "-") == 0)
591                     set_stdin_capture(TRUE);
592                 break;
593 #endif
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);
597                     exit(2);
598                 }
599                 break;
600             case 'v':        /* Show version and exit */
601 #ifdef _WIN32
602                 create_console();
603 #endif
604                 show_version("Wireshark", comp_info_str, runtime_info_str);
605 #ifdef _WIN32
606                 destroy_console();
607 #endif
608                 exit(0);
609                 break;
610             case 'X':
611                 /*
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.
615                  */
616                 ex_opt_add(optarg);
617                 break;
618             case '?':        /* Ignore errors - the "real" scan will catch them. */
619                 break;
620         }
621     }
622
623 #ifdef _WIN32
624     reset_library_path();
625 #endif
626
627     /* Create The Wireshark app */
628     WiresharkApplication ws_app(argc, argv);
629
630     /* initialize the funnel mini-api */
631     // xxx qtshark
632     //initialize_funnel_ops();
633
634     AirPDcapInitContext(&airpdcap_ctx);
635
636 // xxx qtshark
637 #ifdef _WIN32
638     /* Load wpcap if possible. Do this before collecting the run-time version information */
639     load_wpcap();
640
641     /* ... and also load the packet.dll from wpcap */
642     wpcap_packet_load();
643
644 #ifdef HAVE_AIRPCAP
645     /* Load the airpcap.dll.  This must also be done before collecting
646      * run-time version information. */
647     airpcap_dll_ret_val = load_airpcap();
648
649     switch (airpcap_dll_ret_val) {
650     case AIRPCAP_DLL_OK:
651         /* load the airpcap interfaces */
652         airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
653
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.");
657                 g_free(err_str);
658             }
659             airpcap_if_active = NULL;
660
661         } else {
662
663             /* select the first ad default (THIS SHOULD BE CHANGED) */
664             airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
665         }
666         break;
667 #if 0
668     /*
669      * XXX - Maybe we need to warn the user if one of the following happens???
670      */
671     case AIRPCAP_DLL_OLD:
672         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n");
673         break;
674
675     case AIRPCAP_DLL_ERROR:
676         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n");
677         break;
678
679     case AIRPCAP_DLL_NOT_FOUND:
680         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n");
681         break;
682 #endif
683     }
684 #endif /* HAVE_AIRPCAP */
685 #endif /* _WIN32 */
686
687     QString locale;
688     QString cf_name;
689     unsigned int in_file_type = WTAP_TYPE_AUTO;
690
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);
699 #endif
700
701     /* Add it to the information to be reported on a crash. */
702     ws_add_crash_info("Wireshark %s\n"
703            "\n"
704            "%s"
705            "\n"
706            "%s",
707         get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
708
709 #ifdef _WIN32
710     /* Start windows sockets */
711     WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
712 #endif  /* _WIN32 */
713
714     profile_store_persconffiles(TRUE);
715
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));
723     }
724
725     /* Init the "Open file" dialog directory */
726     /* (do this after the path settings are processed) */
727
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));
737     }
738
739     // Initialize our language
740     read_language_prefs();
741     locale = QString(language);
742     wsApp->loadLanguage(locale);
743
744     g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Translator %s", locale.toStdString().c_str());
745
746     // Init the main window (and splash)
747     main_w = new(MainWindow);
748     main_w->show();
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)));
753
754     /* Init the "Open file" dialog directory */
755     /* (do this after the path settings are processed) */
756
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));
766     }
767
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);
771     } else {
772       wsApp->setLastOpenDir(get_persdatafile_dir());
773     }
774
775 #ifdef Q_OS_UNIX
776     // Replicates behavior in gtk_init();
777     signal(SIGPIPE, SIG_IGN);
778 #endif
779
780     set_console_log_handler();
781
782 #ifdef HAVE_LIBPCAP
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);
786 #endif
787
788     init_report_err(failure_alert_box, open_failure_alert_box,
789                     read_failure_alert_box, write_failure_alert_box);
790
791     init_open_routines();
792
793 #ifdef HAVE_PLUGINS
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 */
798
799     /* Scan for plugins.  This does *not* call their registration routines;
800        that's done later. */
801     scan_plugins();
802
803     /* Register all libwiretap plugin modules. */
804     register_all_wiretap_modules();
805
806     /* Register all audio codec plugins. */
807     register_all_codecs();
808 #endif
809
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);
816
817     splash_update(RA_LISTENERS, NULL, NULL);
818
819     /* Register all tap listeners; we do this before we parse the arguments,
820        as the "-z" argument can specify a registered tap. */
821
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 */
825
826     g_log(NULL, G_LOG_LEVEL_DEBUG, "plugin_dir: %s", get_plugin_dir());
827 #ifdef HAVE_PLUGINS
828     register_all_plugin_tap_listeners();
829 #endif
830
831     register_all_tap_listeners();
832     conversation_table_set_gui_info(init_conversation_table);
833     hostlist_table_set_gui_info(init_endpoint_table);
834
835     if (ex_opt_count("read_format") > 0) {
836         in_file_type = open_info_name_to_type(ex_opt_get_next("read_format"));
837     }
838
839     splash_update(RA_PREFERENCES, NULL, NULL);
840
841     prefs_p = ws_app.readConfigurationFiles(&gdp_path, &dp_path);
842
843     /*
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).
853      *
854      * Also reset opterr to 1, so that error messages are printed by
855      * getopt_long().
856      *
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?
868      */
869 #ifdef HAVE_OPTRESET
870     optreset = 1;
871     optind = 1;
872 #else
873     optind = 0;
874 #endif
875     opterr = 1;
876
877     /* Now get our args */
878     while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
879         switch (opt) {
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 */
891 #endif
892 #ifdef HAVE_PCAP_REMOTE
893         case 'A':        /* Authentication */
894 #endif
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 */
902 #ifdef HAVE_LIBPCAP
903             status = capture_opts_add_opt(&global_capture_opts, opt, optarg,
904                                           &start_capture);
905             if(status != 0) {
906                 exit(status);
907             }
908 #else
909             capture_option_specified = TRUE;
910             arg_error = TRUE;
911 #endif
912             break;
913 #ifdef HAVE_KERBEROS
914         case 'K':        /* Kerberos keytab file */
915             read_keytab_file(optarg);
916             break;
917 #endif
918
919         /*** all non capture option specific ***/
920         case 'C':
921             /* Configuration profile settings were already processed just ignore them this time*/
922             break;
923         case 'j':        /* Search backwards for a matching packet from filter in option J */
924             /* Not supported yet */
925             break;
926         case 'g':        /* Go to packet with the given packet number */
927             go_to_packet = get_positive_int(optarg, "go to packet");
928             break;
929         case 'J':        /* Jump to the first packet which matches the filter criteria */
930             /* Not supported yet */
931             break;
932         case 'l':        /* Automatic scrolling in live capture mode */
933 #ifdef HAVE_LIBPCAP
934             /* Not supported yet */
935 #else
936             capture_option_specified = TRUE;
937             arg_error = TRUE;
938 #endif
939             break;
940         case 'L':        /* Print list of link-layer types and exit */
941 #ifdef HAVE_LIBPCAP
942                 list_link_layer_types = TRUE;
943 #else
944                 capture_option_specified = TRUE;
945                 arg_error = TRUE;
946 #endif
947             break;
948         case 'm':        /* Fixed-width font for the display */
949             /* Not supported yet */
950             break;
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;
956             break;
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'",
961                            badopt);
962                 exit(1);
963             }
964             break;
965         case 'o':        /* Override preference from command line */
966             switch (prefs_set_pref(optarg)) {
967                 case PREFS_SET_OK:
968                     break;
969                 case PREFS_SET_SYNTAX_ERR:
970                     cmdarg_err("Invalid -o flag \"%s\"", optarg);
971                     exit(1);
972                     break;
973                 case PREFS_SET_NO_SUCH_PREF:
974                 /* not a preference, might be a recent setting */
975                     switch (recent_set_arg(optarg)) {
976                         case PREFS_SET_OK:
977                             break;
978                         case PREFS_SET_SYNTAX_ERR:
979                             /* shouldn't happen, checked already above */
980                             cmdarg_err("Invalid -o flag \"%s\"", optarg);
981                             exit(1);
982                             break;
983                         case PREFS_SET_NO_SUCH_PREF:
984                         case PREFS_SET_OBSOLETE:
985                             cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
986                                        optarg);
987                             exit(1);
988                             break;
989                         default:
990                             g_assert_not_reached();
991                     }
992                     break;
993                 case PREFS_SET_OBSOLETE:
994                     cmdarg_err("-o flag \"%s\" specifies obsolete preference",
995                                optarg);
996                     exit(1);
997                     break;
998                 default:
999                     g_assert_not_reached();
1000             }
1001             break;
1002         case 'P':
1003             /* Path settings were already processed just ignore them this time*/
1004             break;
1005         case 'r':
1006             cf_name = optarg;
1007             break;
1008         case 'R':        /* Read file filter */
1009             read_filter = QString(optarg);
1010             break;
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);
1032             else {
1033                 cmdarg_err("Invalid time stamp type \"%s\"", optarg);
1034                 cmdarg_err_cont(
1035 "It must be \"a\" for absolute, \"ad\" for absolute with YYYY-MM-DD date,");
1036                 cmdarg_err_cont(
1037 "\"adoy\" for absolute with YYYY/DOY date, \"d\" for delta,");
1038                 cmdarg_err_cont(
1039 "\"dd\" for delta displayed, \"e\" for epoch, \"r\" for relative,");
1040                 cmdarg_err_cont(
1041 "\"u\" for absolute UTC, \"ud\" for absolute UTC with YYYY-MM-DD date,");
1042                 cmdarg_err_cont(
1043 "or \"udoy\" for absolute UTC with YYYY/DOY date.");
1044                 exit(1);
1045             }
1046             break;
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);
1052             else {
1053                 cmdarg_err("Invalid seconds type \"%s\"", optarg);
1054                 cmdarg_err_cont(
1055 "It must be \"s\" for seconds or \"hms\" for hours, minutes and seconds.");
1056                 exit(1);
1057             }
1058             break;
1059         case 'X':
1060             /* ext ops were already processed just ignore them this time*/
1061             break;
1062         case 'Y':
1063             dfilter = QString(optarg);
1064             break;
1065         case 'z':
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();
1074               exit(0);
1075             }
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();
1080                 exit(1);
1081             }
1082             break;
1083         default:
1084         case '?':        /* Bad flag - print usage message */
1085             print_usage(FALSE);
1086             exit(0);
1087             break;
1088         }
1089     }
1090
1091     if (!arg_error) {
1092         argc -= optind;
1093         argv += optind;
1094         if (argc >= 1) {
1095             if (!cf_name.isEmpty()) {
1096                 /*
1097                  * Input file name specified with "-r" *and* specified as a regular
1098                  * command-line argument.
1099                  */
1100                 cmdarg_err("File name specified both with -r and regular argument");
1101                 arg_error = TRUE;
1102             } else {
1103                 /*
1104                  * Input file name not specified with "-r", and a command-line argument
1105                  * was specified; treat it as the input file name.
1106                  *
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.
1112                  */
1113                 cf_name = argv[0];
1114
1115             }
1116             argc--;
1117             argv++;
1118         }
1119
1120         if (argc != 0) {
1121             /*
1122              * Extra command line arguments were specified; complain.
1123              */
1124             cmdarg_err("Invalid argument: %s", argv[0]);
1125             arg_error = TRUE;
1126         }
1127     }
1128     if (arg_error) {
1129 #ifndef HAVE_LIBPCAP
1130         if (capture_option_specified) {
1131             cmdarg_err("This version of Wireshark was not built with support for capturing packets.");
1132         }
1133 #endif
1134         print_usage(FALSE);
1135         exit(1);
1136     }
1137
1138     /* Removed thread code:
1139      * https://code.wireshark.org/review/gitweb?p=wireshark.git;a=commit;h=9e277ae6154fd04bf6a0a34ec5655a73e5a736a3
1140      */
1141
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);
1146
1147 #ifdef HAVE_LIBPCAP
1148     fill_in_local_interfaces(main_window_update);
1149
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.");
1153         exit(1);
1154     }
1155
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.");
1162         exit(1);
1163         }
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.");
1167             exit(1);
1168         }
1169     } else {
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.");
1175             exit(1);
1176         }
1177
1178         /* No - was the ring buffer option specified and, if so, does it make
1179            sense? */
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;
1190             }
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 */
1194             }
1195         }
1196     }
1197
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);
1204         if (status != 0) {
1205             exit(status);
1206         }
1207     }
1208
1209     if (list_link_layer_types) {
1210         /* Get the list of link-layer types for the capture devices. */
1211         if_capabilities_t *caps;
1212         guint i;
1213         interface_t device;
1214         for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
1215
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);
1220 #else
1221                 caps = capture_get_if_capabilities(device.name, FALSE, &err_str,main_window_update);
1222 #endif
1223                 if (caps == NULL) {
1224                     cmdarg_err("%s", err_str);
1225                     g_free(err_str);
1226                     exit(2);
1227                 }
1228             if (caps->data_link_types == NULL) {
1229                 cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
1230                 exit(2);
1231             }
1232 #ifdef _WIN32
1233             create_console();
1234 #endif /* _WIN32 */
1235 #if defined(HAVE_PCAP_CREATE)
1236             capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
1237 #else
1238             capture_opts_print_if_capabilities(caps, device.name, FALSE);
1239 #endif
1240 #ifdef _WIN32
1241             destroy_console();
1242 #endif /* _WIN32 */
1243             free_if_capabilities(caps);
1244             }
1245         }
1246         exit(0);
1247     }
1248
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 */
1252
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. */
1256     prefs_apply_all();
1257     wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged);
1258
1259 #ifdef HAVE_LIBPCAP
1260     if ((global_capture_opts.num_selected == 0) &&
1261             (prefs.capture_device != NULL)) {
1262         guint i;
1263         interface_t device;
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);
1271                 break;
1272             }
1273         }
1274     }
1275 #endif
1276
1277     /* disabled protocols as per configuration file */
1278     if (gdp_path == NULL && dp_path == NULL) {
1279         set_disabled_protos_list();
1280     }
1281
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.
1285
1286     wsApp->setMonospaceFont(prefs.gui_qt_font_name);
1287
1288 ////////
1289
1290     /* Read the dynamic part of the recent file, as we have the gui now ready for
1291        it. */
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));
1297     }
1298
1299     color_filters_enable(recent.packet_list_colorize);
1300
1301     g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings");
1302     color_filters_enable(TRUE);
1303
1304 ////////
1305
1306
1307 ////////
1308     color_filters_init();
1309
1310 ////////
1311
1312 #ifdef HAVE_LIBPCAP
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());
1316     }
1317 #else /* HAVE_LIBPCAP */
1318     ////////
1319 #endif /* HAVE_LIBPCAP */
1320
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);
1325
1326     /* user could specify filename, or display filter, or both */
1327     if (!cf_name.isEmpty()) {
1328
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
1335            filter. */
1336         start_requested_stats();
1337
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
1344                compatibility. */
1345             cf_goto_frame(CaptureFile::globalCapFile(), go_to_packet);
1346         }
1347     }
1348 #ifdef HAVE_LIBPCAP
1349     else {
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);
1356                 g_free(s);
1357             }
1358             /* "-k" was specified; start a capture. */
1359 //            show_main_window(FALSE);
1360             check_and_warn_user_startup(cf_name);
1361
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();
1376             }
1377         }
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());
1381         }
1382     }
1383 #endif /* HAVE_LIBPCAP */
1384
1385     g_main_loop_new(NULL, FALSE);
1386     return wsApp->exec();
1387 }
1388
1389 /*
1390  * Editor modelines
1391  *
1392  * Local Variables:
1393  * c-basic-offset: 4
1394  * tab-width: 8
1395  * indent-tabs-mode: nil
1396  * End:
1397  *
1398  * ex: set shiftwidth=4 tabstop=8 expandtab:
1399  * :indentSize=4:tabSize=8:noTabs=true:
1400  */