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] rtp_analysis, rtp_streams_dlg: Decimal separator fix, CSV

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

From: "Lars Ruoff" <lars.ruoff@xxxxxxx>
Date: Sun, 13 Mar 2005 16:44:02 +0100
Please apply the following patches:

rtp_streams_dlg:
- Applied the workaround for fixing the problem with locale dependent
decimal separator (cf.
http://www.ethereal.com/lists/ethereal-dev/200503/msg00276.html)
- Added a Copy button that copies all data from the CList to clipboard as
CSV.

rtp_analysis:
- Applied the workaround for fixing the problem with locale dependent
decimal separator (cf.
http://www.ethereal.com/lists/ethereal-dev/200503/msg00276.html)

Attached is relevant output of 'svn diff'.

regards,
Lars Ruoff
Index: ethereal/gtk/rtp_stream_dlg.c
===================================================================
--- ethereal/gtk/rtp_stream_dlg.c	(Revision 13743)
+++ ethereal/gtk/rtp_stream_dlg.c	(Arbeitskopie)
@@ -50,6 +50,7 @@
 #include <epan/address.h>
 
 #include <string.h>
+#include <locale.h>
 #include <epan/addr_resolv.h>
 
 
@@ -74,6 +75,7 @@
 static guint32 streams_nb = 0;     /* number of displayed streams */
 
 #define NUM_COLS 12
+static const gchar *titles[NUM_COLS] =  {"Src IP addr", "Src port",  "Dest IP addr", "Dest port", "SSRC", "Payload", "Packets", "Lost", "Max Delta (ms)", "Max Jitter (ms)", "Mean Jitter (ms)", "Pb?"};
 
 /****************************************************************************/
 /* append a line to clist */
@@ -86,7 +88,14 @@
 	gint32 lost;
 	double perc;
 	int i;
+	char *savelocale;
 
+	/* save the current locale */
+	savelocale = setlocale(LC_NUMERIC, NULL);
+	/* switch to "C" locale to avoid problems with localized decimal separators
+		in g_snprintf("%f") functions */
+	setlocale(LC_NUMERIC, "C");
+
 	data[0] = g_strdup(get_addr_name(&(strinfo->src_addr)));
 	data[1] = g_strdup_printf("%u", strinfo->src_port);
 	data[2] = g_strdup(get_addr_name(&(strinfo->dest_addr)));
@@ -113,6 +122,9 @@
 	else
 		data[11] = g_strdup("");
 
+	/* restore previous locale setting */
+	setlocale(LC_NUMERIC, savelocale);
+
 	added_row = gtk_clist_append(GTK_CLIST(clist), data);
 	for (i = 0; i < NUM_COLS; i++)
 		g_free(data[i]);
@@ -408,7 +420,43 @@
 
 
 /****************************************************************************/
+#if (GTK_MAJOR_VERSION >= 2)
 static void
+rtpstream_on_copy_as_csv(GtkWindow *win _U_, gpointer data)
+{
+	int             i,j;
+	gchar           *table_entry;
+	gchar           *CSV_str;
+	GtkClipboard    *cb;
+
+	CSV_str = g_new(gchar,(240*(GTK_CLIST(clist)->rows+1)));
+	strcpy(CSV_str,"");
+	/* Add the column headers to the CSV data */
+	for (j=0; j<NUM_COLS; j++) {
+		strcat(CSV_str, titles[j]);
+		strcat(CSV_str, ",");
+	}
+	strcat(CSV_str,"\n");
+
+	/* Add the column values to the CSV data */
+	for (i=0; i<GTK_CLIST(clist)->rows; i++) {
+		for (j=0; j<NUM_COLS; j++) {
+			gtk_clist_get_text(GTK_CLIST(clist),i,j,&table_entry);
+			strcat(CSV_str,table_entry);
+			strcat(CSV_str,",");
+		} 
+		strcat(CSV_str,"\n");
+	}
+
+	/* Now that we have the CSV data, copy it into the default clipboard */
+	cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+	gtk_clipboard_set_text(cb, CSV_str, -1);
+	g_free(CSV_str);
+} 
+#endif
+
+/****************************************************************************/
+static void
 rtpstream_on_analyse                   (GtkButton       *button _U_,
                                         gpointer         user_data _U_)
 { 
@@ -605,9 +653,11 @@
 	GtkWidget *bt_filter;
 	GtkWidget *bt_analyze;
 	GtkWidget *bt_close;
+#if (GTK_MAJOR_VERSION >= 2)
+    GtkWidget *bt_copy;
+#endif           
     GtkTooltips *tooltips = gtk_tooltips_new();
 
-	gchar *titles[NUM_COLS] =  {"Src IP addr", "Src port",  "Dest IP addr", "Dest port", "SSRC", "Payload", "Packets", "Lost", "Max Delta (ms)", "Max Jitter (ms)", "Mean Jitter (ms)", "Pb?"};
 	column_arrows *col_arrows;
 	GtkWidget *column_lb;
 	int i;
@@ -721,6 +771,15 @@
 	gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_filter);
     gtk_tooltips_set_tip (tooltips, bt_filter, "Prepare a display filter of the selected stream(s)", NULL);
 
+#if (GTK_MAJOR_VERSION >= 2)
+    /* XXX - maybe we want to have a "Copy as CSV" stock button here? */
+    /*bt_copy = gtk_button_new_with_label ("Copy content to clipboard as CSV");*/
+    bt_copy = BUTTON_NEW_FROM_STOCK(GTK_STOCK_COPY);
+	gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_copy);
+    gtk_tooltips_set_tip(tooltips, bt_copy, 
+        "Copy all statistical values of this page to the clipboard in CSV (Comma Seperated Values) format.", NULL);
+#endif                 
+
 	bt_analyze = gtk_button_new_with_label ("Analyze");
 	gtk_container_add (GTK_CONTAINER (hbuttonbox), bt_analyze);
     gtk_tooltips_set_tip (tooltips, bt_analyze, "Open an analyze window of the selected stream(s)", NULL);
@@ -739,6 +798,7 @@
 	SIGNAL_CONNECT(bt_save, "clicked", rtpstream_on_save, NULL);
 	SIGNAL_CONNECT(bt_mark, "clicked", rtpstream_on_mark, NULL);
 	SIGNAL_CONNECT(bt_filter, "clicked", rtpstream_on_filter, NULL);
+    SIGNAL_CONNECT(bt_copy, "clicked", rtpstream_on_copy_as_csv, NULL);
 	SIGNAL_CONNECT(bt_analyze, "clicked", rtpstream_on_analyse, NULL);
 
 	window_set_cancel_button(rtpstream_dlg_w, bt_close, window_cancel_button_cb);
Index: ethereal/gtk/rtp_analysis.c
===================================================================
--- ethereal/gtk/rtp_analysis.c	(Revision 13743)
+++ ethereal/gtk/rtp_analysis.c	(Arbeitskopie)
@@ -79,6 +79,7 @@
 #include <math.h>
 #include <fcntl.h>
 #include <string.h>
+#include <locale.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -2995,6 +2996,7 @@
 	guint added_row;
 	gchar *data[9];
 	gchar field[9][32];
+	char *savelocale;
 
 	data[0]=&field[0][0];
 	data[1]=&field[1][0];
@@ -3006,6 +3008,11 @@
 	data[7]=&field[7][0];
 	data[8]=&field[8][0];
 
+	/* save the current locale */
+	savelocale = setlocale(LC_NUMERIC, NULL);
+	/* switch to "C" locale to avoid problems with localized decimal separators
+		in g_snprintf("%f") functions */
+	setlocale(LC_NUMERIC, "C");
 	g_snprintf(field[0], 20, "%u", number);
 	g_snprintf(field[1], 20, "%u", seq_num);
 	g_snprintf(field[2], 20, "%.2f", delta);
@@ -3015,6 +3022,9 @@
 	g_snprintf(field[6], 40, "%s", status);
 	g_snprintf(field[7], 32, "%s", timeStr);
 	g_snprintf(field[8], 20, "%u", pkt_len);
+	/* restore previous locale setting */
+	setlocale(LC_NUMERIC, savelocale);
+
 	added_row = gtk_clist_append(GTK_CLIST(clist), data);
 	gtk_clist_set_row_data(GTK_CLIST(clist), added_row, GUINT_TO_POINTER(number));
 	gtk_clist_set_background(GTK_CLIST(clist), added_row, color);