nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 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 | #include <locale.h> |
||
31 | |||
32 | #ifdef HAVE_GETOPT_H |
||
33 | #include <getopt.h> |
||
34 | #endif |
||
35 | |||
36 | #ifndef HAVE_GETOPT_LONG |
||
37 | #include "wsutil/wsgetopt.h" |
||
38 | #endif |
||
39 | |||
40 | #include <wsutil/clopts_common.h> |
||
41 | #include <wsutil/cmdarg_err.h> |
||
42 | #include <wsutil/crash_info.h> |
||
43 | #include <wsutil/filesystem.h> |
||
44 | #include <wsutil/privileges.h> |
||
45 | #ifdef HAVE_PLUGINS |
||
46 | #include <wsutil/plugins.h> |
||
47 | #endif |
||
48 | #include <wsutil/report_err.h> |
||
49 | #include <wsutil/unicode-utils.h> |
||
50 | #include <ws_version_info.h> |
||
51 | |||
52 | #include <epan/addr_resolv.h> |
||
53 | #include <epan/ex-opt.h> |
||
54 | #include <epan/tap.h> |
||
55 | #include <epan/stat_tap_ui.h> |
||
56 | #include <epan/column.h> |
||
57 | #include <epan/disabled_protos.h> |
||
58 | #include <epan/prefs.h> |
||
59 | |||
60 | #ifdef HAVE_KERBEROS |
||
61 | #include <epan/packet.h> |
||
62 | #include <epan/asn1.h> |
||
63 | #include <epan/dissectors/packet-kerberos.h> |
||
64 | #endif |
||
65 | |||
66 | #ifdef HAVE_PLUGINS |
||
67 | #include <codecs/codecs.h> |
||
68 | #endif |
||
69 | |||
70 | #ifdef HAVE_EXTCAP |
||
71 | #include <extcap.h> |
||
72 | #endif |
||
73 | |||
74 | /* general (not Qt specific) */ |
||
75 | #include "file.h" |
||
76 | #include "epan/color_filters.h" |
||
77 | #include "log.h" |
||
78 | |||
79 | #include "epan/rtd_table.h" |
||
80 | #include "epan/srt_table.h" |
||
81 | |||
82 | #include "ui/alert_box.h" |
||
83 | #include "ui/console.h" |
||
84 | #include "ui/iface_lists.h" |
||
85 | #include "ui/language.h" |
||
86 | #include "ui/persfilepath_opt.h" |
||
87 | #include "ui/recent.h" |
||
88 | #include "ui/simple_dialog.h" |
||
89 | #include "ui/util.h" |
||
90 | #include "ui/commandline.h" |
||
91 | |||
92 | #include "ui/qt/conversation_dialog.h" |
||
93 | #include "ui/qt/color_utils.h" |
||
94 | #include "ui/qt/coloring_rules_dialog.h" |
||
95 | #include "ui/qt/endpoint_dialog.h" |
||
96 | #include "ui/qt/main_window.h" |
||
97 | #include "ui/qt/response_time_delay_dialog.h" |
||
98 | #include "ui/qt/service_response_time_dialog.h" |
||
99 | #include "ui/qt/simple_dialog.h" |
||
100 | #include "ui/qt/simple_statistics_dialog.h" |
||
101 | #include "ui/qt/splash_overlay.h" |
||
102 | #include "ui/qt/wireshark_application.h" |
||
103 | |||
104 | #include "caputils/capture-pcap-util.h" |
||
105 | |||
106 | #ifdef _WIN32 |
||
107 | # include "caputils/capture-wpcap.h" |
||
108 | # include "caputils/capture_wpcap_packet.h" |
||
109 | # include <tchar.h> /* Needed for Unicode */ |
||
110 | # include <wsutil/file_util.h> |
||
111 | # include <wsutil/os_version_info.h> |
||
112 | #endif /* _WIN32 */ |
||
113 | |||
114 | #ifdef HAVE_AIRPCAP |
||
115 | # include <caputils/airpcap.h> |
||
116 | # include <caputils/airpcap_loader.h> |
||
117 | //# include "airpcap_dlg.h" |
||
118 | //# include "airpcap_gui_utils.h" |
||
119 | #endif |
||
120 | |||
121 | #include "epan/crypt/airpdcap_ws.h" |
||
122 | |||
123 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) |
||
124 | #include <QTextCodec> |
||
125 | #endif |
||
126 | |||
127 | /* update the main window */ |
||
128 | void main_window_update(void) |
||
129 | { |
||
130 | WiresharkApplication::processEvents(); |
||
131 | } |
||
132 | |||
133 | #ifdef HAVE_LIBPCAP |
||
134 | |||
135 | /* quit a nested main window */ |
||
136 | void main_window_nested_quit(void) |
||
137 | { |
||
138 | // if (gtk_main_level() > 0) |
||
139 | wsApp->quit(); |
||
140 | } |
||
141 | |||
142 | /* quit the main window */ |
||
143 | void main_window_quit(void) |
||
144 | { |
||
145 | wsApp->quit(); |
||
146 | } |
||
147 | |||
148 | #endif /* HAVE_LIBPCAP */ |
||
149 | |||
150 | /* |
||
151 | * Report an error in command-line arguments. |
||
152 | * Creates a console on Windows. |
||
153 | */ |
||
154 | // xxx copied from ../gtk/main.c |
||
155 | static void |
||
156 | wireshark_cmdarg_err(const char *fmt, va_list ap) |
||
157 | { |
||
158 | #ifdef _WIN32 |
||
159 | create_console(); |
||
160 | #endif |
||
161 | fprintf(stderr, "wireshark: "); |
||
162 | vfprintf(stderr, fmt, ap); |
||
163 | fprintf(stderr, "\n"); |
||
164 | } |
||
165 | |||
166 | /* |
||
167 | * Report additional information for an error in command-line arguments. |
||
168 | * Creates a console on Windows. |
||
169 | * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling |
||
170 | * terminal isn't the standard error? |
||
171 | */ |
||
172 | // xxx copied from ../gtk/main.c |
||
173 | static void |
||
174 | wireshark_cmdarg_err_cont(const char *fmt, va_list ap) |
||
175 | { |
||
176 | #ifdef _WIN32 |
||
177 | create_console(); |
||
178 | #endif |
||
179 | vfprintf(stderr, fmt, ap); |
||
180 | fprintf(stderr, "\n"); |
||
181 | } |
||
182 | |||
183 | // xxx based from ../gtk/main.c:get_gtk_compiled_info |
||
184 | void |
||
185 | get_wireshark_qt_compiled_info(GString *str) |
||
186 | { |
||
187 | g_string_append(str, "with "); |
||
188 | g_string_append_printf(str, |
||
189 | #ifdef QT_VERSION |
||
190 | "Qt %s", QT_VERSION_STR); |
||
191 | #else |
||
192 | "Qt (version unknown)"); |
||
193 | #endif |
||
194 | |||
195 | /* Capture libraries */ |
||
196 | g_string_append(str, ", "); |
||
197 | get_compiled_caplibs_version(str); |
||
198 | } |
||
199 | |||
200 | // xxx copied from ../gtk/main.c |
||
201 | void |
||
202 | get_gui_compiled_info(GString *str) |
||
203 | { |
||
204 | epan_get_compiled_version_info(str); |
||
205 | |||
206 | g_string_append(str, ", "); |
||
207 | #ifdef QT_MULTIMEDIA_LIB |
||
208 | g_string_append(str, "with QtMultimedia"); |
||
209 | #else |
||
210 | g_string_append(str, "without QtMultimedia"); |
||
211 | #endif |
||
212 | |||
213 | g_string_append(str, ", "); |
||
214 | #ifdef HAVE_AIRPCAP |
||
215 | get_compiled_airpcap_version(str); |
||
216 | #else |
||
217 | g_string_append(str, "without AirPcap"); |
||
218 | #endif |
||
219 | } |
||
220 | |||
221 | // xxx copied from ../gtk/main.c |
||
222 | void |
||
223 | get_wireshark_runtime_info(GString *str) |
||
224 | { |
||
225 | #ifdef HAVE_LIBPCAP |
||
226 | /* Capture libraries */ |
||
227 | g_string_append(str, ", "); |
||
228 | get_runtime_caplibs_version(str); |
||
229 | #endif |
||
230 | |||
231 | /* stuff used by libwireshark */ |
||
232 | epan_get_runtime_version_info(str); |
||
233 | |||
234 | #ifdef HAVE_AIRPCAP |
||
235 | g_string_append(str, ", "); |
||
236 | get_runtime_airpcap_version(str); |
||
237 | #endif |
||
238 | } |
||
239 | |||
240 | #ifdef HAVE_LIBPCAP |
||
241 | /* Check if there's something important to tell the user during startup. |
||
242 | * We want to do this *after* showing the main window so that any windows |
||
243 | * we pop up will be above the main window. |
||
244 | */ |
||
245 | static void |
||
246 | check_and_warn_user_startup(const QString &cf_name) |
||
247 | { |
||
248 | #ifndef _WIN32 |
||
249 | Q_UNUSED(cf_name) |
||
250 | #endif |
||
251 | gchar *cur_user, *cur_group; |
||
252 | |||
253 | /* Tell the user not to run as root. */ |
||
254 | if (running_with_special_privs() && recent.privs_warn_if_elevated) { |
||
255 | cur_user = get_cur_username(); |
||
256 | cur_group = get_cur_groupname(); |
||
257 | simple_message_box(ESD_TYPE_WARN, &recent.privs_warn_if_elevated, |
||
258 | "Running as user \"%s\" and group \"%s\".\n" |
||
259 | "This could be dangerous.\n\n" |
||
260 | "If you're running Wireshark this way in order to perform live capture, " |
||
261 | "you may want to be aware that there is a better way documented at\n" |
||
262 | "https://wiki.wireshark.org/CaptureSetup/CapturePrivileges", cur_user, cur_group); |
||
263 | g_free(cur_user); |
||
264 | g_free(cur_group); |
||
265 | } |
||
266 | |||
267 | #ifdef _WIN32 |
||
268 | /* Warn the user if npf.sys isn't loaded. */ |
||
269 | if (!get_stdin_capture() && cf_name.isEmpty() && !npf_sys_is_running() && recent.privs_warn_if_no_npf && get_windows_major_version() >= 6) { |
||
270 | simple_message_box(ESD_TYPE_WARN, &recent.privs_warn_if_no_npf, "%s", |
||
271 | "The NPF driver isn't running. You may have trouble\n" |
||
272 | "capturing or listing interfaces."); |
||
273 | } |
||
274 | #endif |
||
275 | |||
276 | } |
||
277 | #endif |
||
278 | |||
279 | #ifdef _WIN32 |
||
280 | // Try to avoid library search path collisions. QCoreApplication will |
||
281 | // search QT_INSTALL_PREFIX/plugins for platform DLLs before searching |
||
282 | // the application directory. If |
||
283 | // |
||
284 | // - You have Qt version 5.x.y installed in the default location |
||
285 | // (C:\Qt\5.x) on your machine. |
||
286 | // |
||
287 | // and |
||
288 | // |
||
289 | // - You install Wireshark that was built on a machine with Qt version |
||
290 | // 5.x.z installed in the default location. |
||
291 | // |
||
292 | // Qt5Core.dll will load qwindows.dll from your local C:\Qt\5.x\...\plugins |
||
293 | // directory. This may not be compatible with qwindows.dll from that |
||
294 | // same path on the build machine. At any rate, loading DLLs from paths |
||
295 | // you don't control is ill-advised. We work around this by removing every |
||
296 | // path except our application directory. |
||
297 | |||
298 | static inline void |
||
299 | reset_library_path(void) |
||
300 | { |
||
301 | QString app_path = QDir(get_progfile_dir()).path(); |
||
302 | foreach (QString path, QCoreApplication::libraryPaths()) { |
||
303 | QCoreApplication::removeLibraryPath(path); |
||
304 | } |
||
305 | QCoreApplication::addLibraryPath(app_path); |
||
306 | } |
||
307 | #endif |
||
308 | |||
309 | /* And now our feature presentation... [ fade to music ] */ |
||
310 | int main(int argc, char *qt_argv[]) |
||
311 | { |
||
312 | MainWindow *main_w; |
||
313 | |||
314 | #ifdef _WIN32 |
||
315 | int opt; |
||
316 | #endif |
||
317 | int ret_val; |
||
318 | char **argv = qt_argv; |
||
319 | |||
320 | #ifdef _WIN32 |
||
321 | WSADATA wsaData; |
||
322 | #endif /* _WIN32 */ |
||
323 | |||
324 | char *rf_path; |
||
325 | int rf_open_errno; |
||
326 | char *gdp_path, *dp_path; |
||
327 | #ifdef HAVE_LIBPCAP |
||
328 | gchar *err_str; |
||
329 | int status; |
||
330 | #else |
||
331 | #ifdef _WIN32 |
||
332 | #ifdef HAVE_AIRPCAP |
||
333 | gchar *err_str; |
||
334 | #endif |
||
335 | #endif |
||
336 | #endif |
||
337 | GString *comp_info_str = NULL; |
||
338 | GString *runtime_info_str = NULL; |
||
339 | |||
340 | QString dfilter, read_filter; |
||
341 | |||
342 | cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont); |
||
343 | |||
344 | // In Qt 5, C strings are treated always as UTF-8 when converted to |
||
345 | // QStrings; in Qt 4, the codec must be set to make that happen |
||
346 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) |
||
347 | // Hopefully we won't have to use QString::fromUtf8() in as many places. |
||
348 | QTextCodec *utf8codec = QTextCodec::codecForName("UTF-8"); |
||
349 | QTextCodec::setCodecForCStrings(utf8codec); |
||
350 | // XXX - QObject doesn't *have* a tr method in 5.0, as far as I can see... |
||
351 | QTextCodec::setCodecForTr(utf8codec); |
||
352 | #endif |
||
353 | |||
354 | /* Set the C-language locale to the native environment. */ |
||
355 | setlocale(LC_ALL, ""); |
||
356 | |||
357 | #ifdef _WIN32 |
||
358 | // QCoreApplication clobbers argv. Let's have a local copy. |
||
359 | argv = (char **) g_malloc(sizeof(char *) * argc); |
||
360 | for (opt = 0; opt < argc; opt++) { |
||
361 | argv[opt] = qt_argv[opt]; |
||
362 | } |
||
363 | arg_list_utf_16to8(argc, argv); |
||
364 | create_app_running_mutex(); |
||
365 | #endif /* _WIN32 */ |
||
366 | |||
367 | /* |
||
368 | * Get credential information for later use, and drop privileges |
||
369 | * before doing anything else. |
||
370 | * Let the user know if anything happened. |
||
371 | */ |
||
372 | init_process_policies(); |
||
373 | relinquish_special_privs_perm(); |
||
374 | |||
375 | /* |
||
376 | * Attempt to get the pathname of the executable file. |
||
377 | */ |
||
378 | /* init_progfile_dir_error = */ init_progfile_dir(argv[0], |
||
379 | (int (*)(int, char **)) get_gui_compiled_info); |
||
380 | g_log(NULL, G_LOG_LEVEL_DEBUG, "progfile_dir: %s", get_progfile_dir()); |
||
381 | |||
382 | #ifdef _WIN32 |
||
383 | ws_init_dll_search_path(); |
||
384 | /* Load wpcap if possible. Do this before collecting the run-time version information */ |
||
385 | load_wpcap(); |
||
386 | |||
387 | /* ... and also load the packet.dll from wpcap */ |
||
388 | wpcap_packet_load(); |
||
389 | |||
390 | #ifdef HAVE_AIRPCAP |
||
391 | /* Load the airpcap.dll. This must also be done before collecting |
||
392 | * run-time version information. */ |
||
393 | load_airpcap(); |
||
394 | #if 0 |
||
395 | airpcap_dll_ret_val = load_airpcap(); |
||
396 | |||
397 | switch (airpcap_dll_ret_val) { |
||
398 | case AIRPCAP_DLL_OK: |
||
399 | /* load the airpcap interfaces */ |
||
400 | g_airpcap_if_list = get_airpcap_interface_list(&err, &err_str); |
||
401 | |||
402 | if (g_airpcap_if_list == NULL || g_list_length(g_airpcap_if_list) == 0){ |
||
403 | if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) { |
||
404 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters."); |
||
405 | g_free(err_str); |
||
406 | } |
||
407 | airpcap_if_active = NULL; |
||
408 | |||
409 | } else { |
||
410 | |||
411 | /* select the first ad default (THIS SHOULD BE CHANGED) */ |
||
412 | airpcap_if_active = airpcap_get_default_if(airpcap_if_list); |
||
413 | } |
||
414 | break; |
||
415 | /* |
||
416 | * XXX - Maybe we need to warn the user if one of the following happens??? |
||
417 | */ |
||
418 | case AIRPCAP_DLL_OLD: |
||
419 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n"); |
||
420 | break; |
||
421 | |||
422 | case AIRPCAP_DLL_ERROR: |
||
423 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n"); |
||
424 | break; |
||
425 | |||
426 | case AIRPCAP_DLL_NOT_FOUND: |
||
427 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n"); |
||
428 | break; |
||
429 | } |
||
430 | #endif |
||
431 | #endif /* HAVE_AIRPCAP */ |
||
432 | #endif /* _WIN32 */ |
||
433 | |||
434 | /* Get the compile-time version information string */ |
||
435 | comp_info_str = get_compiled_version_info(get_wireshark_qt_compiled_info, |
||
436 | get_gui_compiled_info); |
||
437 | |||
438 | /* Assemble the run-time version information string */ |
||
439 | runtime_info_str = get_runtime_version_info(get_wireshark_runtime_info); |
||
440 | |||
441 | profile_store_persconffiles(TRUE); |
||
442 | |||
443 | /* Read the profile independent recent file. We have to do this here so we can */ |
||
444 | /* set the profile before it can be set from the command line parameter */ |
||
445 | if (!recent_read_static(&rf_path, &rf_open_errno)) { |
||
446 | simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, |
||
447 | "Could not open common recent file\n\"%s\": %s.", |
||
448 | rf_path, strerror(rf_open_errno)); |
||
449 | g_free(rf_path); |
||
450 | } |
||
451 | |||
452 | commandline_early_options(argc, argv, comp_info_str, runtime_info_str); |
||
453 | |||
454 | #ifdef _WIN32 |
||
455 | reset_library_path(); |
||
456 | #endif |
||
457 | |||
458 | /* Create The Wireshark app */ |
||
459 | WiresharkApplication ws_app(argc, qt_argv); |
||
460 | |||
461 | /* initialize the funnel mini-api */ |
||
462 | // xxx qtshark |
||
463 | //initialize_funnel_ops(); |
||
464 | |||
465 | AirPDcapInitContext(&airpdcap_ctx); |
||
466 | |||
467 | QString cf_name; |
||
468 | unsigned int in_file_type = WTAP_TYPE_AUTO; |
||
469 | |||
470 | /* Add it to the information to be reported on a crash. */ |
||
471 | ws_add_crash_info("Wireshark %s\n" |
||
472 | "\n" |
||
473 | "%s" |
||
474 | "\n" |
||
475 | "%s", |
||
476 | get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str); |
||
477 | |||
478 | #ifdef _WIN32 |
||
479 | /* Start windows sockets */ |
||
480 | WSAStartup( MAKEWORD( 1, 1 ), &wsaData ); |
||
481 | #endif /* _WIN32 */ |
||
482 | |||
483 | /* Read the profile dependent (static part) of the recent file. */ |
||
484 | /* Only the static part of it will be read, as we don't have the gui now to fill the */ |
||
485 | /* recent lists which is done in the dynamic part. */ |
||
486 | /* We have to do this already here, so command line parameters can overwrite these values. */ |
||
487 | if (!recent_read_profile_static(&rf_path, &rf_open_errno)) { |
||
488 | simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, |
||
489 | "Could not open recent file\n\"%s\": %s.", |
||
490 | rf_path, g_strerror(rf_open_errno)); |
||
491 | g_free(rf_path); |
||
492 | } |
||
493 | wsApp->applyCustomColorsFromRecent(); |
||
494 | |||
495 | // Initialize our language |
||
496 | read_language_prefs(); |
||
497 | wsApp->loadLanguage(language); |
||
498 | |||
499 | g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Translator %s", language); |
||
500 | |||
501 | // Init the main window (and splash) |
||
502 | main_w = new(MainWindow); |
||
503 | main_w->show(); |
||
504 | // We may not need a queued connection here but it would seem to make sense |
||
505 | // to force the issue. |
||
506 | main_w->connect(&ws_app, SIGNAL(openCaptureFile(QString,QString,unsigned int)), |
||
507 | main_w, SLOT(openCaptureFile(QString,QString,unsigned int))); |
||
508 | |||
509 | /* Init the "Open file" dialog directory */ |
||
510 | /* (do this after the path settings are processed) */ |
||
511 | if (recent.gui_fileopen_remembered_dir && |
||
512 | test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) { |
||
513 | wsApp->setLastOpenDir(recent.gui_fileopen_remembered_dir); |
||
514 | } else { |
||
515 | wsApp->setLastOpenDir(get_persdatafile_dir()); |
||
516 | } |
||
517 | |||
518 | #ifdef Q_OS_UNIX |
||
519 | // Replicates behavior in gtk_init(); |
||
520 | signal(SIGPIPE, SIG_IGN); |
||
521 | #endif |
||
522 | |||
523 | set_console_log_handler(); |
||
524 | |||
525 | #ifdef HAVE_LIBPCAP |
||
526 | /* Set the initial values in the capture options. This might be overwritten |
||
527 | by preference settings and then again by the command line parameters. */ |
||
528 | capture_opts_init(&global_capture_opts); |
||
529 | #endif |
||
530 | |||
531 | init_report_err(vfailure_alert_box, open_failure_alert_box, |
||
532 | read_failure_alert_box, write_failure_alert_box); |
||
533 | |||
534 | init_open_routines(); |
||
535 | |||
536 | #ifdef HAVE_PLUGINS |
||
537 | /* Register all the plugin types we have. */ |
||
538 | epan_register_plugin_types(); /* Types known to libwireshark */ |
||
539 | wtap_register_plugin_types(); /* Types known to libwiretap */ |
||
540 | codec_register_plugin_types(); /* Types known to libwscodecs */ |
||
541 | |||
542 | /* Scan for plugins. This does *not* call their registration routines; |
||
543 | that's done later. */ |
||
544 | scan_plugins(); |
||
545 | |||
546 | /* Register all libwiretap plugin modules. */ |
||
547 | register_all_wiretap_modules(); |
||
548 | |||
549 | /* Register all audio codec plugins. */ |
||
550 | register_all_codecs(); |
||
551 | #endif |
||
552 | |||
553 | /* Register all dissectors; we must do this before checking for the |
||
554 | "-G" flag, as the "-G" flag dumps information registered by the |
||
555 | dissectors, and we must do it before we read the preferences, in |
||
556 | case any dissectors register preferences. */ |
||
557 | if (!epan_init(register_all_protocols,register_all_protocol_handoffs, |
||
558 | splash_update, NULL)) { |
||
559 | SimpleDialog::displayQueuedMessages(main_w); |
||
560 | return 2; |
||
561 | } |
||
562 | |||
563 | splash_update(RA_LISTENERS, NULL, NULL); |
||
564 | |||
565 | /* Register all tap listeners; we do this before we parse the arguments, |
||
566 | as the "-z" argument can specify a registered tap. */ |
||
567 | |||
568 | /* we register the plugin taps before the other taps because |
||
569 | stats_tree taps plugins will be registered as tap listeners |
||
570 | by stats_tree_stat.c and need to registered before that */ |
||
571 | #ifdef HAVE_PLUGINS |
||
572 | register_all_plugin_tap_listeners(); |
||
573 | #endif |
||
574 | |||
575 | #ifdef HAVE_EXTCAP |
||
576 | extcap_register_preferences(); |
||
577 | #endif |
||
578 | |||
579 | register_all_tap_listeners(); |
||
580 | conversation_table_set_gui_info(init_conversation_table); |
||
581 | hostlist_table_set_gui_info(init_endpoint_table); |
||
582 | srt_table_iterate_tables(register_service_response_tables, NULL); |
||
583 | rtd_table_iterate_tables(register_response_time_delay_tables, NULL); |
||
584 | new_stat_tap_iterate_tables(register_simple_stat_tables, NULL); |
||
585 | |||
586 | if (ex_opt_count("read_format") > 0) { |
||
587 | in_file_type = open_info_name_to_type(ex_opt_get_next("read_format")); |
||
588 | } |
||
589 | |||
590 | splash_update(RA_PREFERENCES, NULL, NULL); |
||
591 | |||
592 | global_commandline_info.prefs_p = ws_app.readConfigurationFiles(&gdp_path, &dp_path, false); |
||
593 | |||
594 | /* Now get our args */ |
||
595 | commandline_other_options(argc, argv, TRUE); |
||
596 | |||
597 | /* Convert some command-line parameters to QStrings */ |
||
598 | if (global_commandline_info.cf_name != NULL) |
||
599 | cf_name = QString(global_commandline_info.cf_name); |
||
600 | if (global_commandline_info.rfilter != NULL) |
||
601 | read_filter = QString(global_commandline_info.rfilter); |
||
602 | if (global_commandline_info.dfilter != NULL) |
||
603 | dfilter = QString(global_commandline_info.dfilter); |
||
604 | |||
605 | /* Removed thread code: |
||
606 | * https://code.wireshark.org/review/gitweb?p=wireshark.git;a=commit;h=9e277ae6154fd04bf6a0a34ec5655a73e5a736a3 |
||
607 | */ |
||
608 | |||
609 | timestamp_set_type(recent.gui_time_format); |
||
610 | timestamp_set_precision(recent.gui_time_precision); |
||
611 | timestamp_set_seconds_type (recent.gui_seconds_format); |
||
612 | |||
613 | #ifdef HAVE_LIBPCAP |
||
614 | splash_update(RA_INTERFACES, NULL, NULL); |
||
615 | |||
616 | fill_in_local_interfaces(main_window_update); |
||
617 | |||
618 | if (global_commandline_info.start_capture || global_commandline_info.list_link_layer_types) { |
||
619 | /* We're supposed to do a live capture or get a list of link-layer |
||
620 | types for a live capture device; if the user didn't specify an |
||
621 | interface to use, pick a default. */ |
||
622 | status = capture_opts_default_iface_if_necessary(&global_capture_opts, |
||
623 | ((global_commandline_info.prefs_p->capture_device) && (*global_commandline_info.prefs_p->capture_device != '\0')) ? get_if_name(global_commandline_info.prefs_p->capture_device) : NULL); |
||
624 | if (status != 0) { |
||
625 | exit(status); |
||
626 | } |
||
627 | } |
||
628 | |||
629 | if (global_commandline_info.list_link_layer_types) { |
||
630 | /* Get the list of link-layer types for the capture devices. */ |
||
631 | if_capabilities_t *caps; |
||
632 | guint i; |
||
633 | interface_t device; |
||
634 | for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { |
||
635 | |||
636 | device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); |
||
637 | if (device.selected) { |
||
638 | #if defined(HAVE_PCAP_CREATE) |
||
639 | caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, NULL, &err_str, main_window_update); |
||
640 | #else |
||
641 | caps = capture_get_if_capabilities(device.name, FALSE, NULL, &err_str,main_window_update); |
||
642 | #endif |
||
643 | if (caps == NULL) { |
||
644 | cmdarg_err("%s", err_str); |
||
645 | g_free(err_str); |
||
646 | exit(2); |
||
647 | } |
||
648 | if (caps->data_link_types == NULL) { |
||
649 | cmdarg_err("The capture device \"%s\" has no data link types.", device.name); |
||
650 | exit(2); |
||
651 | } |
||
652 | #ifdef _WIN32 |
||
653 | create_console(); |
||
654 | #endif /* _WIN32 */ |
||
655 | #if defined(HAVE_PCAP_CREATE) |
||
656 | capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported); |
||
657 | #else |
||
658 | capture_opts_print_if_capabilities(caps, device.name, FALSE); |
||
659 | #endif |
||
660 | #ifdef _WIN32 |
||
661 | destroy_console(); |
||
662 | #endif /* _WIN32 */ |
||
663 | free_if_capabilities(caps); |
||
664 | } |
||
665 | } |
||
666 | exit(0); |
||
667 | } |
||
668 | |||
669 | capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE); |
||
670 | capture_opts_trim_ring_num_files(&global_capture_opts); |
||
671 | #endif /* HAVE_LIBPCAP */ |
||
672 | |||
673 | /* Notify all registered modules that have had any of their preferences |
||
674 | changed either from one of the preferences file or from the command |
||
675 | line that their preferences have changed. */ |
||
676 | prefs_apply_all(); |
||
677 | wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged); |
||
678 | |||
679 | #ifdef HAVE_LIBPCAP |
||
680 | if ((global_capture_opts.num_selected == 0) && |
||
681 | (prefs.capture_device != NULL)) { |
||
682 | guint i; |
||
683 | interface_t device; |
||
684 | for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { |
||
685 | device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); |
||
686 | if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) { |
||
687 | device.selected = TRUE; |
||
688 | global_capture_opts.num_selected++; |
||
689 | global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); |
||
690 | g_array_insert_val(global_capture_opts.all_ifaces, i, device); |
||
691 | break; |
||
692 | } |
||
693 | } |
||
694 | } |
||
695 | #endif |
||
696 | |||
697 | /* disabled protocols as per configuration file */ |
||
698 | if (gdp_path == NULL && dp_path == NULL) { |
||
699 | set_disabled_protos_list(); |
||
700 | set_disabled_heur_dissector_list(); |
||
701 | } |
||
702 | |||
703 | if(global_commandline_info.disable_protocol_slist) { |
||
704 | GSList *proto_disable; |
||
705 | for (proto_disable = global_commandline_info.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable)) |
||
706 | { |
||
707 | proto_disable_proto_by_name((char*)proto_disable->data); |
||
708 | } |
||
709 | } |
||
710 | |||
711 | if(global_commandline_info.enable_heur_slist) { |
||
712 | GSList *heur_enable; |
||
713 | for (heur_enable = global_commandline_info.enable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable)) |
||
714 | { |
||
715 | proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE); |
||
716 | } |
||
717 | } |
||
718 | |||
719 | if(global_commandline_info.disable_heur_slist) { |
||
720 | GSList *heur_disable; |
||
721 | for (heur_disable = global_commandline_info.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable)) |
||
722 | { |
||
723 | proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE); |
||
724 | } |
||
725 | } |
||
726 | |||
727 | build_column_format_array(&CaptureFile::globalCapFile()->cinfo, global_commandline_info.prefs_p->num_cols, TRUE); |
||
728 | wsApp->emitAppSignal(WiresharkApplication::ColumnsChanged); // We read "recent" widths above. |
||
729 | wsApp->emitAppSignal(WiresharkApplication::RecentFilesRead); // Must be emitted after PreferencesChanged. |
||
730 | |||
731 | wsApp->setMonospaceFont(prefs.gui_qt_font_name); |
||
732 | |||
733 | /* For update of WindowTitle (When use gui.window_title preference) */ |
||
734 | main_w->setWSWindowTitle(); |
||
735 | //////// |
||
736 | |||
737 | /* Read the dynamic part of the recent file, as we have the gui now ready for |
||
738 | it. */ |
||
739 | if (!recent_read_dynamic(&rf_path, &rf_open_errno)) { |
||
740 | simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, |
||
741 | "Could not open recent file\n\"%s\": %s.", |
||
742 | rf_path, g_strerror(rf_open_errno)); |
||
743 | g_free(rf_path); |
||
744 | } |
||
745 | |||
746 | packet_list_enable_color(recent.packet_list_colorize); |
||
747 | |||
748 | g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: fetch recent color settings"); |
||
749 | packet_list_enable_color(TRUE); |
||
750 | |||
751 | //////// |
||
752 | |||
753 | |||
754 | //////// |
||
755 | gchar* err_msg = NULL; |
||
756 | if (!color_filters_init(&err_msg, color_filter_add_cb)) { |
||
757 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg); |
||
758 | g_free(err_msg); |
||
759 | } |
||
760 | |||
761 | //////// |
||
762 | |||
763 | #ifdef HAVE_LIBPCAP |
||
764 | /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */ |
||
765 | if (!global_commandline_info.start_capture && !global_capture_opts.default_options.cfilter) { |
||
766 | global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter()); |
||
767 | } |
||
768 | #else /* HAVE_LIBPCAP */ |
||
769 | //////// |
||
770 | #endif /* HAVE_LIBPCAP */ |
||
771 | |||
772 | wsApp->allSystemsGo(); |
||
773 | g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "Wireshark is up and ready to go"); |
||
774 | SimpleDialog::displayQueuedMessages(main_w); |
||
775 | |||
776 | /* User could specify filename, or display filter, or both */ |
||
777 | if (!dfilter.isEmpty()) |
||
778 | main_w->filterPackets(dfilter, false); |
||
779 | if (!cf_name.isEmpty()) { |
||
780 | if (main_w->openCaptureFile(cf_name, read_filter, in_file_type)) { |
||
781 | |||
782 | /* Open stat windows; we do so after creating the main window, |
||
783 | to avoid Qt warnings, and after successfully opening the |
||
784 | capture file, so we know we have something to compute stats |
||
785 | on, and after registering all dissectors, so that MATE will |
||
786 | have registered its field array and we can have a tap filter |
||
787 | with one of MATE's late-registered fields as part of the |
||
788 | filter. */ |
||
789 | start_requested_stats(); |
||
790 | |||
791 | if(global_commandline_info.go_to_packet != 0) { |
||
792 | /* Jump to the specified frame number, kept for backward |
||
793 | compatibility. */ |
||
794 | cf_goto_frame(CaptureFile::globalCapFile(), global_commandline_info.go_to_packet); |
||
795 | } else if (global_commandline_info.jfilter != NULL) { |
||
796 | dfilter_t *jump_to_filter = NULL; |
||
797 | /* try to compile given filter */ |
||
798 | if (!dfilter_compile(global_commandline_info.jfilter, &jump_to_filter, &err_msg)) { |
||
799 | // Similar code in MainWindow::mergeCaptureFile(). |
||
800 | QMessageBox::warning(main_w, QObject::tr("Invalid Display Filter"), |
||
801 | QObject::tr("The filter expression %1 isn't a valid display filter. (%2).") |
||
802 | .arg(global_commandline_info.jfilter, err_msg), |
||
803 | QMessageBox::Ok); |
||
804 | g_free(err_msg); |
||
805 | } else { |
||
806 | /* Filter ok, jump to the first packet matching the filter |
||
807 | conditions. Default search direction is forward, but if |
||
808 | option d was given, search backwards */ |
||
809 | cf_find_packet_dfilter(CaptureFile::globalCapFile(), jump_to_filter, global_commandline_info.jump_backwards); |
||
810 | } |
||
811 | } |
||
812 | } |
||
813 | } |
||
814 | #ifdef HAVE_LIBPCAP |
||
815 | else { |
||
816 | if (global_commandline_info.start_capture) { |
||
817 | if (global_capture_opts.save_file != NULL) { |
||
818 | /* Save the directory name for future file dialogs. */ |
||
819 | /* (get_dirname overwrites filename) */ |
||
820 | gchar *s = g_strdup(global_capture_opts.save_file); |
||
821 | set_last_open_dir(get_dirname(s)); |
||
822 | g_free(s); |
||
823 | } |
||
824 | /* "-k" was specified; start a capture. */ |
||
825 | // show_main_window(FALSE); |
||
826 | check_and_warn_user_startup(cf_name); |
||
827 | |||
828 | /* If no user interfaces were specified on the command line, |
||
829 | copy the list of selected interfaces to the set of interfaces |
||
830 | to use for this capture. */ |
||
831 | if (global_capture_opts.ifaces->len == 0) |
||
832 | collect_ifaces(&global_capture_opts); |
||
833 | CaptureFile::globalCapFile()->window = main_w; |
||
834 | if (capture_start(&global_capture_opts, main_w->captureSession(), main_w->captureInfoData(), main_window_update)) { |
||
835 | /* The capture started. Open stat windows; we do so after creating |
||
836 | the main window, to avoid GTK warnings, and after successfully |
||
837 | opening the capture file, so we know we have something to compute |
||
838 | stats on, and after registering all dissectors, so that MATE will |
||
839 | have registered its field array and we can have a tap filter with |
||
840 | one of MATE's late-registered fields as part of the filter. */ |
||
841 | start_requested_stats(); |
||
842 | } |
||
843 | } |
||
844 | /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */ |
||
845 | if (!global_commandline_info.start_capture && !global_capture_opts.default_options.cfilter) { |
||
846 | global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter()); |
||
847 | } |
||
848 | } |
||
849 | #endif /* HAVE_LIBPCAP */ |
||
850 | |||
851 | profile_store_persconffiles(FALSE); |
||
852 | |||
853 | ret_val = wsApp->exec(); |
||
854 | |||
855 | epan_cleanup(); |
||
856 | |||
857 | #ifdef HAVE_EXTCAP |
||
858 | extcap_cleanup(); |
||
859 | #endif |
||
860 | |||
861 | AirPDcapDestroyContext(&airpdcap_ctx); |
||
862 | |||
863 | #ifdef _WIN32 |
||
864 | /* Shutdown windows sockets */ |
||
865 | WSACleanup(); |
||
866 | |||
867 | /* For some unknown reason, the "atexit()" call in "create_console()" |
||
868 | doesn't arrange that "destroy_console()" be called when we exit, |
||
869 | so we call it here if a console was created. */ |
||
870 | destroy_console(); |
||
871 | #endif /* _WIN32 */ |
||
872 | |||
873 | return ret_val; |
||
874 | } |
||
875 | |||
876 | /* |
||
877 | * Editor modelines |
||
878 | * |
||
879 | * Local Variables: |
||
880 | * c-basic-offset: 4 |
||
881 | * tab-width: 8 |
||
882 | * indent-tabs-mode: nil |
||
883 | * End: |
||
884 | * |
||
885 | * ex: set shiftwidth=4 tabstop=8 expandtab: |
||
886 | * :indentSize=4:tabSize=8:noTabs=true: |
||
887 | */ |