HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / ui / qt / main.cpp
blobc4f2eb6e8ec0a238f98d4f1fb5e93650d30c9cc0
1 /* main.cpp
3 * $Id$
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "wireshark_application.h"
25 #include "main_window.h"
27 #include "config.h"
28 #include <ctype.h>
29 #include "globals.h"
31 #include <glib.h>
33 #ifndef HAVE_GETOPT
34 # include "wsutil/wsgetopt.h"
35 #else
36 # include <getopt.h>
37 #endif
39 #include <wsutil/crash_info.h>
40 #include <wsutil/u3.h>
41 #include <wsutil/file_util.h>
43 #include <wiretap/merge.h>
45 #include <epan/epan.h>
46 #include <epan/filesystem.h>
47 #include <wsutil/privileges.h>
48 #include <epan/epan_dissect.h>
49 #include <epan/timestamp.h>
50 #include <epan/packet.h>
51 #include <epan/plugins.h>
52 #include <epan/dfilter/dfilter.h>
53 #include <epan/strutil.h>
54 #include <epan/addr_resolv.h>
55 #include <epan/emem.h>
56 #include <epan/ex-opt.h>
57 #include <epan/funnel.h>
58 #include <epan/expert.h>
59 #include <epan/frequency-utils.h>
60 #include <epan/prefs.h>
61 #include <epan/prefs-int.h>
62 #include <epan/tap.h>
63 #include <epan/stat_cmd_args.h>
64 #include <epan/uat.h>
65 #include <epan/column.h>
66 #include <epan/disabled_protos.h>
67 #include <epan/print.h>
69 /* general (not Qt specific) */
70 #include "file.h"
71 #include "summary.h"
72 #include "color.h"
73 #include "color_filters.h"
74 #include "register.h"
75 #include "ringbuffer.h"
76 #include "ui/util.h"
77 #include "clopts_common.h"
78 #include "cmdarg_err.h"
79 #include "version_info.h"
80 #include "log.h"
82 #include "ui/alert_box.h"
83 #include "ui/capture_globals.h"
84 #include "ui/iface_lists.h"
85 #include "ui/main_statusbar.h"
86 #include "ui/recent.h"
87 #include "ui/simple_dialog.h"
88 #include "ui/ui_util.h"
90 #ifdef HAVE_LIBPCAP
91 # include "capture_ui_utils.h"
92 # include "capture-pcap-util.h"
93 # include "capture_ifinfo.h"
94 # include "capture.h"
95 # include "capture_sync.h"
96 #endif
98 #ifdef _WIN32
99 # include "capture-wpcap.h"
100 # include "capture_wpcap_packet.h"
101 # include <tchar.h> /* Needed for Unicode */
102 # include <wsutil/unicode-utils.h>
103 # include <commctrl.h>
104 # include <shellapi.h>
105 # include <conio.h>
106 # include "ui/win32/console_win32.h"
107 #endif /* _WIN32 */
109 #ifdef HAVE_AIRPCAP
110 # include <airpcap.h>
111 # include "airpcap_loader.h"
112 //# include "airpcap_dlg.h"
113 //# include "airpcap_gui_utils.h"
114 #endif
116 #include <epan/crypt/airpdcap_ws.h>
118 #include <QDebug>
119 #include <QDateTime>
120 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
121 #include <QTextCodec>
122 #endif
123 #include <qtranslator.h>
124 #include <qlocale.h>
125 #include <qlibraryinfo.h>
127 #ifdef HAVE_LIBPCAP
128 capture_options global_capture_opts;
129 capture_session global_capture_session;
130 #endif
132 capture_file cfile;
134 #ifdef HAVE_AIRPCAP
135 int airpcap_dll_ret_val = -1;
136 #endif
138 GString *comp_info_str, *runtime_info_str;
140 //static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */
142 //static guint tap_update_timer_id;
144 static void console_log_handler(const char *log_domain,
145 GLogLevelFlags log_level, const char *message, gpointer user_data);
148 #ifdef HAVE_LIBPCAP
149 extern capture_options global_capture_opts;
151 static void
152 main_capture_callback(gint event, capture_session *cap_session, gpointer user_data )
154 Q_UNUSED(user_data);
155 wsApp->captureCallback(event, cap_session);
157 #endif // HAVE_LIBPCAP
159 static void
160 main_cf_callback(gint event, gpointer data, gpointer user_data )
162 Q_UNUSED(user_data);
163 wsApp->captureFileCallback(event, data);
166 /* update the main window */
167 void main_window_update(void)
169 WiresharkApplication::processEvents();
172 #ifdef HAVE_LIBPCAP
174 /* quit a nested main window */
175 void main_window_nested_quit(void)
177 // if (gtk_main_level() > 0)
178 wsApp->quit();
181 /* quit the main window */
182 void main_window_quit(void)
184 wsApp->quit();
187 #endif /* HAVE_LIBPCAP */
190 // xxx copied from ../gtk/main.c
191 static void
192 print_usage(gboolean print_ver) {
193 FILE *output;
195 #ifdef _WIN32
196 create_console();
197 #endif
199 if (print_ver) {
200 output = stdout;
201 fprintf(output, "Wireshark " VERSION "%s\n"
202 "Interactively dump and analyze network traffic.\n"
203 "See http://www.wireshark.org for more information.\n"
204 "\n"
205 "%s",
206 wireshark_svnversion, get_copyright_info());
207 } else {
208 output = stderr;
210 fprintf(output, "\n");
211 fprintf(output, "Usage: wireshark [options] ... [ <infile> ]\n");
212 fprintf(output, "\n");
214 #ifdef HAVE_LIBPCAP
215 fprintf(output, "Capture interface:\n");
216 fprintf(output, " -i <interface> name or idx of interface (def: first non-loopback)\n");
217 fprintf(output, " -f <capture filter> packet filter in libpcap filter syntax\n");
218 fprintf(output, " -s <snaplen> packet snapshot length (def: 65535)\n");
219 fprintf(output, " -p don't capture in promiscuous mode\n");
220 fprintf(output, " -k start capturing immediately (def: do nothing)\n");
221 fprintf(output, " -Q quit Wireshark after capturing\n");
222 fprintf(output, " -S update packet display when new packets are captured\n");
223 fprintf(output, " -l turn on automatic scrolling while -S is in use\n");
224 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
225 fprintf(output, " -B <buffer size> size of kernel buffer (def: %dMB)\n", DEFAULT_CAPTURE_BUFFER_SIZE);
226 #endif
227 fprintf(output, " -y <link type> link layer type (def: first appropriate)\n");
228 fprintf(output, " -D print list of interfaces and exit\n");
229 fprintf(output, " -L print list of link-layer types of iface and exit\n");
230 fprintf(output, "\n");
231 fprintf(output, "Capture stop conditions:\n");
232 fprintf(output, " -c <packet count> stop after n packets (def: infinite)\n");
233 fprintf(output, " -a <autostop cond.> ... duration:NUM - stop after NUM seconds\n");
234 fprintf(output, " filesize:NUM - stop this file after NUM KB\n");
235 fprintf(output, " files:NUM - stop after NUM files\n");
236 /*fprintf(output, "\n");*/
237 fprintf(output, "Capture output:\n");
238 fprintf(output, " -b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs\n");
239 fprintf(output, " filesize:NUM - switch to next file after NUM KB\n");
240 fprintf(output, " files:NUM - ringbuffer: replace after NUM files\n");
241 #endif /* HAVE_LIBPCAP */
243 /*fprintf(output, "\n");*/
244 fprintf(output, "Input file:\n");
245 fprintf(output, " -r <infile> set the filename to read from (no pipes or stdin!)\n");
247 fprintf(output, "\n");
248 fprintf(output, "Processing:\n");
249 fprintf(output, " -R <read filter> packet filter in Wireshark display filter syntax\n");
250 fprintf(output, " -n disable all name resolutions (def: all enabled)\n");
251 fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mntC\"\n");
253 fprintf(output, "\n");
254 fprintf(output, "User interface:\n");
255 fprintf(output, " -C <config profile> start with specified configuration profile\n");
256 fprintf(output, " -g <packet number> go to specified packet number after \"-r\"\n");
257 fprintf(output, " -J <jump filter> jump to the first packet matching the (display)\n");
258 fprintf(output, " filter\n");
259 fprintf(output, " -j search backwards for a matching packet after \"-J\"\n");
260 fprintf(output, " -m <font> set the font name used for most text\n");
261 fprintf(output, " -t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first)\n");
262 fprintf(output, " -u s|hms output format of seconds (def: s: seconds)\n");
263 fprintf(output, " -X <key>:<value> eXtension options, see man page for details\n");
264 fprintf(output, " -z <statistics> show various statistics, see man page for details\n");
266 fprintf(output, "\n");
267 fprintf(output, "Output:\n");
268 fprintf(output, " -w <outfile|-> set the output filename (or '-' for stdout)\n");
270 fprintf(output, "\n");
271 fprintf(output, "Miscellaneous:\n");
272 fprintf(output, " -h display this help and exit\n");
273 fprintf(output, " -v display version info and exit\n");
274 fprintf(output, " -P <key>:<path> persconf:path - personal configuration files\n");
275 fprintf(output, " persdata:path - personal data files\n");
276 fprintf(output, " -o <name>:<value> ... override preference or recent setting\n");
277 fprintf(output, " -K <keytab> keytab file to use for kerberos decryption\n");
278 #ifndef _WIN32
279 fprintf(output, " --display=DISPLAY X display to use\n");
280 #endif
282 #ifdef _WIN32
283 destroy_console();
284 #endif
287 // xxx copied from ../gtk/main.c
288 static void
289 show_version(void)
291 printf(PACKAGE " " VERSION "%s\n"
292 "\n"
293 "%s"
294 "\n"
295 "%s"
296 "\n"
297 "%s",
298 wireshark_svnversion, get_copyright_info(), comp_info_str->str,
299 runtime_info_str->str);
303 * Report an error in command-line arguments.
304 * Creates a console on Windows.
306 // xxx copied from ../gtk/main.c
307 void
308 cmdarg_err(const char *fmt, ...)
310 va_list ap;
312 #ifdef _WIN32
313 create_console();
314 #endif
315 fprintf(stderr, "wireshark: ");
316 va_start(ap, fmt);
317 vfprintf(stderr, fmt, ap);
318 va_end(ap);
319 fprintf(stderr, "\n");
323 * Report additional information for an error in command-line arguments.
324 * Creates a console on Windows.
325 * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
326 * terminal isn't the standard error?
328 // xxx copied from ../gtk/main.c
329 void
330 cmdarg_err_cont(const char *fmt, ...)
332 va_list ap;
334 #ifdef _WIN32
335 create_console();
336 #endif
337 va_start(ap, fmt);
338 vfprintf(stderr, fmt, ap);
339 fprintf(stderr, "\n");
340 va_end(ap);
343 static void
344 console_log_handler(const char *log_domain, GLogLevelFlags log_level,
345 const char *message, gpointer user_data)
347 Q_UNUSED(user_data);
348 QString level;
349 QString hmsz = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
351 // xxx qtshark: We want all of the messages for now.
352 // /* ignore log message, if log_level isn't interesting based
353 // upon the console log preferences.
354 // If the preferences haven't been loaded loaded yet, display the
355 // message anyway.
357 // The default console_log_level preference value is such that only
358 // ERROR, CRITICAL and WARNING level messages are processed;
359 // MESSAGE, INFO and DEBUG level messages are ignored. */
360 // if((log_level & G_LOG_LEVEL_MASK & prefs.console_log_level) == 0 &&
361 // prefs.console_log_level != 0) {
362 // return;
364 switch(log_level & G_LOG_LEVEL_MASK) {
365 case G_LOG_LEVEL_ERROR:
366 level = "Err ";
367 break;
368 case G_LOG_LEVEL_CRITICAL:
369 level = "Crit";
370 break;
371 case G_LOG_LEVEL_WARNING:
372 level = "Warn";
373 break;
374 case G_LOG_LEVEL_MESSAGE:
375 level = "Msg ";
376 break;
377 case G_LOG_LEVEL_INFO:
378 level = "Info";
379 break;
380 case G_LOG_LEVEL_DEBUG:
381 level = "Dbg ";
382 break;
383 default:
384 qDebug("%s unknown log_level %u", hmsz.toUtf8().constData(), log_level);
385 g_assert_not_reached();
388 qDebug("%s %s %s %s", hmsz.toUtf8().constData(), log_domain, level.toUtf8().constData(), message);
391 // xxx based from ../gtk/main.c:get_gtk_compiled_info
392 static void
393 get_qt_compiled_info(GString *str)
395 g_string_append(str, "with ");
396 g_string_append_printf(str,
397 #ifdef QT_VERSION
398 "Qt %s ", QT_VERSION_STR);
399 #else
400 "Qt (version unknown) ");
401 #endif
404 // xxx copied from ../gtk/main.c
405 static void
406 get_gui_compiled_info(GString *str)
408 epan_get_compiled_version_info(str);
410 g_string_append(str, ", ");
411 g_string_append(str, "without PortAudio");
413 g_string_append(str, ", ");
414 #ifdef HAVE_AIRPCAP
415 get_compiled_airpcap_version(str);
416 #else
417 g_string_append(str, "without AirPcap");
418 #endif
421 // xxx copied from ../gtk/main.c
422 static void
423 get_gui_runtime_info(GString *str)
425 epan_get_runtime_version_info(str);
427 #ifdef HAVE_AIRPCAP
428 g_string_append(str, ", ");
429 get_runtime_airpcap_version(str);
430 #endif
433 if(u3_active()) {
434 g_string_append(str, ", ");
435 u3_runtime_info(str);
440 /* And now our feature presentation... [ fade to music ] */
441 int main(int argc, char *argv[])
443 WiresharkApplication ws_app(argc, argv);
444 MainWindow *main_w;
446 int opt;
447 gboolean arg_error = FALSE;
449 #ifdef _WIN32
450 WSADATA wsaData;
451 #endif /* _WIN32 */
453 char *rf_path;
454 int rf_open_errno;
455 char *gdp_path, *dp_path;
456 #ifdef HAVE_LIBPCAP
457 int err;
458 gboolean start_capture = FALSE;
459 // gboolean list_link_layer_types = FALSE;
460 GList *if_list;
461 gchar *err_str;
462 #else
463 gboolean capture_option_specified = FALSE;
464 #ifdef _WIN32
465 #ifdef HAVE_AIRPCAP
466 gchar *err_str;
467 #endif
468 #endif
469 #endif
470 e_prefs *prefs_p;
471 GLogLevelFlags log_flags;
472 int status;
474 #ifdef _WIN32
475 create_app_running_mutex();
476 #endif
478 QString locale;
479 QString *cf_name = NULL;
481 // In Qt 5, C strings are treated always as UTF-8 when converted to
482 // QStrings; in Qt 4, the codec must be set to make that happen
483 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
484 // Hopefully we won't have to use QString::fromUtf8() in as many places.
485 QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8");
486 QTextCodec::setCodecForCStrings(utf8codec);
487 // XXX - QObject doesn't *have* a tr method in 5.0, as far as I can see...
488 QTextCodec::setCodecForTr(utf8codec);
489 #endif
491 // Init the main window (and splash)
492 main_w = new(MainWindow);
493 main_w->show();
494 // We may not need a queued connection here but it would seem to make sense
495 // to force the issue.
496 main_w->connect(&ws_app, SIGNAL(openCaptureFile(QString&)),
497 main_w, SLOT(openCaptureFile(QString&)));
499 // XXX Should the remaining code be in WiresharkApplcation::WiresharkApplication?
500 #ifdef HAVE_LIBPCAP
501 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
502 #define OPTSTRING_B "B:"
503 #else
504 #define OPTSTRING_B ""
505 #endif /* _WIN32 or HAVE_PCAP_CREATE */
506 #else /* HAVE_LIBPCAP */
507 #define OPTSTRING_B ""
508 #endif /* HAVE_LIBPCAP */
510 #ifdef HAVE_PCAP_CREATE
511 #define OPTSTRING_I "I"
512 #else
513 #define OPTSTRING_I ""
514 #endif
516 #define OPTSTRING "a:b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:"
518 struct option long_options[] = {
519 {(char *)"read-file", required_argument, NULL, (int)'r' },
520 {0, 0, 0, 0 }
523 static const char optstring[] = OPTSTRING;
525 /* Assemble the compile-time version information string */
526 comp_info_str = g_string_new("Compiled ");
528 // xxx qtshark
529 get_compiled_version_info(comp_info_str, get_qt_compiled_info, get_gui_compiled_info);
531 /* Assemble the run-time version information string */
532 runtime_info_str = g_string_new("Running ");
533 // xxx qtshark
534 get_runtime_version_info(runtime_info_str, get_gui_runtime_info);
536 ws_add_crash_info(PACKAGE " " VERSION "%s\n"
537 "\n"
538 "%s"
539 "\n"
540 "%s",
541 wireshark_svnversion, comp_info_str->str, runtime_info_str->str);
544 * Get credential information for later use, and drop privileges
545 * before doing anything else.
546 * Let the user know if anything happened.
548 init_process_policies();
549 relinquish_special_privs_perm();
552 * Attempt to get the pathname of the executable file.
554 /* init_progfile_dir_error = */ init_progfile_dir(QCoreApplication::applicationFilePath().toUtf8().constData(), NULL);
555 g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir());
557 /* initialize the funnel mini-api */
558 // xxx qtshark
559 //initialize_funnel_ops();
561 AirPDcapInitContext(&airpdcap_ctx);
563 // xxx qtshark
564 #ifdef _WIN32
565 /* Load wpcap if possible. Do this before collecting the run-time version information */
566 load_wpcap();
568 /* ... and also load the packet.dll from wpcap */
569 wpcap_packet_load();
571 #ifdef HAVE_AIRPCAP
572 /* Load the airpcap.dll. This must also be done before collecting
573 * run-time version information. */
574 airpcap_dll_ret_val = load_airpcap();
576 switch (airpcap_dll_ret_val) {
577 case AIRPCAP_DLL_OK:
578 /* load the airpcap interfaces */
579 airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
581 if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){
582 if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) {
583 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters!");
584 g_free(err_str);
586 airpcap_if_active = NULL;
588 } else {
590 /* select the first ad default (THIS SHOULD BE CHANGED) */
591 airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
593 break;
594 #if 0
596 * XXX - Maybe we need to warn the user if one of the following happens???
598 case AIRPCAP_DLL_OLD:
599 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n");
600 break;
602 case AIRPCAP_DLL_ERROR:
603 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n");
604 break;
606 case AIRPCAP_DLL_NOT_FOUND:
607 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n");
608 break;
609 #endif
611 #endif /* HAVE_AIRPCAP */
613 /* Start windows sockets */
614 WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
615 #endif /* _WIN32 */
617 profile_store_persconffiles (TRUE);
619 /* Read the profile independent recent file. We have to do this here so we can */
620 /* set the profile before it can be set from the command line parameterts */
621 recent_read_static(&rf_path, &rf_open_errno);
622 if (rf_path != NULL && rf_open_errno != 0) {
623 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
624 "Could not open common recent file\n\"%s\": %s.",
625 rf_path, strerror(rf_open_errno));
627 wsApp->emitAppSignal(WiresharkApplication::StaticRecentFilesRead);
629 while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
630 switch (opt) {
631 case 'C': /* Configuration Profile */
632 if (profile_exists (optarg, FALSE)) {
633 set_profile_name (optarg);
634 } else {
635 cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
636 exit(1);
638 break;
639 case 'D': /* Print a list of capture devices and exit */
640 #ifdef HAVE_LIBPCAP
641 if_list = capture_interface_list(&err, &err_str, main_window_update);
642 if (if_list == NULL) {
643 switch (err) {
644 case CANT_GET_INTERFACE_LIST:
645 cmdarg_err("%s", err_str);
646 g_free(err_str);
647 break;
649 case NO_INTERFACES_FOUND:
650 cmdarg_err("There are no interfaces on which a capture can be done");
651 break;
653 exit(2);
655 #ifdef _WIN32
656 create_console();
657 #endif /* _WIN32 */
658 capture_opts_print_interfaces(if_list);
659 free_interface_list(if_list);
660 #ifdef _WIN32
661 destroy_console();
662 #endif /* _WIN32 */
663 exit(0);
664 #else /* HAVE_LIBPCAP */
665 capture_option_specified = TRUE;
666 arg_error = TRUE;
667 #endif /* HAVE_LIBPCAP */
668 break;
669 case 'h': /* Print help and exit */
670 print_usage(TRUE);
671 exit(0);
672 break;
673 #ifdef _WIN32
674 case 'i':
675 if (strcmp(optarg, "-") == 0)
676 set_stdin_capture(TRUE);
677 break;
678 #endif
679 case 'P': /* Path settings - change these before the Preferences and alike are processed */
680 status = filesystem_opt(opt, optarg);
681 if(status != 0) {
682 cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg);
683 exit(status);
685 break;
686 case 'v': /* Show version and exit */
687 #ifdef _WIN32
688 create_console();
689 #endif
690 show_version();
691 #ifdef _WIN32
692 destroy_console();
693 #endif
694 exit(0);
695 break;
696 case 'r':
697 cf_name = new QString(optarg);
698 break;
699 case 'X':
701 * Extension command line options have to be processed before
702 * we call epan_init() as they are supposed to be used by dissectors
703 * or taps very early in the registration process.
705 ex_opt_add(optarg);
706 break;
707 case '?':
708 print_usage(TRUE);
709 exit(0);
710 break;
714 if (!arg_error) {
715 argc -= optind;
716 argv += optind;
717 if (argc >= 1) {
718 if (cf_name != NULL) {
720 * Input file name specified with "-r" *and* specified as a regular
721 * command-line argument.
723 cmdarg_err("File name specified both with -r and regular argument");
724 arg_error = TRUE;
725 } else {
727 * Input file name not specified with "-r", and a command-line argument
728 * was specified; treat it as the input file name.
730 * Yes, this is different from tshark, where non-flag command-line
731 * arguments are a filter, but this works better on GUI desktops
732 * where a command can be specified to be run to open a particular
733 * file - yes, you could have "-r" as the last part of the command,
734 * but that's a bit ugly.
736 cf_name = new QString(g_strdup(argv[0]));
739 argc--;
740 argv++;
743 if (argc != 0) {
745 * Extra command line arguments were specified; complain.
747 cmdarg_err("Invalid argument: %s", argv[0]);
748 arg_error = TRUE;
751 if (arg_error) {
752 #ifndef HAVE_LIBPCAP
753 if (capture_option_specified) {
754 cmdarg_err("This version of Wireshark was not built with support for capturing packets.");
756 #endif
757 print_usage(FALSE);
758 exit(1);
761 /* Init the "Open file" dialog directory */
762 /* (do this after the path settings are processed) */
764 /* Read the profile dependent (static part) of the recent file. */
765 /* Only the static part of it will be read, as we don't have the gui now to fill the */
766 /* recent lists which is done in the dynamic part. */
767 /* We have to do this already here, so command line parameters can overwrite these values. */
768 recent_read_profile_static(&rf_path, &rf_open_errno);
769 if (rf_path != NULL && rf_open_errno != 0) {
770 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
771 "Could not open recent file\n\"%s\": %s.",
772 rf_path, g_strerror(rf_open_errno));
775 if (recent.gui_fileopen_remembered_dir &&
776 test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
777 wsApp->setLastOpenDir(recent.gui_fileopen_remembered_dir);
778 } else {
779 wsApp->setLastOpenDir(get_persdatafile_dir());
782 #ifdef HAVE_LIBPCAP
783 capture_callback_add(main_capture_callback, NULL);
784 #endif
785 cf_callback_add(main_cf_callback, NULL);
787 /* Arrange that if we have no console window, and a GLib message logging
788 routine is called to log a message, we pop up a console window.
790 We do that by inserting our own handler for all messages logged
791 to the default domain; that handler pops up a console if necessary,
792 and then calls the default handler. */
794 /* We might want to have component specific log levels later ... */
796 log_flags = (GLogLevelFlags) (
797 G_LOG_LEVEL_ERROR|
798 G_LOG_LEVEL_CRITICAL|
799 G_LOG_LEVEL_WARNING|
800 G_LOG_LEVEL_MESSAGE|
801 G_LOG_LEVEL_INFO|
802 G_LOG_LEVEL_DEBUG|
803 G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION );
805 g_log_set_handler(NULL,
806 log_flags,
807 console_log_handler, NULL /* user_data */);
808 g_log_set_handler(LOG_DOMAIN_MAIN,
809 log_flags,
810 console_log_handler, NULL /* user_data */);
812 #ifdef HAVE_LIBPCAP
813 g_log_set_handler(LOG_DOMAIN_CAPTURE,
814 log_flags,
815 console_log_handler, NULL /* user_data */);
816 g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
817 log_flags,
818 console_log_handler, NULL /* user_data */);
820 /* Set the initial values in the capture options. This might be overwritten
821 by preference settings and then again by the command line parameters. */
822 capture_opts_init(&global_capture_opts);
824 capture_session_init(&global_capture_session, (void *)&cfile);
825 #endif
827 /* Register all dissectors; we must do this before checking for the
828 "-G" flag, as the "-G" flag dumps information registered by the
829 dissectors, and we must do it before we read the preferences, in
830 case any dissectors register preferences. */
831 epan_init(register_all_protocols,register_all_protocol_handoffs,
832 splash_update, NULL,
833 failure_alert_box,open_failure_alert_box,read_failure_alert_box,
834 write_failure_alert_box
837 splash_update(RA_PREFERENCES, NULL, NULL);
838 prefs_p = ws_app.readConfigurationFiles (&gdp_path, &dp_path);
840 //initialize language !
842 /*TODO: Enhance... may be get the locale from the enum gui_qt_language */
843 switch(prefs_p->gui_qt_language){
844 case 1: /* English */
845 locale = "en";
846 break;
847 case 2: /* French */
848 locale = "fr";
849 break;
850 case 3: /* German */
851 locale = "de";
852 break;
853 case 4: /* Chinese */
854 locale = "zh_CN";
855 break;
856 default: /* Auto-Detect */
857 locale = QLocale::system().name();
858 break;
860 g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Translator %s", locale.toStdString().c_str());
861 QTranslator translator;
862 translator.load(QString(":/i18n/qtshark_") + locale);
863 wsApp->installTranslator(&translator);
865 QTranslator qtTranslator;
866 qtTranslator.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
867 wsApp->installTranslator(&qtTranslator);
869 splash_update(RA_LISTENERS, NULL, NULL);
871 /* Register all tap listeners; we do this before we parse the arguments,
872 as the "-z" argument can specify a registered tap. */
874 /* we register the plugin taps before the other taps because
875 stats_tree taps plugins will be registered as tap listeners
876 by stats_tree_stat.c and need to registered before that */
878 g_log(NULL, G_LOG_LEVEL_DEBUG, "plugin_dir: %s", get_plugin_dir());
879 #ifdef HAVE_PLUGINS
880 register_all_plugin_tap_listeners();
881 #endif
883 // register_all_tap_listeners();
885 /* Removed thread code:
886 * http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027
889 g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: timestamp types should be set elsewhere");
890 timestamp_set_type(TS_RELATIVE);
891 timestamp_set_precision(TS_PREC_AUTO_USEC);
892 timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
894 #ifdef HAVE_LIBPCAP
895 fill_in_local_interfaces(main_window_update);
897 capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
898 capture_opts_trim_ring_num_files(&global_capture_opts);
899 #endif /* HAVE_LIBPCAP */
901 /* Notify all registered modules that have had any of their preferences
902 changed either from one of the preferences file or from the command
903 line that their preferences have changed. */
904 prefs_apply_all();
905 wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged);
907 #ifdef HAVE_LIBPCAP
908 if ((global_capture_opts.num_selected == 0) &&
909 (prefs.capture_device != NULL)) {
910 guint i;
911 interface_t device;
912 for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
913 device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
914 if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) {
915 device.selected = TRUE;
916 global_capture_opts.num_selected++;
917 global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
918 g_array_insert_val(global_capture_opts.all_ifaces, i, device);
919 break;
923 #endif
925 /* disabled protocols as per configuration file */
926 if (gdp_path == NULL && dp_path == NULL) {
927 set_disabled_protos_list();
930 build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE);
932 wsApp->setMonospaceFont(prefs.gui_qt_font_name);
934 ////////
936 /* Read the dynamic part of the recent file, as we have the gui now ready for
937 it. */
938 recent_read_dynamic(&rf_path, &rf_open_errno);
939 if (rf_path != NULL && rf_open_errno != 0) {
940 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
941 "Could not open recent file\n\"%s\": %s.",
942 rf_path, g_strerror(rf_open_errno));
945 color_filters_enable(recent.packet_list_colorize);
947 g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings");
948 color_filters_enable(TRUE);
950 ////////
953 ////////
954 color_filters_init();
956 ////////
958 #ifdef HAVE_LIBPCAP
959 /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
960 if (!start_capture && !global_capture_opts.default_options.cfilter) {
961 global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
963 #else /* HAVE_LIBPCAP */
964 ////////
965 #endif /* HAVE_LIBPCAP */
967 // w->setEnabled(true);
968 wsApp->allSystemsGo();
969 g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "Wireshark is up and ready to go");
971 if (cf_name != NULL) {
972 main_w->openCaptureFile(*cf_name);
975 g_main_loop_new(NULL, FALSE);
976 return wsApp->exec();
980 * Editor modelines
982 * Local Variables:
983 * c-basic-offset: 4
984 * tab-width: 8
985 * indent-tabs-mode: nil
986 * End:
988 * ex: set shiftwidth=4 tabstop=8 expandtab:
989 * :indentSize=4:tabSize=8:noTabs=true: