Make sure that the Capture/Start menue item will always use the
[obnox/wireshark/wip.git] / gtk / main.c
index 4b4142e7369730be22eb60a7e5d4092b9c15e6b8..11f4a4673ed54bfe6d84c8927f11483e547a17ee 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef NEED_STRERROR_H
-#include "wsutil/strerror.h"
-#endif
-
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #else
@@ -1871,24 +1867,24 @@ read_configuration_files(char **gdp_path, char **dp_path)
     if (gpf_open_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open global preferences file\n\"%s\": %s.", gpf_path,
-        strerror(gpf_open_errno));
+        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,
-        strerror(gpf_read_errno));
+        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,
-        strerror(pf_open_errno));
+        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,
-        strerror(pf_read_errno));
+        g_strerror(pf_read_errno));
     }
     g_free(pf_path);
     pf_path = NULL;
@@ -1906,7 +1902,7 @@ read_configuration_files(char **gdp_path, char **dp_path)
   if (cf_path != NULL) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open your capture filter file\n\"%s\": %s.", cf_path,
-        strerror(cf_open_errno));
+        g_strerror(cf_open_errno));
       g_free(cf_path);
   }
 
@@ -1915,7 +1911,7 @@ read_configuration_files(char **gdp_path, char **dp_path)
   if (df_path != NULL) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open your display filter file\n\"%s\": %s.", df_path,
-        strerror(df_open_errno));
+        g_strerror(df_open_errno));
       g_free(df_path);
   }
 
@@ -1926,12 +1922,12 @@ read_configuration_files(char **gdp_path, char **dp_path)
     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, strerror(gdp_open_errno));
+       *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, strerror(gdp_read_errno));
+       *gdp_path, g_strerror(gdp_read_errno));
     }
     g_free(*gdp_path);
     *gdp_path = NULL;
@@ -1940,12 +1936,12 @@ read_configuration_files(char **gdp_path, char **dp_path)
     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,
-        strerror(dp_open_errno));
+        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,
-        strerror(dp_read_errno));
+        g_strerror(dp_read_errno));
     }
     g_free(*dp_path);
     *dp_path = NULL;
@@ -1974,7 +1970,10 @@ check_and_warn_user_startup(gchar *cf_name _U_)
     cur_group = get_cur_groupname();
     priv_warning_dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
       "Running as user \"%s\" and group \"%s\".\n"
-      "This could be dangerous.", cur_user, cur_group);
+      "This could be dangerous.\n\n"
+      "If you're running Wireshark this way in order to perform live capture, "
+      "you may want to be aware that there is a better way documented at\n"
+      "http://wiki.wireshark.org/CaptureSetup/CapturePrivileges", cur_user, cur_group);
     g_free(cur_user);
     g_free(cur_group);
     simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
@@ -2159,7 +2158,7 @@ main(int argc, char *argv[])
   if (rf_path != NULL && rf_open_errno != 0) {
     simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                  "Could not open common recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
+                 rf_path, g_strerror(rf_open_errno));
   }
 
   /* "pre-scan" the command line parameters, if we have "console only"
@@ -2254,7 +2253,7 @@ main(int argc, char *argv[])
   if (rf_path != NULL && rf_open_errno != 0) {
     simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                  "Could not open recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
+                 rf_path, g_strerror(rf_open_errno));
   }
 
   if (recent.gui_fileopen_remembered_dir &&
@@ -2300,6 +2299,10 @@ main(int argc, char *argv[])
   optind = optind_initial;
   opterr = 1;
 
+#ifdef USE_THREADS
+  g_thread_init(NULL);
+#endif
+
   /* Set the current locale according to the program environment.
    * We haven't localized anything, but some GTK widgets are localized
    * (the file selection dialogue, for example).
@@ -2572,6 +2575,10 @@ main(int argc, char *argv[])
           timestamp_set_type(TS_DELTA_DIS);
         else if (strcmp(optarg, "e") == 0)
           timestamp_set_type(TS_EPOCH);
+        else if (strcmp(optarg, "u") == 0)
+          timestamp_set_type(TS_UTC);
+        else if (strcmp(optarg, "ud") == 0)
+          timestamp_set_type(TS_UTC_WITH_DATE);
         else {
           cmdarg_err("Invalid time stamp type \"%s\"", optarg);
           cmdarg_err_cont("It must be \"r\" for relative, \"a\" for absolute,");
@@ -2754,6 +2761,47 @@ main(int argc, char *argv[])
      line that their preferences have changed. */
   prefs_apply_all();
 
+#ifdef HAVE_LIBPCAP
+#ifndef USE_THREADS
+  if ((global_capture_opts.ifaces->len > 1) && start_capture) {
+    cmdarg_err("You specified multiple interfaces for capturing which this version of Wireshark doesn't support.");
+    exit(2);
+  }
+#endif
+  if ((global_capture_opts.ifaces->len == 0) &&
+      (prefs.capture_device != NULL)) {
+    interface_options interface_opts;
+
+    interface_opts.name = g_strdup(get_if_name(prefs.capture_device));
+    interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
+    interface_opts.monitor_mode = prefs_capture_device_monitor_mode(interface_opts.name);
+    interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name);
+    interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
+    interface_opts.snaplen = global_capture_opts.default_options.snaplen;
+    interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
+    interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
+    interface_opts.buffer_size =  global_capture_opts.default_options.buffer_size;
+#endif
+#ifdef HAVE_PCAP_REMOTE
+    interface_opts.src_type = global_capture_opts.default_options.src_type;
+    interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
+    interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
+    interface_opts.auth_type = global_capture_opts.default_options.auth_type;
+    interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
+    interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
+    interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
+    interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
+    interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
+ #endif
+ #ifdef HAVE_PCAP_SETSAMPLING
+    interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
+    interface_opts.sampling_param  = global_capture_opts.default_options.sampling_param;
+ #endif
+    g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
+  }
+#endif
+
   /* disabled protocols as per configuration file */
   if (gdp_path == NULL && dp_path == NULL) {
     set_disabled_protos_list();
@@ -2789,7 +2837,7 @@ main(int argc, char *argv[])
   if (rf_path != NULL && rf_open_errno != 0) {
     simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                  "Could not open recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
+                 rf_path, g_strerror(rf_open_errno));
   }
 
   color_filters_enable(recent.packet_list_colorize);
@@ -2950,17 +2998,16 @@ main(int argc, char *argv[])
            one of MATE's late-registered fields as part of the filter. */
         start_requested_stats();
       }
-    }
-    else {
+    } else {
       show_main_window(FALSE);
       check_and_warn_user_startup(cf_name);
       set_menus_for_capture_in_progress(FALSE);
       set_capture_if_dialog_for_capture_in_progress(FALSE);
     }
 
-    /* if the user didn't supplied a capture filter, use the one to filter out remote connections like SSH */
-    if (!start_capture && !global_capture_opts.cfilter) {
-      global_capture_opts.cfilter = g_strdup(get_conn_cfilter());
+    /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
+    if (!start_capture && !global_capture_opts.default_options.cfilter) {
+      global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
     }
 #else /* HAVE_LIBPCAP */
     show_main_window(FALSE);
@@ -3457,6 +3504,7 @@ main_widgets_show_or_hide(void)
     if (!have_capture_file) {
         if(welcome_pane) {
             gtk_widget_show(welcome_pane);
+            select_ifaces();
         }
     } else {
         gtk_widget_hide(welcome_pane);
@@ -3638,11 +3686,11 @@ prefs_to_capture_opts(void)
 #ifdef HAVE_LIBPCAP
   /* Set promiscuous mode from the preferences setting. */
   /* the same applies to other preferences settings as well. */
-    global_capture_opts.promisc_mode   = prefs.capture_prom_mode;
-    global_capture_opts.use_pcapng     = prefs.capture_pcap_ng;
-    global_capture_opts.show_info      = prefs.capture_show_info;
-    global_capture_opts.real_time_mode = prefs.capture_real_time;
-    auto_scroll_live                   = prefs.capture_auto_scroll;
+    global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
+    global_capture_opts.use_pcapng                   = prefs.capture_pcap_ng;
+    global_capture_opts.show_info                    = prefs.capture_show_info;
+    global_capture_opts.real_time_mode               = prefs.capture_real_time;
+    auto_scroll_live                                 = prefs.capture_auto_scroll;
 #endif /* HAVE_LIBPCAP */
 
   /* Set the name resolution code's flags from the preferences. */
@@ -3656,7 +3704,7 @@ static void copy_global_profile (const gchar *profile_name)
    if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) {
      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                   "Can't create directory\n\"%s\":\n%s.",
-                  pf_dir_path, strerror(errno));
+                  pf_dir_path, g_strerror(errno));
 
      g_free(pf_dir_path);
    }
@@ -3665,7 +3713,7 @@ static void copy_global_profile (const gchar *profile_name)
                                 &pf_dir_path, &pf_dir_path2) == -1) {
      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                   "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.",
-                  pf_filename, pf_dir_path2, pf_dir_path, strerror(errno));
+                  pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno));
 
      g_free(pf_filename);
      g_free(pf_dir_path);
@@ -3718,7 +3766,7 @@ void change_configuration_profile (const gchar *profile_name)
    if (rf_path != NULL && rf_open_errno != 0) {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                  "Could not open common recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
+                 rf_path, g_strerror(rf_open_errno));
    }
    if (recent.gui_fileopen_remembered_dir &&
        test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {