Ethereal-dev: [Ethereal-dev] patch: add Capture/Restart

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Santeri Paavolainen <santtu@xxxxxxx>
Date: Wed, 10 Apr 2002 13:31:51 +0300 (EEST)
This patch adds (for non-win32 platforms) a new item to the Capture menu,
"Restart." It is effectively equivalent to doing Stop and then Start. It
is just a feature I've found missing when doing testing -- you've run a
test suite, and want to restart with otherwise the same settings but clear
out the old data from the capture.

BTW, it'd probably be handy to add an accelerator to this function,
however since Ctrl-R was already taken, and although Ctrl-A ("A"gain)  
would be free I think the latter should be bound to "Mark all frames"  
instead (as is common then Ctrl-A would be "select all").

-- 
santtu@xxxxxx                    I have become death, destroyer of the worlds.
diff -rwc ethereal-0.9.3-orig/capture.c ethereal-0.9.3/capture.c
*** ethereal-0.9.3-orig/capture.c	Mon Feb 25 00:38:33 2002
--- ethereal-0.9.3/capture.c	Wed Apr 10 13:22:39 2002
***************
*** 238,243 ****
--- 238,246 ----
  int child_process;
  #endif
  
+ static char *capfile_name_orig = NULL;
+ static gboolean restart_capture_after_exit = FALSE;
+ 
  /* Add a string pointer to a NULL-terminated array of string pointers. */
  static char **
  add_arg(char **args, int *argc, char *arg)
***************
*** 293,298 ****
--- 296,309 ----
    gboolean stats_known;
    struct pcap_stat stats;
  
+   if (capfile_name_orig != NULL)
+     g_free(capfile_name_orig);
+ 
+   if (capfile_name != NULL)
+     capfile_name_orig = g_strdup(capfile_name);
+   else
+     capfile_name_orig = NULL;
+ 
    if (capfile_name != NULL) {
      if (capture_opts.ringbuffer_on) {
        /* ringbuffer is enabled */
***************
*** 773,778 ****
--- 784,794 ----
      g_free(cf->save_file);
      cf->save_file = NULL;
  
+     if (restart_capture_after_exit)
+       do_capture(capfile_name_orig);
+ 
+     restart_capture_after_exit = FALSE;
+ 
      return;
    }
  
***************
*** 1992,1997 ****
--- 2008,2026 ----
  }
  
  void
+ capture_restart(void)
+ {
+ #ifndef _WIN32
+   if (fork_child == -1)
+     do_capture(capfile_name_orig);
+   else {
+     kill(fork_child, SIGUSR1);
+     restart_capture_after_exit = TRUE;
+   }
+ #endif
+ }
+ 
+ void
  kill_capture_child(void)
  {
    /*
diff -rwc ethereal-0.9.3-orig/capture.h ethereal-0.9.3/capture.h
*** ethereal-0.9.3-orig/capture.h	Mon Feb 25 00:38:33 2002
--- ethereal-0.9.3/capture.h	Wed Apr 10 12:59:48 2002
***************
*** 67,72 ****
--- 67,75 ----
  /* Stop a capture from a menu item. */
  void   capture_stop(void);
  
+ /* Restart a capture from a menu item. */
+ void    capture_restart(void);
+ 
  /* Terminate the capture child cleanly when exiting. */
  void   kill_capture_child(void);
  
diff -rwc ethereal-0.9.3-orig/gtk/capture_dlg.c ethereal-0.9.3/gtk/capture_dlg.c
*** ethereal-0.9.3-orig/gtk/capture_dlg.c	Fri Mar 15 04:44:49 2002
--- ethereal-0.9.3/gtk/capture_dlg.c	Wed Apr 10 12:59:18 2002
***************
*** 118,123 ****
--- 118,129 ----
      capture_stop();
  }
  
+ void
+ capture_restart_cb(GtkWidget *w _U_, gpointer d _U_)
+ {
+     capture_restart();
+ }
+ 
  /*
   * Keep a static pointer to the current "Capture Options" window, if
   * any, so that if somebody tries to do "Capture:Start" while there's
diff -rwc ethereal-0.9.3-orig/gtk/capture_dlg.h ethereal-0.9.3/gtk/capture_dlg.h
*** ethereal-0.9.3-orig/gtk/capture_dlg.h	Sat Oct 14 07:14:05 2000
--- ethereal-0.9.3/gtk/capture_dlg.h	Wed Apr 10 12:59:01 2002
***************
*** 28,32 ****
--- 28,33 ----
  
  void   capture_prep_cb(GtkWidget *, gpointer);
  void   capture_stop_cb(GtkWidget *, gpointer);
+ void   capture_restart_cb(GtkWidget *, gpointer);
  
  #endif /* capture.h */
diff -rwc ethereal-0.9.3-orig/gtk/menu.c ethereal-0.9.3/gtk/menu.c
*** ethereal-0.9.3-orig/gtk/menu.c	Wed Jan 30 04:57:07 2002
--- ethereal-0.9.3/gtk/menu.c	Wed Apr 10 13:04:12 2002
***************
*** 137,142 ****
--- 137,143 ----
     */
  #ifndef _WIN32
    {"/Capture/S_top", "<control>E", GTK_MENU_FUNC(capture_stop_cb), 0, NULL},
+   {"/Capture/_Restart", NULL, GTK_MENU_FUNC(capture_restart_cb), 0, NULL},
  #endif /* _WIN32 */
  #endif /* HAVE_LIBPCAP */
    {"/_Display", NULL, NULL, 0, "<Branch>" },