ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] Patch for stopping traces on SIGINT

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

From: Neil Horman <nhorman@xxxxxxxxxxxxx>
Date: Thu, 11 Sep 2003 09:40:12 -0400
Hello all-
I've created a patch to allow a user to stop a trace with a SIGINT (#18 on the wish list). Its not implemented to actually use SIGINT since gtk registers a handler for that signal that I didn't really want to override, but instead it registers signal handlers in gtk for keyboard events and listens for ASCII 0x03 to end the tracing, which from a look and feel standpoint, is the same thing, and I think a generally better way to do this. Anywho, the patch is attached, submitted for the maintainers approval :)

Neil
Index: capture.c
===================================================================
RCS file: /cvsroot/ethereal/capture.c,v
retrieving revision 1.208
diff -u -r1.208 capture.c
--- capture.c	23 Jul 2003 05:01:15 -0000	1.208
+++ capture.c	11 Sep 2003 13:35:39 -0000
@@ -247,6 +247,32 @@
 int child_process;
 #endif
 
+
+/*
+ * This needs to be static, so that the SIGUSR1 handler can clear the "go"
+ * flag.
+ */
+static loop_data   ld;
+
+/*
+ *This is the ASCII value of a ctrl-c
+ */
+#define CTRL_C 0x03
+static void key_press_win(GtkWidget *widget,
+	 	   GdkEventKey *key,	
+                   gpointer   callback_data )
+{
+   /*
+    *check to see if the key press event
+    *is a ctrl-c.  If it is, end the capture
+    */
+   if((char)*(key->string) == CTRL_C)
+   {
+      ld.go = FALSE; 
+   }
+}
+
+
 /* Add a string pointer to a NULL-terminated array of string pointers. */
 static char **
 add_arg(char **args, int *argc, char *arg)
@@ -1342,12 +1368,6 @@
 }
 #endif
 
-/*
- * This needs to be static, so that the SIGUSR1 handler can clear the "go"
- * flag.
- */
-static loop_data   ld;
-
 /* Do the low-level work of a capture.
    Returns TRUE if it succeeds, FALSE otherwise. */
 int
@@ -1696,6 +1716,8 @@
   main_vb = gtk_vbox_new(FALSE, 1);
   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
   gtk_container_add(GTK_CONTAINER(cap_w), main_vb);
+  gtk_signal_connect(GTK_OBJECT(cap_w), "key_press_event", 
+			(GtkSignalFunc) key_press_win, NULL );
   gtk_widget_show(main_vb);
 
   counts_fr = gtk_frame_new("Captured Frames");
Index: gtk/main.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/main.c,v
retrieving revision 1.310
diff -u -r1.310 main.c
--- gtk/main.c	10 Sep 2003 05:35:26 -0000	1.310
+++ gtk/main.c	11 Sep 2003 13:35:40 -0000
@@ -1483,6 +1483,24 @@
 
 }
 
+/*
+ *This is the ASCII value of a ctrl-c
+ */
+#define CTRL_C 0x03
+static void key_press_handler(GtkWidget *widget,
+                   GdkEventKey *key,
+                   gpointer   callback_data )
+{
+   /*
+    *check to see if the key press event
+    *is a ctrl-c.  If it is, end the capture
+    */
+   if((char)*(key->string) == CTRL_C)
+   {
+      capture_stop(); 
+   }
+}
+
 /* And now our feature presentation... [ fade to music ] */
 int
 main(int argc, char *argv[])
@@ -2663,6 +2681,8 @@
 
     /* Main window */
     top_level = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_signal_connect(GTK_OBJECT(top_level), "key_press_event",
+                        (GtkSignalFunc) key_press_handler, NULL );
     gtk_widget_set_name(top_level, "main window");
     SIGNAL_CONNECT(top_level, "delete_event", main_window_delete_event_cb,
                    NULL);