Add a few more menu items.
[obnox/wireshark/wip.git] / capture.c
index 5e808f95ebef95295b62919efc8b7b682fd74575..22bab8dd94b53a246ae6843af4b578e1b703c499 100644 (file)
--- a/capture.c
+++ b/capture.c
@@ -133,19 +133,44 @@ gboolean
 capture_start(capture_options *capture_opts)
 {
   gboolean ret;
+  guint i;
   GString *source = g_string_new("");
 
+  if (capture_opts->state != CAPTURE_STOPPED)
+    return FALSE;
+  capture_opts->state = CAPTURE_PREPARING;
+
   /* close the currently loaded capture file */
   cf_close(capture_opts->cf);
 
-  g_assert(capture_opts->state == CAPTURE_STOPPED);
-  capture_opts->state = CAPTURE_PREPARING;
-
   g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ...");
 
-  g_string_printf(source, "%s", get_iface_description(capture_opts));
-  if(capture_opts->cfilter && capture_opts->cfilter[0]) {
-    g_string_append_printf(source, " (%s)", capture_opts->cfilter);
+#ifdef _WIN32
+  if (capture_opts->ifaces->len < 2) {
+#else
+  if (capture_opts->ifaces->len < 4) {
+#endif
+    for (i = 0; i < capture_opts->ifaces->len; i++) {
+      interface_options interface_opts;
+
+      interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
+      if (i > 0) {
+          if (capture_opts->ifaces->len > 2) {
+              g_string_append_printf(source, ",");
+          }
+          g_string_append_printf(source, " ");
+          if (i == capture_opts->ifaces->len - 1) {
+              g_string_append_printf(source, "and ");
+          }
+      }
+      g_string_append_printf(source, "%s", get_iface_description_for_interface(capture_opts, i));
+      if ((interface_opts.cfilter != NULL) &&
+          (strlen(interface_opts.cfilter) > 0)) {
+        g_string_append_printf(source, " (%s)", interface_opts.cfilter);
+      }
+    }
+  } else {
+    g_string_append_printf(source, "%u interfaces", capture_opts->ifaces->len);
   }
   cf_set_tempfile_source(capture_opts->cf, source->str);
   g_string_free(source, TRUE);
@@ -399,6 +424,7 @@ capture_input_new_packets(capture_options *capture_opts, int to_read)
     /* increase the capture file packet counter by the number of incoming packets */
     cf_set_packet_count(capture_opts->cf,
         cf_get_packet_count(capture_opts->cf) + to_read);
+    cf_fake_continue_tail(capture_opts->cf);
 
     capture_callback_invoke(capture_cb_capture_fixed_continue, capture_opts);
   }
@@ -467,20 +493,27 @@ capture_input_error_message(capture_options *capture_opts, char *error_msg, char
    capture filter when starting/running the capture.
  */
 void
-capture_input_cfilter_error_message(capture_options *capture_opts, char *error_message)
+capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message)
 {
-  dfilter_t   *rfcode = NULL;
-  gchar *safe_cfilter = simple_dialog_format_message(capture_opts->cfilter);
-  gchar *safe_cfilter_error_msg = simple_dialog_format_message(error_message);
+  dfilter_t *rfcode = NULL;
+  gchar *safe_cfilter;
+  gchar *safe_descr;
+  gchar *safe_cfilter_error_msg;
+  interface_options interface_opts;
 
   g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture filter error message from child: \"%s\"", error_message);
 
   g_assert(capture_opts->state == CAPTURE_PREPARING || capture_opts->state == CAPTURE_RUNNING);
+  g_assert(i < capture_opts->ifaces->len);
 
+  interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
+  safe_cfilter = simple_dialog_format_message(interface_opts.cfilter);
+  safe_descr = simple_dialog_format_message(interface_opts.descr);
+  safe_cfilter_error_msg = simple_dialog_format_message(error_message);
   /* Did the user try a display filter? */
-  if (dfilter_compile(capture_opts->cfilter, &rfcode) && rfcode != NULL) {
+  if (dfilter_compile(interface_opts.cfilter, &rfcode) && rfcode != NULL) {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-      "%sInvalid capture filter: \"%s\"!%s\n"
+      "%sInvalid capture filter \"%s\" for interface %s!%s\n"
       "\n"
       "That string looks like a valid display filter; however, it isn't a valid\n"
       "capture filter (%s).\n"
@@ -489,19 +522,20 @@ capture_input_cfilter_error_message(capture_options *capture_opts, char *error_m
       "so you can't use most display filter expressions as capture filters.\n"
       "\n"
       "See the User's Guide for a description of the capture filter syntax.",
-      simple_dialog_primary_start(), safe_cfilter,
+      simple_dialog_primary_start(), safe_cfilter, safe_descr,
       simple_dialog_primary_end(), safe_cfilter_error_msg);
       dfilter_free(rfcode);
   } else {
     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-      "%sInvalid capture filter: \"%s\"!%s\n"
+      "%sInvalid capture filter \"%s\" for interface %s!%s\n"
       "\n"
       "That string isn't a valid capture filter (%s).\n"
       "See the User's Guide for a description of the capture filter syntax.",
-      simple_dialog_primary_start(), safe_cfilter,
+      simple_dialog_primary_start(), safe_cfilter, safe_descr,
       simple_dialog_primary_end(), safe_cfilter_error_msg);
   }
   g_free(safe_cfilter_error_msg);
+  g_free(safe_descr);
   g_free(safe_cfilter);
 
   /* the capture child will close the sync_pipe if required, nothing to do for now */
@@ -532,16 +566,16 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
     }
 
     if(capture_opts->real_time_mode) {
-       cf_read_status_t status;
+        cf_read_status_t status;
 
         /* Read what remains of the capture file. */
         status = cf_finish_tail(capture_opts->cf, &err);
 
         /* XXX: If -Q (quit-after-cap) then cf->count clr'd below so save it first */
-       packet_count_save = cf_get_packet_count(capture_opts->cf);
+        packet_count_save = cf_get_packet_count(capture_opts->cf);
         /* Tell the GUI we are not doing a capture any more.
-                  Must be done after the cf_finish_tail(), so file lengths are 
-                   correctly displayed */
+           Must be done after the cf_finish_tail(), so file lengths are 
+           correctly displayed */
         capture_callback_invoke(capture_cb_capture_update_finished, capture_opts);
 
         /* Finish the capture. */
@@ -579,6 +613,7 @@ capture_input_closed(capture_options *capture_opts, gchar *msg)
           /* Exit by leaving the main loop, so that any quit functions
              we registered get called. */
           main_window_quit();
+         break;
         }
 
     } else {
@@ -640,12 +675,12 @@ capture_stat_start(GList *if_list) {
      *
      * This means that
      *
-     * 1) this might fail if you run out of BPF devices
+     *    1) this might fail if you run out of BPF devices
      *
      * and
      *
-     * 2) opening every interface could leave too few BPF devices
-     *    for *other* programs.
+     *    2) opening every interface could leave too few BPF devices
+     *       for *other* programs.
      *
      * It also means the system could end up getting a lot of traffic
      * that it has to pass through the networking stack and capture
@@ -661,9 +696,11 @@ capture_stat_start(GList *if_list) {
         /* Initialize the cache */
         for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
             if_info = if_entry->data;
-            sc_item = g_malloc0(sizeof(if_stat_cache_item_t));
-            sc_item->name = g_strdup(if_info->name);
-            sc->cache_list = g_list_append(sc->cache_list, sc_item);
+            if (if_info) {
+                sc_item = g_malloc0(sizeof(if_stat_cache_item_t));
+                sc_item->name = g_strdup(if_info->name);
+                sc->cache_list = g_list_append(sc->cache_list, sc_item);
+            }
         }
     }
     return sc;
@@ -732,7 +769,7 @@ capture_stat_stop(if_stat_cache_t *sc) {
 
     ret = sync_interface_stats_close(&sc->stat_fd, &sc->fork_child, &msg);
     if (ret == -1) {
-       /* XXX - report failure? */
+        /* XXX - report failure? */
         g_free(msg);
     }