#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
#include <wsutil/privileges.h>
-#include <wsutil/report_err.h>
-#include <ws_version_info.h>
+#include <wsutil/report_message.h>
+#include <version_info.h>
#include <wiretap/merge.h>
#include "ui/alert_box.h"
#include "ui/console.h"
#include "ui/decode_as_utils.h"
-#include "filter_files.h"
+#include "ui/filter_files.h"
#include "ui/main_statusbar.h"
#include "ui/persfilepath_opt.h"
#include "ui/preference_utils.h"
#include <gtkmacintegration/gtkosxapplication.h>
#endif
+#define INVALID_OPTION 1
+#define INIT_FAILED 2
+#define INVALID_CAPABILITY 2
+#define INVALID_LINK_TYPE 2
+
/*
* Files under personal and global preferences directories in which
* GTK settings for Wireshark are stored.
char *cur_filter, *new_filter;
if ((!text) || (0 == strlen(text))) {
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to build a filter!\nTry expanding or choosing another item.");
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to build a filter.\nTry expanding or choosing another item.");
return;
}
cfile.edt);
if ((!filter) || (0 == strlen(filter))) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "Could not acquire information to build a filter!\n"
+ "Could not acquire information to build a filter.\n"
"Try expanding or choosing another item.");
return;
}
"As everyone can edit the Wiki and add new content (or extend existing), "
"you are encouraged to add information if you can.\n"
"\n"
- "Hint 1: If you are new to wiki editing, try out editing the Sandbox first!\n"
+ "Hint 1: If you are new to wiki editing, try out editing the Sandbox first.\n"
"\n"
"Hint 2: If you want to add a new protocol page, you should use the ProtocolTemplate, "
"which will save you a lot of editing and will give a consistent look over the pages.",
* rather than, say, a progress spinner, here! */
if(cf->count > 10000) {
close_dlg = (GtkWidget *)simple_dialog(ESD_TYPE_STOP, ESD_BTN_NONE,
- "%sClosing file!%s\n\nPlease wait ...",
+ "%sClosing file.%s\n\nPlease wait ...",
simple_dialog_primary_start(),
simple_dialog_primary_end());
gtk_window_set_position(GTK_WINDOW(close_dlg), GTK_WIN_POS_CENTER_ON_PARENT);
}
static e_prefs *
-read_configuration_files(char **gdp_path, char **dp_path)
-{
- int gpf_open_errno, gpf_read_errno;
- int cf_open_errno, df_open_errno;
- int gdp_open_errno, gdp_read_errno;
- int dp_open_errno, dp_read_errno;
- char *gpf_path, *pf_path;
- char *cf_path, *df_path;
- int pf_open_errno, pf_read_errno;
+read_configuration_files(void)
+{
e_prefs *prefs_p;
- /* load the decode as entries of this profile */
- load_decode_as_entries();
-
- /* Read the preference files. */
- prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
-
- if (gpf_path != NULL) {
- if (gpf_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open global preferences file\n\"%s\": %s.",
- gpf_path, g_strerror(gpf_open_errno));
- }
- if (gpf_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading global preferences file\n\"%s\": %s.",
- gpf_path, g_strerror(gpf_read_errno));
- }
- }
- if (pf_path != NULL) {
- if (pf_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your preferences file\n\"%s\": %s.",
- pf_path, g_strerror(pf_open_errno));
- }
- if (pf_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading your preferences file\n\"%s\": %s.",
- pf_path, g_strerror(pf_read_errno));
- }
- g_free(pf_path);
- pf_path = NULL;
- }
+ /* Load libwireshark settings from the current profile. */
+ prefs_p = epan_load_settings();
#ifdef _WIN32
/* if the user wants a console to be always there, well, we should open one for him */
#endif
/* Read the capture filter file. */
- read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
- if (cf_path != NULL) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your capture filter file\n\"%s\": %s.",
- cf_path, g_strerror(cf_open_errno));
- g_free(cf_path);
- }
+ read_filter_list(CFILTER_LIST);
/* Read the display filter file. */
- read_filter_list(DFILTER_LIST, &df_path, &df_open_errno);
- if (df_path != NULL) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your display filter file\n\"%s\": %s.",
- df_path, g_strerror(df_open_errno));
- g_free(df_path);
- }
-
- /* Read the disabled protocols file. */
- read_disabled_protos_list(gdp_path, &gdp_open_errno, &gdp_read_errno,
- dp_path, &dp_open_errno, &dp_read_errno);
- read_enabled_protos_list(gdp_path, &gdp_open_errno, &gdp_read_errno,
- dp_path, &dp_open_errno, &dp_read_errno);
- read_disabled_heur_dissector_list(gdp_path, &gdp_open_errno, &gdp_read_errno,
- dp_path, &dp_open_errno, &dp_read_errno);
- if (*gdp_path != NULL) {
- if (gdp_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open global disabled protocols file\n\"%s\": %s.",
- *gdp_path, g_strerror(gdp_open_errno));
- }
- if (gdp_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading global disabled protocols file\n\"%s\": %s.",
- *gdp_path, g_strerror(gdp_read_errno));
- }
- g_free(*gdp_path);
- *gdp_path = NULL;
- }
- if (*dp_path != NULL) {
- if (dp_open_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your disabled protocols file\n\"%s\": %s.",
- *dp_path, g_strerror(dp_open_errno));
- }
- if (dp_read_errno != 0) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "I/O error reading your disabled protocols file\n\"%s\": %s.",
- *dp_path, g_strerror(dp_read_errno));
- }
- g_free(*dp_path);
- *dp_path = NULL;
- }
+ read_filter_list(DFILTER_LIST);
return prefs_p;
}
{
char *init_progfile_dir_error;
char *s;
-
+ int ret = EXIT_SUCCESS;
extern int info_update_freq; /* Found in about_dlg.c. */
const gchar *filter;
#ifdef _WIN32
WSADATA wsaData;
+ int result;
#endif /* _WIN32 */
char *rf_path;
int rf_open_errno;
- char *gdp_path, *dp_path;
int err;
#ifdef HAVE_LIBPCAP
gchar *err_str;
- int status;
+ int caps_queries = 0;
#else
#ifdef _WIN32
#ifdef HAVE_AIRPCAP
#ifdef _WIN32
/* Start windows sockets */
- WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
+ result = WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
+ if (result != 0) {
+ simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+ "Error: WSAStartup failed with error: %d", result);
+ ret = INIT_FAILED;
+ goto clean_exit;
+ }
#endif /* _WIN32 */
profile_store_persconffiles (TRUE);
capture_session_init(&global_capture_session, &cfile);
#endif
- init_report_err(vfailure_alert_box, open_failure_alert_box,
- read_failure_alert_box, write_failure_alert_box);
+ init_report_message(vfailure_alert_box, vwarning_alert_box,
+ open_failure_alert_box, read_failure_alert_box,
+ write_failure_alert_box);
/* Non-blank filter means we're remote. Throttle splash screen and resolution updates. */
filter = get_conn_cfilter();
dissectors, and we must do it before we read the preferences, in
case any dissectors register preferences. */
if (!epan_init(register_all_protocols,register_all_protocol_handoffs,
- splash_update, (gpointer) splash_win))
- return 2;
+ splash_update, (gpointer) splash_win)) {
+ ret = INIT_FAILED;
+ goto clean_exit;
+ }
splash_update(RA_LISTENERS, NULL, (gpointer)splash_win);
splash_update(RA_PREFERENCES, NULL, (gpointer)splash_win);
- global_commandline_info.prefs_p = read_configuration_files (&gdp_path, &dp_path);
+ global_commandline_info.prefs_p = read_configuration_files();
/* Removed thread code:
* https://code.wireshark.org/review/gitweb?p=wireshark.git;a=commit;h=9e277ae6154fd04bf6a0a34ec5655a73e5a736a3
*/
- splash_update(RA_CONFIGURATION, NULL, (gpointer)splash_win);
cap_file_init(&cfile);
/* Fill in capture options with values from the preferences */
fill_in_local_interfaces(main_window_update);
- if (global_commandline_info.start_capture || global_commandline_info.list_link_layer_types) {
- /* We're supposed to do a live capture or get a list of link-layer
+ if (global_commandline_info.list_link_layer_types)
+ caps_queries |= CAPS_QUERY_LINK_TYPES;
+ if (global_commandline_info.list_timestamp_types)
+ caps_queries |= CAPS_QUERY_TIMESTAMP_TYPES;
+
+ if (global_commandline_info.start_capture || caps_queries) {
+ /* We're supposed to do a live capture or get a list of link-layer/timestamp
types for a live capture device; if the user didn't specify an
interface to use, pick a default. */
- status = capture_opts_default_iface_if_necessary(&global_capture_opts,
+ ret = capture_opts_default_iface_if_necessary(&global_capture_opts,
((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);
- if (status != 0) {
- exit(status);
+ if (ret != 0) {
+ goto clean_exit;
}
}
- if (global_commandline_info.list_link_layer_types) {
+ if (caps_queries) {
/* Get the list of link-layer types for the capture devices. */
if_capabilities_t *caps;
guint i;
interface_t device;
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
-
+ int if_caps_queries = caps_queries;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device.selected) {
gchar* auth_str = NULL;
if (caps == NULL) {
cmdarg_err("%s", err_str);
g_free(err_str);
- exit(2);
+ ret = INVALID_CAPABILITY;
+ goto clean_exit;
+ }
+ if (caps->data_link_types == NULL) {
+ cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
+ ret = INVALID_LINK_TYPE;
+ goto clean_exit;
}
- if (caps->data_link_types == NULL) {
- cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
- exit(2);
- }
#ifdef _WIN32
- create_console();
+ create_console();
#endif /* _WIN32 */
#if defined(HAVE_PCAP_CREATE)
- capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
-#else
- capture_opts_print_if_capabilities(caps, device.name, FALSE);
+ if (device.monitor_mode_supported)
+ if_caps_queries |= CAPS_MONITOR_MODE;
#endif
+ capture_opts_print_if_capabilities(caps, device.name, if_caps_queries);
#ifdef _WIN32
- destroy_console();
+ destroy_console();
#endif /* _WIN32 */
- free_if_capabilities(caps);
+ free_if_capabilities(caps);
}
}
- exit(0);
+ ret = EXIT_SUCCESS;
+ goto clean_exit;
}
- capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
- capture_opts_trim_ring_num_files(&global_capture_opts);
+ capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
+ capture_opts_trim_ring_num_files(&global_capture_opts);
#endif /* HAVE_LIBPCAP */
/* Notify all registered modules that have had any of their preferences
}
#endif
- /* disabled protocols as per configuration file */
- if (gdp_path == NULL && dp_path == NULL) {
- set_disabled_protos_list();
- set_enabled_protos_list();
- set_disabled_heur_dissector_list();
- }
-
- if(global_dissect_options.disable_protocol_slist) {
- GSList *proto_disable;
- for (proto_disable = global_dissect_options.disable_protocol_slist; proto_disable != NULL; proto_disable = g_slist_next(proto_disable))
- {
- proto_disable_proto_by_name((char*)proto_disable->data);
- }
- }
-
- if(global_dissect_options.enable_protocol_slist) {
- GSList *proto_enable;
- for (proto_enable = global_dissect_options.enable_protocol_slist; proto_enable != NULL; proto_enable = g_slist_next(proto_enable))
- {
- proto_enable_proto_by_name((char*)proto_enable->data);
- }
- }
-
- if(global_dissect_options.disable_heur_slist) {
- GSList *heur_enable;
- for (heur_enable = global_dissect_options.disable_heur_slist; heur_enable != NULL; heur_enable = g_slist_next(heur_enable))
- {
- proto_enable_heuristic_by_name((char*)heur_enable->data, TRUE);
- }
- }
-
- if(global_dissect_options.disable_heur_slist) {
- GSList *heur_disable;
- for (heur_disable = global_dissect_options.disable_heur_slist; heur_disable != NULL; heur_disable = g_slist_next(heur_disable))
- {
- proto_enable_heuristic_by_name((char*)heur_disable->data, FALSE);
- }
+ /*
+ * Enabled and disabled protocols and heuristic dissectors as per
+ * command-line options.
+ */
+ if (!setup_enabled_and_disabled_protocols()) {
+ ret = INVALID_OPTION;
+ goto clean_exit;
}
build_column_format_array(&cfile.cinfo, global_commandline_info.prefs_p->num_cols, TRUE);
main_unregister_resource();
#endif
- exit(0);
+clean_exit:
+#ifdef HAVE_LIBPCAP
+ capture_opts_cleanup(&global_capture_opts);
+#endif
+ col_cleanup(&cfile.cinfo);
+ free_filter_lists();
+ wtap_cleanup();
+ free_progdirs();
+#ifdef HAVE_PLUGINS
+ plugins_cleanup();
+#endif
+ return ret;
}
#ifdef _WIN32
menubar = main_menu_new(&accel);
#if defined(HAVE_IGE_MAC_INTEGRATION) || defined (HAVE_GTKOSXAPPLICATION)
- /* Mac OS X native menus are created and displayed by main_menu_new() */
+ /* macOS native menus are created and displayed by main_menu_new() */
if(!prefs_p->gui_macosx_style) {
#endif
gtk_window_add_accel_group(GTK_WINDOW(top_level), accel);
/* Change configuration profile */
void change_configuration_profile (const gchar *profile_name)
{
- char *gdp_path, *dp_path;
char *rf_path;
int rf_open_errno;
gchar* err_msg = NULL;
set_profile_name (profile_name);
profile_bar_update ();
- /* Reset current preferences and apply the new */
+ /*
+ * Reset current preferences and enabled/disabled protocols and
+ * heuristic dissectors.
+ */
prefs_reset();
menu_prefs_reset();
+ proto_reenable_all();
- (void) read_configuration_files (&gdp_path, &dp_path);
+ /*
+ * Read the configuration files for the new profile.
+ */
+ (void) read_configuration_files();
if (!recent_read_profile_static(&rf_path, &rf_open_errno)) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
filter_expression_reinit(FILTER_EXPRESSION_REINIT_CREATE);
toolbar_redraw_all();
- /* Enable all protocols and disable from the disabled list */
- proto_enable_all();
- if (gdp_path == NULL && dp_path == NULL) {
- set_disabled_protos_list();
- set_enabled_protos_list();
- set_disabled_heur_dissector_list();
- }
-
/* Reload color filters */
if (!color_filters_reload(&err_msg, color_filter_add_cb)) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);