aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorMartin Mathieson <martin.r.mathieson@googlemail.com>2014-06-04 23:35:38 +0100
committerMartin Mathieson <martin.r.mathieson@googlemail.com>2014-06-05 18:00:49 +0000
commit29222aba7c110c766f752800c2f2a4a4b5b51271 (patch)
tree705f6997bc162c5a631b3bd5eb6f9e1e4c96c59b /ui
parent6ac68b1fd5e549723ac65f1bad1e1a3c44716149 (diff)
Add Object (file) export for files transferred over TFTP.
Updated following review comments. Change-Id: I56e70d8f8e332d2aea604ceec16c980ad890fa58 Reviewed-on: https://code.wireshark.org/review/1885 Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/Makefile.common1
-rw-r--r--ui/export_object.h3
-rw-r--r--ui/export_object_tftp.c139
-rw-r--r--ui/gtk/export_object_dlg.c7
-rw-r--r--ui/gtk/export_object_dlg.h1
-rw-r--r--ui/gtk/main_menubar.c3
6 files changed, 153 insertions, 1 deletions
diff --git a/ui/Makefile.common b/ui/Makefile.common
index a8a5531804..3e1f209a33 100644
--- a/ui/Makefile.common
+++ b/ui/Makefile.common
@@ -48,6 +48,7 @@ WIRESHARK_UI_SRC = \
export_object_dicom.c \
export_object_http.c \
export_object_smb.c \
+ export_object_tftp.c \
follow.c \
iface_lists.c \
io_graph_item.c \
diff --git a/ui/export_object.h b/ui/export_object.h
index 1767773124..44120a2573 100644
--- a/ui/export_object.h
+++ b/ui/export_object.h
@@ -60,8 +60,11 @@ gboolean eo_http_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _
const void *data);
gboolean eo_smb_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_,
const void *data);
+gboolean eo_tftp_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_,
+ const void *data);
void eo_smb_cleanup(void);
+void eo_tftp_cleanup(void);
#ifdef __cplusplus
diff --git a/ui/export_object_tftp.c b/ui/export_object_tftp.c
new file mode 100644
index 0000000000..34055e0d22
--- /dev/null
+++ b/ui/export_object_tftp.c
@@ -0,0 +1,139 @@
+/* export_object_tftp.c
+ * Routines for aving objects (files) found in TFTP sessions
+ * See also: export_object.c / export_object.h for common code
+ * Initial file, prototypes and general structure initially copied
+ * from export_object_smb.c
+ *
+ * Martin Mathieson
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include <epan/packet.h>
+#include <epan/dissectors/packet-tftp.h>
+#include <epan/tap.h>
+
+#include "export_object.h"
+
+/* A list of block list entries to delete from cleanup callback when window is closed. */
+typedef struct eo_info_dynamic_t {
+ gchar *filename;
+ GSList *block_list;
+} eo_info_dynamic_t;
+static GSList *s_dynamic_info_list = NULL;
+
+/* Tap function */
+gboolean
+eo_tftp_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_,
+ const void *data)
+{
+ export_object_list_t *object_list = (export_object_list_t *)tapdata;
+ const tftp_eo_t *eo_info = (const tftp_eo_t *)data;
+ export_object_entry_t *entry;
+
+ GSList *block_iterator;
+ guint payload_data_offset = 0;
+ eo_info_dynamic_t *dynamic_info;
+
+ /* These values will be freed when the Export Object window is closed. */
+ entry = (export_object_entry_t*)g_malloc(sizeof(export_object_entry_t));
+
+ /* Remember which frame had the last block of the file */
+ entry->pkt_num = pinfo->fd->num;
+
+ /* Copy filename */
+ entry->filename = g_strdup(g_path_get_basename(eo_info->filename));
+
+ /* Iterate over list of blocks and concatenate into contiguous memory */
+ entry->payload_len = eo_info->payload_len;
+ entry->payload_data = (guint8 *)g_try_malloc((gsize)entry->payload_len);
+ for (block_iterator = eo_info->block_list; block_iterator; block_iterator = block_iterator->next) {
+ file_block_t *block = (file_block_t*)block_iterator->data;
+ memcpy(entry->payload_data + payload_data_offset,
+ block->data,
+ block->length);
+ payload_data_offset += block->length;
+ }
+
+ /* These 2 fields not used */
+ entry->hostname = NULL;
+ entry->content_type = NULL;
+
+ /* Add to list of entries to be cleaned up. eo_info is only packet scope, so
+ need to make list only of block list now */
+ dynamic_info = (eo_info_dynamic_t*)g_malloc(sizeof(eo_info_dynamic_t));
+ dynamic_info->filename = eo_info->filename;
+ dynamic_info->block_list = eo_info->block_list;
+ s_dynamic_info_list = g_slist_append(s_dynamic_info_list, (eo_info_dynamic_t*)dynamic_info);
+
+ /* Pass out entry to the GUI */
+ object_list_add_entry(object_list, entry);
+
+ return TRUE; /* State changed - window should be redrawn */
+}
+
+/* Clean up the stored parts of a single tapped entry */
+static void cleanup_tftp_eo(eo_info_dynamic_t *dynamic_info)
+{
+ GSList *block_iterator;
+ /* Free the filename */
+ g_free(dynamic_info->filename);
+
+ /* Walk list of block items */
+ for (block_iterator = dynamic_info->block_list; block_iterator; block_iterator = block_iterator->next) {
+ file_block_t *block = (file_block_t*)(block_iterator->data);
+ /* Free block data */
+ wmem_free(NULL, block->data);
+
+ /* Free block itself */
+ g_free(block);
+ }
+}
+
+/* Callback for freeing up data supplied with taps. The taps themselves only have
+ packet scope, so only store/free dynamic memory pointers */
+void eo_tftp_cleanup(void)
+{
+ /* Cleanup each entry in the global list */
+ GSList *dynamic_iterator;
+ for (dynamic_iterator = s_dynamic_info_list; dynamic_iterator; dynamic_iterator = dynamic_iterator->next) {
+ eo_info_dynamic_t *dynamic_info = (eo_info_dynamic_t*)dynamic_iterator->data;
+ cleanup_tftp_eo(dynamic_info);
+ }
+ /* List is empty again */
+ s_dynamic_info_list = NULL;
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/gtk/export_object_dlg.c b/ui/gtk/export_object_dlg.c
index 7e6fd68fd5..2b72edbcc2 100644
--- a/ui/gtk/export_object_dlg.c
+++ b/ui/gtk/export_object_dlg.c
@@ -509,3 +509,10 @@ eo_smb_cb(GtkWidget *widget _U_, gpointer data _U_)
/* Call the export_object window */
export_object_window("smb_eo", "SMB", eo_smb_packet, eo_smb_cleanup);
}
+
+void
+eo_tftp_cb(GtkWidget *widget _U_, gpointer data _U_)
+{
+ /* Call the export_object window */
+ export_object_window("tftp_eo", "TFTP", eo_tftp_packet, eo_tftp_cleanup);
+}
diff --git a/ui/gtk/export_object_dlg.h b/ui/gtk/export_object_dlg.h
index 803dee30e3..73fae69a34 100644
--- a/ui/gtk/export_object_dlg.h
+++ b/ui/gtk/export_object_dlg.h
@@ -29,5 +29,6 @@
void eo_dicom_cb(GtkWidget *widget _U_, gpointer data _U_);
void eo_http_cb(GtkWidget *widget _U_, gpointer data _U_);
void eo_smb_cb(GtkWidget *widget _U_, gpointer data _U_);
+void eo_tftp_cb(GtkWidget *widget _U_, gpointer data _U_);
#endif /* __EXPORT_OBJECT_DLG_H__ */
diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c
index 463311f93c..8966e99634 100644
--- a/ui/gtk/main_menubar.c
+++ b/ui/gtk/main_menubar.c
@@ -994,6 +994,7 @@ static const char *ui_desc_menubar =
" <menuitem name='HTTP' action='/File/ExportObjects/HTTP'/>\n"
" <menuitem name='DICOM' action='/File/ExportObjects/DICOM'/>\n"
" <menuitem name='SMB' action='/File/ExportObjects/SMB'/>\n"
+" <menuitem name='TFTP' action='/File/ExportObjects/TFTP'/>\n"
" </menu>\n"
" <separator/>\n"
" <menuitem name='Print' action='/File/Print'/>\n"
@@ -1468,7 +1469,7 @@ static const GtkActionEntry main_menu_bar_entries[] = {
{ "/File/ExportObjects/HTTP", NULL, "_HTTP", NULL, NULL, G_CALLBACK(eo_http_cb) },
{ "/File/ExportObjects/DICOM", NULL, "_DICOM", NULL, NULL, G_CALLBACK(eo_dicom_cb) },
{ "/File/ExportObjects/SMB", NULL, "_SMB/SMB2", NULL, NULL, G_CALLBACK(eo_smb_cb) },
-
+ { "/File/ExportObjects/TFTP", NULL, "_TFTP", NULL, NULL, G_CALLBACK(eo_tftp_cb) },
{ "/Edit/Copy", NULL, "Copy", NULL, NULL, NULL },