aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--gtk/menu.c2
-rw-r--r--gtk/proto_draw.c41
-rw-r--r--gtk/proto_draw.h7
-rw-r--r--gtk/ui_util.c21
-rw-r--r--gtk/ui_util.h6
6 files changed, 78 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 88f1d12a71..65193985cc 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2268,6 +2268,7 @@ Ming Zhang <mingz [AT] ele.uri.edu>
Neil Piercy <Neil.Piercy [AT] ipaccess.com>
Rémi Denis-Courmont <courmisch [AT] via.ecp.fr>
Francisco Alcoba <francisco.alcoba [AT] ericsson.com>
+Thomas Palmer <tpalmer [AT] elmore.rr.com>
Alain Magloire <alainm[AT]rcsm.ece.mcgill.ca> was kind enough to
give his permission to use his version of snprintf.c.
diff --git a/gtk/menu.c b/gtk/menu.c
index b9a3f39c14..7ceb475741 100644
--- a/gtk/menu.c
+++ b/gtk/menu.c
@@ -473,6 +473,8 @@ static GtkItemFactoryEntry hexdump_menu_items[] =
ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
0, NULL, NULL),
ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Copy Packet Bytes into Clipboard", NULL, copy_hex_cb,
0, NULL, NULL)
};
diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c
index a2eb20fbea..f824483c83 100644
--- a/gtk/proto_draw.c
+++ b/gtk/proto_draw.c
@@ -801,6 +801,47 @@ savehex_dlg_destroy_cb(void)
savehex_dlg = NULL;
}
+extern void
+copy_hex_cb(GtkWidget * w _U_, gpointer data _U_)
+{
+ GtkWidget *bv;
+ int len;
+ int i=0;
+ const guint8 *data_p = NULL;
+ GString *ASCII_representation = g_string_new("");
+ GString *byte_str = g_string_new("");
+
+ bv = get_notebook_bv_ptr(byte_nb_ptr);
+ if (bv == NULL) {
+ /* shouldn't happen */
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not find the corresponding text window!");
+ return;
+ }
+
+ data_p = get_byte_view_data_and_length(GTK_WIDGET(bv), &len);
+
+ g_string_append_printf(byte_str,"%04x ",i); /* Offset 0000 */
+ for (i=0; i<len; i++){
+ g_string_append_printf(ASCII_representation,"%c",isprint(*data_p) ? *data_p : '.');
+ g_string_append_printf(byte_str," %02x",*data_p++);
+ if ((i+1)%16==0 && i!=0){
+ g_string_append_printf(byte_str," %s\n%04x ",ASCII_representation->str,i+1);
+ g_string_assign (ASCII_representation,"");
+ }
+ }
+
+ if(ASCII_representation->len){
+ for (i=ASCII_representation->len; i<16; i++){
+ g_string_append_printf(byte_str," ");
+ }
+ g_string_append_printf(byte_str," %s\n",ASCII_representation->str);
+ }
+ /* Now that we have the byte data, copy it into the default clipboard */
+ copy_to_clipboard(byte_str);
+ g_string_free(byte_str, TRUE); /* Free the memory */
+ g_string_free(ASCII_representation, TRUE); /* Free the memory */
+}
+
/* save the current highlighted hex data */
static void
savehex_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_)
diff --git a/gtk/proto_draw.h b/gtk/proto_draw.h
index 6f9a95f3d0..740161df58 100644
--- a/gtk/proto_draw.h
+++ b/gtk/proto_draw.h
@@ -96,6 +96,13 @@ extern gboolean byte_view_select(GtkWidget *widget, GdkEventButton *event);
*/
extern void savehex_cb(GtkWidget * w, gpointer data);
+/** Callback for "Copy packet bytes to clipboard" operation.
+ *
+ * @param w unused
+ * @param data unused
+ */
+extern void copy_hex_cb(GtkWidget * w, gpointer data);
+
#if GTK_MAJOR_VERSION < 2
/** Redraw a given byte view window.
*
diff --git a/gtk/ui_util.c b/gtk/ui_util.c
index 8401f7042c..2e50b767ac 100644
--- a/gtk/ui_util.c
+++ b/gtk/ui_util.c
@@ -988,3 +988,24 @@ simple_list_new(gint cols, gchar **titles) {
return plugins_list;
}
+extern void
+copy_to_clipboard(GString *str)
+{
+#if (GTK_MAJOR_VERSION >= 2)
+ GtkClipboard *cb;
+
+ cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
+ gtk_clipboard_set_text(cb, str->str, -1); /* Copy the byte data into the clipboard */
+#else
+ GtkWidget *window;
+ GtkWidget *text;
+
+ window = window_new (GTK_WINDOW_TOPLEVEL,"");
+ text = gtk_text_new (NULL, NULL); /* Create the GtkText widget */
+ gtk_container_add (GTK_CONTAINER (window), text); /* Avoid a GTK assertion */
+ gtk_widget_realize (text); /* Realizing a widget creates a window for it, ready for us to insert some text */
+ gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str->str, -1);
+ gtk_editable_select_region((GtkEditable *)text, 0, -1); /* Select ALL text */
+ gtk_editable_copy_clipboard((GtkEditable *)text); /* Copy the byte data into the clipboard */
+#endif
+}
diff --git a/gtk/ui_util.h b/gtk/ui_util.h
index 9ac69a2e89..ca7f3c024c 100644
--- a/gtk/ui_util.h
+++ b/gtk/ui_util.h
@@ -291,4 +291,10 @@ extern GtkWidget *xpm_to_widget(const char ** xpm);
*/
extern GtkWidget *xpm_to_widget_from_parent(GtkWidget *parent, const char ** xpm);
+/** Copy a GString to the clipboard.
+ *
+ * @param str GString that is to be copied to the clipboard.
+ */
+extern void copy_to_clipboard(GString *str);
+
#endif /* __GTKGUIUI_UTIL_H__ */