aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorJaap Keuter <jaap.keuter@xs4all.nl>2010-11-12 22:20:12 +0000
committerJaap Keuter <jaap.keuter@xs4all.nl>2010-11-12 22:20:12 +0000
commit296e43c3ebd6c7e8cfb50f0957dc487f5248bf2b (patch)
tree31ea11d78152da42e1aabe36c2f4531e030df931 /gtk
parent671344e6cc27831b89f31bbfe22cc6e8a776abe4 (diff)
Add text import capability, like text2pcap, directly into the GUI.
svn path=/trunk/; revision=34856
Diffstat (limited to 'gtk')
-rw-r--r--gtk/CMakeLists.txt2
-rw-r--r--gtk/Makefile.am3
-rw-r--r--gtk/Makefile.common14
-rw-r--r--gtk/file_import_dlg.c1320
-rw-r--r--gtk/file_import_dlg.h31
-rw-r--r--gtk/menus.c4
-rw-r--r--gtk/text_import.c973
-rw-r--r--gtk/text_import.h103
-rw-r--r--gtk/text_import_scanner.l101
9 files changed, 2548 insertions, 3 deletions
diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt
index ec1254d96e..c47098944b 100644
--- a/gtk/CMakeLists.txt
+++ b/gtk/CMakeLists.txt
@@ -49,6 +49,7 @@ set(WIRESHARK_GTK_SRC
export_object_smb.c
filter_autocomplete.c
file_dlg.c
+ file_import_dlg.c
fileset_dlg.c
filter_dlg.c
filter_utils.c
@@ -114,6 +115,7 @@ set(WIRESHARK_GTK_SRC
summary_dlg.c
supported_protos_dlg.c
tap_dfilter_dlg.c
+ text_import.c
text_page_utils.c
u3.c
uat_gui.c
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 59bddeb5af..82f591b8e2 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -22,6 +22,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
include Makefile.common
+include ../Makefile.am.inc
if HAVE_WARNINGS_AS_ERRORS
AM_CFLAGS = -Werror
@@ -37,6 +38,8 @@ MAINTAINERCLEANFILES = \
$(GENERATED_FILES) \
Makefile.in
+RUNLEX=$(top_srcdir)/tools/runlex.sh
+
wireshark-tap-register.c: $(WIRESHARK_TAP_SRC) $(top_srcdir)/tools/make-tapreg-dotc
@echo Making wireshark-tap-register.c
@$(top_srcdir)/tools/make-tapreg-dotc wireshark-tap-register.c $(srcdir) $(WIRESHARK_TAP_SRC)
diff --git a/gtk/Makefile.common b/gtk/Makefile.common
index ffd4d5d444..c948a2f015 100644
--- a/gtk/Makefile.common
+++ b/gtk/Makefile.common
@@ -24,16 +24,21 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Generated header files that we want in the distribution.
-# (None, so far.)
-GENERATED_HEADER_FILES =
+GENERATED_HEADER_FILES = \
+ text_import_scanner_lex.h
# Generated C source files that we want in the distribution.
GENERATED_C_FILES = \
- wireshark-tap-register.c
+ wireshark-tap-register.c \
+ text_import_scanner.c
# All the generated files we want in the distribution.
GENERATED_FILES = $(GENERATED_HEADER_FILES) $(GENERATED_C_FILES)
+# Files that generate compileable files
+GENERATOR_FILES = \
+ text_import_scanner.l
+
WIRESHARK_GTK_SRC = \
about_dlg.c \
airpcap_dlg.c \
@@ -61,6 +66,7 @@ WIRESHARK_GTK_SRC = \
export_object_smb.c \
filter_autocomplete.c \
file_dlg.c \
+ file_import_dlg.c \
fileset_dlg.c \
filter_dlg.c \
filter_utils.c \
@@ -126,6 +132,7 @@ WIRESHARK_GTK_SRC = \
summary_dlg.c \
supported_protos_dlg.c \
tap_dfilter_dlg.c \
+ text_import.c \
text_page_utils.c \
u3.c \
uat_gui.c \
@@ -243,6 +250,7 @@ noinst_HEADERS = \
expert_indicators.h \
export_object.h \
file_dlg.h \
+ file_import_dlg.h \
fileset_dlg.h \
filter_autocomplete.h \
filter_dlg.h \
diff --git a/gtk/file_import_dlg.c b/gtk/file_import_dlg.c
new file mode 100644
index 0000000000..2577da2283
--- /dev/null
+++ b/gtk/file_import_dlg.c
@@ -0,0 +1,1320 @@
+/* file_import_dlg.c
+ * Dialog to setup for import of a text file, like text2pcap
+ * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
+ *
+ * $Id$
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <ctype.h>
+#include <string.h>
+
+#include "globals.h"
+#include "wtap.h"
+#include "pcap-encap.h"
+
+#include <epan/prefs.h>
+
+#include <gtk/gtk.h>
+
+#include "filters.h"
+#include "simple_dialog.h"
+#include "alert_box.h"
+
+#include "gtk/gtkglobals.h"
+#include "gtk/stock_icons.h"
+#include "gtk/dlg_utils.h"
+#include "gtk/gui_utils.h"
+#include "gtk/file_dlg.h"
+#include "gtk/capture_file_dlg.h"
+#include "gtk/help_dlg.h"
+
+#include "gtk/file_import_dlg.h"
+#include "gtk/text_import.h"
+
+#include "file.h"
+#include "wsutil/file_util.h"
+#include "tempfile.h"
+
+#define INPUT_FRM_KEY "input_frame"
+
+#define INPUT_FILENAME_TE_KEY "input_filename_text"
+
+#define INPUT_OFFSET_HEX_RB_KEY "input_offset_hex_radio"
+#define INPUT_OFFSET_OCT_RB_KEY "input_offset_oct_radio"
+#define INPUT_OFFSET_DEC_RB_KEY "input_offset_dec_radio"
+
+#define INPUT_DATETIME_CB_KEY "input_datetime_checkbox"
+#define INPUT_TIMEFMT_LBL_KEY "input_timeformat_label"
+#define INPUT_TIMEFMT_TE_KEY "input_timeformat_entry"
+
+#define IMPORT_FRM_KEY "import_frame"
+#define IMPORT_ENCAP_CO_KEY "import_encap_combo"
+
+#define IMPORT_HEADER_FRM_KEY "import_header_frame"
+#define IMPORT_HEADER_CB_KEY "import_header_checkbox"
+#define IMPORT_HEADER_ETH_RB_KEY "import_header_ethernet_radio"
+#define IMPORT_HEADER_ETYPE_LBL_KEY "import_header_etype_label"
+#define IMPORT_HEADER_ETYPE_TE_KEY "import_header_etype_text"
+#define IMPORT_HEADER_IPV4_RB_KEY "import_header_ipv4_radio"
+#define IMPORT_HEADER_PROT_LBL_KEY "import_header_prot_label"
+#define IMPORT_HEADER_PROT_TE_KEY "import_header_prot_text"
+#define IMPORT_HEADER_UDP_RB_KEY "import_header_udp_radio"
+#define IMPORT_HEADER_SRC_PORT_LBL_KEY "import_header_src_port_label"
+#define IMPORT_HEADER_SRC_PORT_TE_KEY "import_header_src_port_text"
+#define IMPORT_HEADER_TCP_RB_KEY "import_header_tcp_radio"
+#define IMPORT_HEADER_DST_PORT_LBL_KEY "import_header_dst_port_label"
+#define IMPORT_HEADER_DST_PORT_TE_KEY "import_header_dst_port_text"
+#define IMPORT_HEADER_SCTP_RB_KEY "import_header_sctp_radio"
+#define IMPORT_HEADER_TAG_LBL_KEY "import_header_tag_label"
+#define IMPORT_HEADER_TAG_TE_KEY "import_header_tag_text"
+#define IMPORT_HEADER_SCTP_D_RB_KEY "import_header_sctp_data_radio"
+#define IMPORT_HEADER_PPI_LBL_KEY "import_header_ppi_label"
+#define IMPORT_HEADER_PPI_TE_KEY "import_header_ppi_text"
+
+#define IMPORT_FRAME_LENGTH_TE_KEY "import_frame_length_text"
+
+static GtkWidget *file_import_dlg_w = NULL;
+static GtkListStore *encap_list_store = NULL;
+
+/*****************************************************************************/
+
+static void
+file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
+{
+ file_import_dlg_w = NULL;
+}
+
+/*****************************************************************************/
+
+static void
+browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
+{
+ file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Text",
+ FILE_SELECTION_READ_BROWSE);
+}
+
+static void
+timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
+{
+ GtkWidget *timefmt_lbl, *timefmt_te;
+ gboolean apply_fmt;
+
+ timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
+ timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
+
+ apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+ gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
+ gtk_widget_set_sensitive(timefmt_te, apply_fmt);
+}
+
+/*****************************************************************************/
+static void
+create_encap_list_store(void)
+{
+ GtkTreeIter iter;
+ gint encap;
+ const gchar *name;
+
+ encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
+
+ /* Scan all Wiretap encapsulation types */
+ for (encap = 1; encap < wtap_get_num_encap_types(); encap++)
+ {
+ /* Check if we can write it to a PCAP file */
+ if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) &&
+ /*
+ * Exclude wtap encapsulations that require a pseudo header,
+ * because we won't setup one from the text we import and
+ * wiretap doesn't allow us to write 'raw' frames
+ */
+ !((encap == WTAP_ENCAP_ATM_PDUS) ||
+ (encap == WTAP_ENCAP_IRDA) ||
+ (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
+ (encap == WTAP_ENCAP_LINUX_LAPD) ||
+ (encap == WTAP_ENCAP_SITA) ||
+ (encap == WTAP_ENCAP_ERF) ||
+ (encap == WTAP_ENCAP_I2C) ||
+ (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
+ (encap == WTAP_ENCAP_PPP_WITH_PHDR)
+ ) )
+ {
+ /* If it has got a name */
+ if ((name = wtap_encap_string(encap)))
+ {
+ gtk_list_store_append(encap_list_store, &iter);
+ gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
+ }
+ }
+ }
+
+}
+
+static GtkWidget *
+fill_encap_combo(void)
+{
+ GtkWidget *encap_co = NULL;
+ GtkCellRenderer *cell;
+
+ encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
+ cell = gtk_cell_renderer_text_new();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
+
+ return encap_co;
+}
+
+static void header_frm_child_set(GtkWidget *widget, gpointer data);
+
+static void
+encap_co_changed(GtkComboBox *widget, gpointer data)
+{
+ GtkTreeIter iter;
+ gboolean result;
+ GtkWidget *header_cb;
+
+ result = gtk_combo_box_get_active_iter(widget, &iter);
+
+ if (result)
+ {
+ guint8 encap;
+ GtkTreeModel *model = gtk_combo_box_get_model(widget);
+ gtk_tree_model_get(model, &iter, 1, &encap, -1);
+
+ if (encap != WTAP_ENCAP_ETHERNET)
+ result = FALSE;
+ }
+
+ if (result)
+ {
+ header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
+ g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
+ } else {
+ gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
+ }
+}
+
+/*****************************************************************************/
+
+static void
+header_frm_child_set(GtkWidget *widget, gpointer data)
+{
+ gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
+}
+
+static void
+header_cb_toggle(GtkWidget *widget, gpointer data)
+{
+ gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
+ GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
+ /* The frame's checkbox must stay sensitive, of course... */
+ gtk_widget_set_sensitive(widget, TRUE);
+}
+
+/*
+ * Header radio button toggle handlers
+ */
+static void
+header_eth_rb_toggle(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
+ GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ {
+ gtk_widget_set_sensitive(etype_lbl, TRUE);
+ gtk_widget_set_sensitive(etype_te, TRUE);
+ gtk_widget_set_sensitive(prot_lbl, FALSE);
+ gtk_widget_set_sensitive(prot_te, FALSE);
+ gtk_widget_set_sensitive(src_port_lbl, FALSE);
+ gtk_widget_set_sensitive(src_port_te, FALSE);
+ gtk_widget_set_sensitive(dst_port_lbl, FALSE);
+ gtk_widget_set_sensitive(dst_port_te, FALSE);
+ gtk_widget_set_sensitive(tag_lbl, FALSE);
+ gtk_widget_set_sensitive(tag_te, FALSE);
+ gtk_widget_set_sensitive(ppi_lbl, FALSE);
+ gtk_widget_set_sensitive(ppi_te, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(etype_lbl, FALSE);
+ gtk_widget_set_sensitive(etype_te, FALSE);
+ }
+}
+
+static void
+header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
+ GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ {
+ gtk_widget_set_sensitive(etype_lbl, FALSE);
+ gtk_widget_set_sensitive(etype_te, FALSE);
+ gtk_widget_set_sensitive(prot_lbl, TRUE);
+ gtk_widget_set_sensitive(prot_te, TRUE);
+ gtk_widget_set_sensitive(src_port_lbl, FALSE);
+ gtk_widget_set_sensitive(src_port_te, FALSE);
+ gtk_widget_set_sensitive(dst_port_lbl, FALSE);
+ gtk_widget_set_sensitive(dst_port_te, FALSE);
+ gtk_widget_set_sensitive(tag_lbl, FALSE);
+ gtk_widget_set_sensitive(tag_te, FALSE);
+ gtk_widget_set_sensitive(ppi_lbl, FALSE);
+ gtk_widget_set_sensitive(ppi_te, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(prot_lbl, FALSE);
+ gtk_widget_set_sensitive(prot_te, FALSE);
+ }
+}
+
+static void
+header_udp_rb_toggle(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
+ GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ {
+ gtk_widget_set_sensitive(etype_lbl, FALSE);
+ gtk_widget_set_sensitive(etype_te, FALSE);
+ gtk_widget_set_sensitive(prot_lbl, FALSE);
+ gtk_widget_set_sensitive(prot_te, FALSE);
+ gtk_widget_set_sensitive(src_port_lbl, TRUE);
+ gtk_widget_set_sensitive(src_port_te, TRUE);
+ gtk_widget_set_sensitive(dst_port_lbl, TRUE);
+ gtk_widget_set_sensitive(dst_port_te, TRUE);
+ gtk_widget_set_sensitive(tag_lbl, FALSE);
+ gtk_widget_set_sensitive(tag_te, FALSE);
+ gtk_widget_set_sensitive(ppi_lbl, FALSE);
+ gtk_widget_set_sensitive(ppi_te, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(src_port_lbl, FALSE);
+ gtk_widget_set_sensitive(src_port_te, FALSE);
+ gtk_widget_set_sensitive(dst_port_lbl, FALSE);
+ gtk_widget_set_sensitive(dst_port_te, FALSE);
+ }
+}
+
+static void
+header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
+ GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ {
+ gtk_widget_set_sensitive(etype_lbl, FALSE);
+ gtk_widget_set_sensitive(etype_te, FALSE);
+ gtk_widget_set_sensitive(prot_lbl, FALSE);
+ gtk_widget_set_sensitive(prot_te, FALSE);
+ gtk_widget_set_sensitive(src_port_lbl, TRUE);
+ gtk_widget_set_sensitive(src_port_te, TRUE);
+ gtk_widget_set_sensitive(dst_port_lbl, TRUE);
+ gtk_widget_set_sensitive(dst_port_te, TRUE);
+ gtk_widget_set_sensitive(tag_lbl, FALSE);
+ gtk_widget_set_sensitive(tag_te, FALSE);
+ gtk_widget_set_sensitive(ppi_lbl, FALSE);
+ gtk_widget_set_sensitive(ppi_te, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(src_port_lbl, FALSE);
+ gtk_widget_set_sensitive(src_port_te, FALSE);
+ gtk_widget_set_sensitive(dst_port_lbl, FALSE);
+ gtk_widget_set_sensitive(dst_port_te, FALSE);
+ }
+}
+
+static void
+header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
+ GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ {
+ gtk_widget_set_sensitive(etype_lbl, FALSE);
+ gtk_widget_set_sensitive(etype_te, FALSE);
+ gtk_widget_set_sensitive(prot_lbl, FALSE);
+ gtk_widget_set_sensitive(prot_te, FALSE);
+ gtk_widget_set_sensitive(src_port_lbl, TRUE);
+ gtk_widget_set_sensitive(src_port_te, TRUE);
+ gtk_widget_set_sensitive(dst_port_lbl, TRUE);
+ gtk_widget_set_sensitive(dst_port_te, TRUE);
+ gtk_widget_set_sensitive(tag_lbl, TRUE);
+ gtk_widget_set_sensitive(tag_te, TRUE);
+ gtk_widget_set_sensitive(ppi_lbl, FALSE);
+ gtk_widget_set_sensitive(ppi_te, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(src_port_lbl, FALSE);
+ gtk_widget_set_sensitive(src_port_te, FALSE);
+ gtk_widget_set_sensitive(dst_port_lbl, FALSE);
+ gtk_widget_set_sensitive(dst_port_te, FALSE);
+ gtk_widget_set_sensitive(tag_lbl, FALSE);
+ gtk_widget_set_sensitive(tag_te, FALSE);
+ }
+}
+
+static void
+header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
+{
+ GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
+ GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
+ {
+ gtk_widget_set_sensitive(etype_lbl, FALSE);
+ gtk_widget_set_sensitive(etype_te, FALSE);
+ gtk_widget_set_sensitive(prot_lbl, FALSE);
+ gtk_widget_set_sensitive(prot_te, FALSE);
+ gtk_widget_set_sensitive(src_port_lbl, TRUE);
+ gtk_widget_set_sensitive(src_port_te, TRUE);
+ gtk_widget_set_sensitive(dst_port_lbl, TRUE);
+ gtk_widget_set_sensitive(dst_port_te, TRUE);
+ gtk_widget_set_sensitive(tag_lbl, FALSE);
+ gtk_widget_set_sensitive(tag_te, FALSE);
+ gtk_widget_set_sensitive(ppi_lbl, TRUE);
+ gtk_widget_set_sensitive(ppi_te, TRUE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(src_port_lbl, FALSE);
+ gtk_widget_set_sensitive(src_port_te, FALSE);
+ gtk_widget_set_sensitive(dst_port_lbl, FALSE);
+ gtk_widget_set_sensitive(dst_port_te, FALSE);
+ gtk_widget_set_sensitive(ppi_lbl, FALSE);
+ gtk_widget_set_sensitive(ppi_te, FALSE);
+ }
+}
+
+/*****************************************************************************/
+
+static void
+file_import_open(text_import_info_t *info)
+{
+ int import_file_fd;
+ char *tmpname, *capfile_name = NULL;
+ int err;
+
+ /* Choose a random name for the temporary import buffer */
+ import_file_fd = create_tempfile(&tmpname, "import");
+ capfile_name = g_strdup(tmpname);
+
+ info->wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_PCAP, info->encapsulation, info->max_frame_length, FALSE, &err);
+ if (info->wdh == NULL) {
+ open_failure_alert_box(capfile_name, err, TRUE);
+ fclose(info->import_text_file);
+ goto end;
+ }
+
+ text_import_setup(info);
+
+ text_importset_in(info->import_text_file);
+ text_importlex();
+
+ text_import_cleanup();
+
+ if (fclose(info->import_text_file))
+ {
+ read_failure_alert_box(info->import_text_filename, errno);
+ }
+
+ if (!wtap_dump_close(info->wdh, &err))
+ {
+ write_failure_alert_box(capfile_name, err);
+ }
+
+ if (cf_open(&cfile, capfile_name, TRUE /* temporary file */, &err) != CF_OK)
+ {
+ open_failure_alert_box(capfile_name, err, FALSE);
+ goto end;
+ }
+
+ switch (cf_read(&cfile, FALSE)) {
+ case CF_READ_OK:
+ case CF_READ_ERROR:
+ /* Just because we got an error, that doesn't mean we were unable
+ to read any of the file; we handle what we could get from the
+ file. */
+ break;
+
+ case CF_READ_ABORTED:
+ /* The user bailed out of re-reading the capture file; the
+ capture file has been closed - just free the capture file name
+ string and return (without changing the last containing
+ directory). */
+ break;
+ }
+
+end:
+ g_free(info->import_text_filename);
+ g_free(info->date_timestamp_format);
+ g_free(info);
+ g_free(capfile_name);
+ window_destroy(file_import_dlg_w);
+}
+
+static text_import_info_t *
+setup_file_import(GtkWidget *main_w)
+{
+ GtkWidget *input_frm, *import_frm;
+
+ text_import_info_t *text_import_info = g_malloc0(sizeof(text_import_info_t));
+
+ /* Retrieve the input and import settings from the dialog */
+
+ /* First the main components */
+ input_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
+ import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
+
+ /* Then the input frame controls of interest */
+ {
+ GtkWidget *filename_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
+ GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
+ GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
+ GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
+ GtkWidget *timefmt_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
+ GtkWidget *timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
+
+ text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
+
+ /* Try to open the input file */
+ text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
+ if (!text_import_info->import_text_file) {
+ open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
+ g_free(text_import_info->import_text_filename);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+
+ text_import_info->offset_type =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
+ 0;
+ text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
+ text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
+ }
+
+ /* Then the import frame controls of interest */
+ {
+ GtkWidget *encap_co = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
+ GtkWidget *header_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
+ GtkWidget *framelen_te = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
+
+ /* Then the header frame controls of interest */
+ GtkWidget *header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
+
+ GtkWidget *header_eth_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
+ GtkWidget *header_ipv4_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
+ GtkWidget *header_udp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
+ GtkWidget *header_tcp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
+ GtkWidget *header_sctp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
+ GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
+
+ GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
+ GtkWidget *protocol_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
+ GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
+ GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
+ GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
+ GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
+
+ GtkTreeIter iter;
+
+ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter))
+ {
+ GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
+ gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
+ }
+
+ if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
+ (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb))))
+ {
+ text_import_info->dummy_header_type =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb)) ? HEADER_ETH :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb)) ? HEADER_IPV4 :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb)) ? HEADER_UDP :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb)) ? HEADER_TCP :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb)) ? HEADER_SCTP :
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
+ HEADER_NONE;
+
+ switch (text_import_info->dummy_header_type)
+ {
+ case HEADER_ETH:
+ text_import_info->pid = strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
+ if (text_import_info->pid > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
+ text_import_info->pid);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ break;
+
+ case HEADER_IPV4:
+ text_import_info->protocol = strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
+ if (text_import_info->protocol > 0xff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
+ text_import_info->protocol);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ break;
+
+ case HEADER_UDP:
+ case HEADER_TCP:
+ text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
+ if (text_import_info->src_port > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
+ text_import_info->src_port);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
+ if (text_import_info->dst_port > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
+ text_import_info->dst_port);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ break;
+
+ case HEADER_SCTP:
+ text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
+ if (text_import_info->src_port > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
+ text_import_info->src_port);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
+ if (text_import_info->dst_port > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
+ text_import_info->dst_port);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ text_import_info->tag = strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
+ break;
+
+ case HEADER_SCTP_DATA:
+ text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
+ if (text_import_info->src_port > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
+ text_import_info->src_port);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
+ if (text_import_info->dst_port > 0xffff)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
+ text_import_info->dst_port);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ text_import_info->ppi = strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
+ break;
+
+ default:
+ break;
+ }
+ } else {
+ text_import_info->dummy_header_type = HEADER_NONE;
+ }
+
+ text_import_info->max_frame_length = strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
+ if (text_import_info->max_frame_length == 0) {
+ text_import_info->max_frame_length = IMPORT_MAX_PACKET;
+ }
+ else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
+ text_import_info->max_frame_length);
+ g_free(text_import_info->import_text_filename);
+ fclose(text_import_info->import_text_file);
+ g_free(text_import_info->date_timestamp_format);
+ g_free(text_import_info);
+ return NULL;
+ }
+ }
+
+ return text_import_info;
+}
+
+/*****************************************************************************/
+
+static void
+file_import_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
+{
+ text_import_info_t *text_import_info;
+
+ switch (btn) {
+ case ESD_BTN_SAVE:
+ /* save file first */
+ file_save_as_cmd(after_save_no_action, NULL);
+ break;
+ case ESD_BTN_DONT_SAVE:
+ cf_close(&cfile);
+ break;
+ case ESD_BTN_CANCEL:
+ return;
+ default:
+ g_assert_not_reached();
+ }
+
+ text_import_info = setup_file_import(data);
+ if (text_import_info)
+ file_import_open(text_import_info);
+}
+
+static void
+file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
+{
+ text_import_info_t *text_import_info;
+
+ if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
+ gpointer dialog;
+ /* user didn't save his current file, ask him */
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
+ "%sSave capture file before opening a new one?%s\n\n"
+ "If you open a new capture file without saving, your capture data will be discarded.",
+ simple_dialog_primary_start(), simple_dialog_primary_end());
+ simple_dialog_set_cb(dialog, file_import_answered_cb, data);
+ } else {
+ /* unchanged file, just open a new one */
+ text_import_info = setup_file_import(data);
+ if (text_import_info)
+ file_import_open(text_import_info);
+ }
+
+}
+
+/*****************************************************************************/
+
+/*
+ * Dialog creator
+ */
+static GtkWidget *
+file_import_dlg_new()
+{
+ GtkWidget *main_w, *main_vb,
+ *input_frm, *input_tb, *input_vb,
+ *filename_hb, *filename_lbl, *filename_te, *browse_bt,
+ *offset_hb, *offset_lbl_vb, *offset_lbl, *offset_rb_vb,
+ *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
+ *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
+ *import_frm, *import_vb,
+ *encap_hb, *encap_lbl, *encap_co,
+ *header_cb, *header_frm, *header_hb,
+ *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
+ *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
+ *header_rblbl_vb,
+ *header_rblbl_1_hb, *header_rblbl_1_lbl,
+ *header_rblbl_2_hb, *header_rblbl_2_lbl,
+ *header_rblbl_3_hb, *header_rblbl_3_lbl,
+ *header_rblbl_4_hb, *header_rblbl_4_lbl,
+ *header_rblbl_5_hb, *header_rblbl_5_lbl,
+ *header_rblbl_6_hb, *header_rblbl_6_lbl,
+ *header_entries_vb,
+ *etype_te, *protocol_te, *src_port_te,
+ *dst_port_te, *tag_te, *ppi_te,
+ *framelen_hb, *framelen_lbl, *framelen_te,
+ *bbox, *help_bt, *close_bt, *ok_bt;
+
+ GSList *offset_grp, /* Offset radio button group */
+ *header_grp; /* Dummy header radio button group */
+
+#if GTK_CHECK_VERSION(2,12,0)
+#else
+ GtkTooltips *tooltips = gtk_tooltips_new();
+#endif
+
+ /* Setup the dialog */
+
+ main_w = dlg_window_new("Wireshark: Import from Text");
+ gtk_window_set_default_size(GTK_WINDOW(main_w), 400, 300);
+
+ main_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
+ gtk_container_add(GTK_CONTAINER(main_w), main_vb);
+
+ /* Setup the input frame */
+
+ input_frm = gtk_frame_new("Input");
+ gtk_box_pack_start(GTK_BOX(main_vb), input_frm, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(main_w), INPUT_FRM_KEY, input_frm);
+
+ input_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(input_frm), input_vb);
+
+ input_tb = gtk_table_new(2, 3, FALSE);
+ gtk_container_set_border_width(GTK_CONTAINER(input_tb), 5);
+ gtk_box_pack_start(GTK_BOX(input_vb), input_tb, FALSE, FALSE, 0);
+ gtk_table_set_row_spacings(GTK_TABLE(input_tb), 5);
+ gtk_table_set_col_spacings(GTK_TABLE(input_tb), 5);
+
+ /* Filename */
+ filename_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_set_border_width(GTK_CONTAINER(filename_hb), 3);
+
+ filename_lbl = gtk_label_new("Filename:");
+ gtk_table_attach(GTK_TABLE(input_tb), filename_lbl, 0, 1, 0, 1, 0, 0, 0, 0);
+
+ filename_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(filename_te, "Set name of text file to import");
+#else
+ gtk_tooltips_set_tip(tooltips, filename_te, "Set name of text file to import", NULL);
+#endif
+ gtk_table_attach_defaults(GTK_TABLE(input_tb), filename_te, 1, 2, 0, 1);
+
+ g_object_set_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY, filename_te);
+
+ browse_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(browse_bt, "Browse for text file to import");
+#else
+ gtk_tooltips_set_tip(tooltips, browse_bt, "Browse for text file to import", NULL);
+#endif
+ gtk_table_attach(GTK_TABLE(input_tb), browse_bt, 2, 3, 0, 1, 0, 0, 0, 0);
+
+ g_signal_connect(browse_bt, "clicked", G_CALLBACK(browse_file_cb), filename_te);
+
+ /* Offsets */
+ offset_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_set_border_width(GTK_CONTAINER(offset_hb), 3);
+ gtk_box_pack_start(GTK_BOX(input_vb), offset_hb, FALSE, FALSE, 0);
+
+ offset_lbl_vb = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(offset_hb), offset_lbl_vb, FALSE, FALSE, 0);
+
+ offset_lbl = gtk_label_new("Offsets:");
+ gtk_misc_set_alignment(GTK_MISC(offset_lbl), 1.0f, 0.0f);
+ gtk_table_attach(GTK_TABLE(input_tb), offset_lbl, 0, 1, 1, 2, 0, 0, 0, 0);
+
+ offset_rb_vb = gtk_vbox_new(FALSE, 0);
+ gtk_table_attach_defaults(GTK_TABLE(input_tb), offset_rb_vb, 1, 2, 1, 2);
+
+ offset_hex_rb = gtk_radio_button_new_with_label(NULL, "Hexadecimal");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(offset_hex_rb, "Offsets in the text file are in hexadecimal notation");
+#else
+ gtk_tooltips_set_tip(tooltips, offset_hex_rb, "Offsets in the text file are in hexadecimal notation", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_hex_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY, offset_hex_rb);
+
+ offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_hex_rb));
+ offset_oct_rb = gtk_radio_button_new_with_label(offset_grp, "Octal");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(offset_oct_rb, "Offsets in the text file are in octal notation");
+#else
+ gtk_tooltips_set_tip(tooltips, offset_oct_rb, "Offsets in the text file are in octal notation", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_oct_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY, offset_oct_rb);
+
+ offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_oct_rb));
+ offset_dec_rb = gtk_radio_button_new_with_label(offset_grp, "Decimal");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(offset_dec_rb, "Offsets in the text file are in decimal notation");
+#else
+ gtk_tooltips_set_tip(tooltips, offset_dec_rb, "Offsets in the text file are in decimal notation", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_dec_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY, offset_dec_rb);
+
+ /* Time format */
+ timefmt_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_set_border_width(GTK_CONTAINER(timefmt_hb), 3);
+ gtk_box_pack_start(GTK_BOX(input_vb), timefmt_hb, FALSE, FALSE, 0);
+
+ timefmt_cb = gtk_check_button_new_with_label("Date/Time");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(timefmt_cb, "Whether or not the text file contains timestamp information");
+#else
+ gtk_tooltips_set_tip(tooltips, timefmt_cb, "Whether or not the text file contains timestamp information", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_cb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY, timefmt_cb);
+
+ timefmt_lbl = gtk_label_new(" Format:");
+ gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_lbl, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_LBL_KEY, timefmt_lbl);
+
+ timefmt_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(timefmt_te, "The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)");
+#else
+ gtk_tooltips_set_tip(tooltips, timefmt_te, "The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_TE_KEY, timefmt_te);
+ g_object_set_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY, timefmt_te);
+
+ g_signal_connect(timefmt_cb, "toggled", G_CALLBACK(timefmt_cb_toggle), NULL);
+ g_signal_emit_by_name(G_OBJECT(timefmt_cb), "toggled", NULL);
+
+ /* Setup the import frame */
+
+ import_frm = gtk_frame_new("Import");
+ gtk_box_pack_start(GTK_BOX(main_vb), import_frm, TRUE, TRUE, 3);
+
+ g_object_set_data(G_OBJECT(main_w), IMPORT_FRM_KEY, import_frm);
+
+ import_vb = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(import_frm), import_vb);
+
+ /* Encapsulation */
+ encap_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_set_border_width(GTK_CONTAINER(encap_hb), 3);
+ gtk_box_pack_start(GTK_BOX(import_vb), encap_hb, FALSE, FALSE, 0);
+
+ encap_lbl = gtk_label_new("Encapsulation type:");
+ gtk_box_pack_start(GTK_BOX(encap_hb), encap_lbl, FALSE, FALSE, 0);
+
+ encap_co = fill_encap_combo();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(encap_co, "Encapsulation type for the frames in the import capture file");
+#else
+ gtk_tooltips_set_tip(tooltips, encap_co, "Encapsulation type for the frames in the import capture file", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(encap_hb), encap_co, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY, encap_co);
+
+ /* Dummy header */
+ header_frm = gtk_frame_new(NULL);
+ header_cb = gtk_check_button_new_with_label("Dummy header");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_cb, "Whether or not to prefix a dummy header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_cb, "Whether or not to prefix a dummy header to the frames", NULL);
+#endif
+ gtk_frame_set_label_widget(GTK_FRAME(header_frm), header_cb);
+ gtk_container_set_border_width(GTK_CONTAINER(header_frm), 3);
+ gtk_box_pack_start(GTK_BOX(import_vb), header_frm, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY, header_frm);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY, header_cb);
+
+ header_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_set_border_width(GTK_CONTAINER(header_hb), 3);
+ gtk_container_add(GTK_CONTAINER(header_frm), header_hb);
+
+ header_rblbl_vb = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_hb), header_rblbl_vb, TRUE, TRUE, 0);
+
+ header_entries_vb = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_hb), header_entries_vb, FALSE, FALSE, 0);
+
+ /* Line 1 */
+ header_rblbl_1_hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_1_hb, FALSE, FALSE, 2);
+
+ header_eth_rb = gtk_radio_button_new_with_label(NULL, "Ethernet");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_eth_rb, "Prefix an Ethernet header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_eth_rb, "Prefix an Ethernet header to the frames", NULL);
+#endif
+ header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_eth_rb));
+ g_signal_connect(header_eth_rb, "toggled", G_CALLBACK(header_eth_rb_toggle), header_frm);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_eth_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY, header_eth_rb);
+
+ header_rblbl_1_lbl = gtk_label_new(" Ethertype (hex):");
+ gtk_box_pack_end(GTK_BOX(header_rblbl_1_hb), header_rblbl_1_lbl, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(header_rblbl_1_lbl), 1.0f, 0.5f);
+
+ etype_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(etype_te, "The type to set in the Ethernet header");
+#else
+ gtk_tooltips_set_tip(tooltips, etype_te, "The type to set in the Ethernet header", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(header_entries_vb), etype_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_LBL_KEY, header_rblbl_1_lbl);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY, etype_te);
+
+ /* Line 2 */
+ header_rblbl_2_hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_2_hb, FALSE, FALSE, 2);
+
+ header_ipv4_rb = gtk_radio_button_new_with_label(header_grp, "IPv4");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames", NULL);
+#endif
+ header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_ipv4_rb));
+ g_signal_connect(header_ipv4_rb, "toggled", G_CALLBACK(header_ipv4_rb_toggle), header_frm);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_ipv4_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY, header_ipv4_rb);
+
+ header_rblbl_2_lbl = gtk_label_new(" Protocol (dec):");
+ gtk_box_pack_end(GTK_BOX(header_rblbl_2_hb), header_rblbl_2_lbl, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(header_rblbl_2_lbl), 1.0f, 0.5f);
+
+ protocol_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(protocol_te, "The protocol id to set in the IPv4 header");
+#else
+ gtk_tooltips_set_tip(tooltips, protocol_te, "The protocol id to set in the IPv4 header", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(header_entries_vb), protocol_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_LBL_KEY, header_rblbl_2_lbl);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY, protocol_te);
+
+ /* Line 3 */
+ header_rblbl_3_hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_3_hb, FALSE, FALSE, 2);
+
+ header_udp_rb = gtk_radio_button_new_with_label(header_grp, "UDP");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames", NULL);
+#endif
+ header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_udp_rb));
+ g_signal_connect(header_udp_rb, "toggled", G_CALLBACK(header_udp_rb_toggle), header_frm);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_udp_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY, header_udp_rb);
+
+ header_rblbl_3_lbl = gtk_label_new(" Source port:");
+ gtk_box_pack_end(GTK_BOX(header_rblbl_3_hb), header_rblbl_3_lbl, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(header_rblbl_3_lbl), 1.0f, 0.5f);
+
+ src_port_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(src_port_te, "The source port to set in the UDP, TCP or SCTP header");
+#else
+ gtk_tooltips_set_tip(tooltips, src_port_te, "The source port to set in the UDP, TCP or SCTP header", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(header_entries_vb), src_port_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_LBL_KEY, header_rblbl_3_lbl);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY, src_port_te);
+
+ /* Line 4 */
+ header_rblbl_4_hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_4_hb, FALSE, FALSE, 2);
+
+ header_tcp_rb = gtk_radio_button_new_with_label(header_grp, "TCP");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames", NULL);
+#endif
+ header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_tcp_rb));
+ g_signal_connect(header_tcp_rb, "toggled", G_CALLBACK(header_tcp_rb_toggle), header_frm);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_tcp_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY, header_tcp_rb);
+
+ header_rblbl_4_lbl = gtk_label_new(" Destination port:");
+ gtk_box_pack_end(GTK_BOX(header_rblbl_4_hb), header_rblbl_4_lbl, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(header_rblbl_4_lbl), 1.0f, 0.5f);
+
+ dst_port_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(dst_port_te, "The destination port to set in the UDP, TCP or SCTP header");
+#else
+ gtk_tooltips_set_tip(tooltips, dst_port_te, "The destination port to set in the UDP, TCP or SCTP header", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(header_entries_vb), dst_port_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_LBL_KEY, header_rblbl_4_lbl);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY, dst_port_te);
+
+ /* Line 5 */
+ header_rblbl_5_hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_5_hb, FALSE, FALSE, 2);
+
+ header_sctp_rb = gtk_radio_button_new_with_label(header_grp, "SCTP");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames", NULL);
+#endif
+ header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_rb));
+ g_signal_connect(header_sctp_rb, "toggled", G_CALLBACK(header_sctp_rb_toggle), header_frm);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_sctp_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY, header_sctp_rb);
+
+ header_rblbl_5_lbl = gtk_label_new(" Tag:");
+ gtk_box_pack_end(GTK_BOX(header_rblbl_5_hb), header_rblbl_5_lbl, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(header_rblbl_5_lbl), 1.0f, 0.5f);
+
+ tag_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(tag_te, "The verification tag to set in the SCTP header");
+#else
+ gtk_tooltips_set_tip(tooltips, tag_te, "The verification tag to set in the SCTP header", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(header_entries_vb), tag_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_LBL_KEY, header_rblbl_5_lbl);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY, tag_te);
+
+ /* Line 6 */
+ header_rblbl_6_hb = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_6_hb, FALSE, FALSE, 2);
+
+ header_sctp_data_rb = gtk_radio_button_new_with_label(header_grp, "SCTP (DATA)");
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames");
+#else
+ gtk_tooltips_set_tip(tooltips, header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames", NULL);
+#endif
+ header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_data_rb));
+ g_signal_connect(header_sctp_data_rb, "toggled", G_CALLBACK(header_sctp_data_rb_toggle), header_frm);
+ gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_sctp_data_rb, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY, header_sctp_data_rb);
+
+ header_rblbl_6_lbl = gtk_label_new(" PPI:");
+ gtk_box_pack_end(GTK_BOX(header_rblbl_6_hb), header_rblbl_6_lbl, TRUE, TRUE, 0);
+ gtk_misc_set_alignment(GTK_MISC(header_rblbl_6_lbl), 1.0f, 0.5f);
+
+ ppi_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(ppi_te, "The payload protocol identifier to set in the SCTP DATA header");
+#else
+ gtk_tooltips_set_tip(tooltips, ppi_te, "The payload protocol identifier to set in the SCTP DATA header", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(header_entries_vb), ppi_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_LBL_KEY, header_rblbl_6_lbl);
+ g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY, ppi_te);
+
+ /* Set sensitivity */
+ g_signal_connect(header_cb, "toggled", G_CALLBACK(header_cb_toggle), header_frm);
+ g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", header_frm);
+
+ g_signal_emit_by_name(G_OBJECT(header_eth_rb), "toggled", header_frm);
+
+ g_signal_connect(encap_co, "changed", G_CALLBACK(encap_co_changed), header_frm);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
+
+ /* Frame length */
+ framelen_hb = gtk_hbox_new(FALSE, 3);
+ gtk_container_set_border_width(GTK_CONTAINER(framelen_hb), 3);
+ gtk_box_pack_start(GTK_BOX(import_vb), framelen_hb, FALSE, FALSE, 0);
+
+ framelen_lbl = gtk_label_new("Max. frame length:");
+ gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_lbl, FALSE, FALSE, 0);
+
+ framelen_te = gtk_entry_new();
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)");
+#else
+ gtk_tooltips_set_tip(tooltips, framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)", NULL);
+#endif
+ gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_te, FALSE, FALSE, 0);
+
+ g_object_set_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY, framelen_te);
+
+ /* Setup the button row */
+
+ bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
+ gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
+
+ help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
+ /* TODO: Create a Help chapter, make a proper reference, add it to help_dlg */
+ g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CONTENT);
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(help_bt, "Show topic specific help");
+#else
+ gtk_tooltips_set_tip(tooltips, help_bt, "Show topic specific help", NULL);
+#endif
+
+ close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
+ window_set_cancel_button(main_w, close_bt, window_cancel_button_cb);
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
+#else
+ gtk_tooltips_set_tip(tooltips, close_bt, "Close this dialog", NULL);
+#endif
+
+ ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
+ g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_import_ok_cb), main_w);
+ gtk_widget_grab_default(ok_bt);
+#if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text(ok_bt, "Import the selected file into a temporary capture file");
+#else
+ gtk_tooltips_set_tip(tooltips, ok_bt, "Import the selected file into a temporary capture file", NULL);
+#endif
+
+ /* Setup widget handling */
+
+ g_signal_connect(main_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
+ g_signal_connect(main_w, "destroy", G_CALLBACK(file_import_dlg_destroy_cb), NULL);
+
+ gtk_widget_show_all(main_w);
+ window_present(main_w);
+
+ return main_w;
+}
+
+void
+file_import_cmd_cb(GtkWidget *widget _U_)
+{
+ /* Do we have an encapsulation type list? */
+ if (!encap_list_store)
+ {
+ /* No. Create one. */
+ create_encap_list_store();
+ }
+
+ /* Has a file import dialog already been opened? */
+ if (file_import_dlg_w)
+ {
+ /* Yes. Just re-activate that dialog box. */
+ reactivate_window(file_import_dlg_w);
+ } else {
+ /* No. Create one */
+ file_import_dlg_w = file_import_dlg_new();
+ }
+
+ return;
+}
+
diff --git a/gtk/file_import_dlg.h b/gtk/file_import_dlg.h
new file mode 100644
index 0000000000..573c0eb486
--- /dev/null
+++ b/gtk/file_import_dlg.h
@@ -0,0 +1,31 @@
+/* file_import_dlg.h
+ * Definitions for file import dialog box
+ * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
+ *
+ * $Id$
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __FILE_IMPORT_DLG_H__
+#define __FILE_IMPORT_DLG_H__
+
+void file_import_cmd_cb(GtkWidget *widget);
+
+#endif /* file_import_dlg.h */
diff --git a/gtk/menus.c b/gtk/menus.c
index 35811579c4..4b444a4bb5 100644
--- a/gtk/menus.c
+++ b/gtk/menus.c
@@ -60,6 +60,7 @@
#include "gtk/dlg_utils.h"
#include "gtk/capture_file_dlg.h"
#include "gtk/fileset_dlg.h"
+#include "gtk/file_import_dlg.h"
#include "gtk/find_dlg.h"
#include "gtk/goto_dlg.h"
#include "gtk/summary_dlg.h"
@@ -1004,6 +1005,7 @@ static const char *ui_desc_menubar =
" <placeholder name='RecentFiles'/>\n"
" </menu>\n"
" <menuitem name='Merge' action='/File/Merge'/>\n"
+" <menuitem name='Import' action='/File/Import'/>\n"
" <menuitem name='Close' action='/File/Close'/>\n"
" <separator/>\n"
" <menuitem name='Save' action='/File/Save'/>\n"
@@ -1313,6 +1315,7 @@ static const GtkActionEntry main_menu_bar_entries[] = {
{ "/File/Open", GTK_STOCK_OPEN, "_Open...", "<control>O", "Open a file", G_CALLBACK(file_open_cmd_cb) },
{ "/File/OpenRecent", NULL, "Open _Recent", NULL, NULL, NULL },
{ "/File/Merge", NULL, "_Merge...", NULL, NULL, G_CALLBACK(file_merge_cmd_cb) },
+ { "/File/Import", NULL, "_Import...", NULL, NULL, G_CALLBACK(file_import_cmd_cb) },
{ "/File/Close", GTK_STOCK_CLOSE, "_Close", "<control>W", NULL, G_CALLBACK(file_close_cmd_cb) },
{ "/File/Save", GTK_STOCK_SAVE, "_Save", "<control>S", NULL, G_CALLBACK(file_save_cmd_cb) },
@@ -1673,6 +1676,7 @@ static GtkItemFactoryEntry menu_items[] =
0, "<StockItem>", GTK_STOCK_OPEN,},
{"/File/Open _Recent", NULL, NULL, 0, "<Branch>", NULL,},
{"/File/_Merge...", NULL, GTK_MENU_FUNC(file_merge_cmd_cb), 0, NULL, NULL,},
+ {"/File/_Import...", NULL, GTK_MENU_FUNC(file_import_cmd_cb), 0, NULL, NULL,},
{"/File/_Close", "<control>W", GTK_MENU_FUNC(file_close_cmd_cb),
0, "<StockItem>", GTK_STOCK_CLOSE,},
{"/File/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
diff --git a/gtk/text_import.c b/gtk/text_import.c
new file mode 100644
index 0000000000..bbee61a803
--- /dev/null
+++ b/gtk/text_import.c
@@ -0,0 +1,973 @@
+/* text_import.c
+ * State machine for text import
+ * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * Based on text2pcap.c by Ashok Narayanan <ashokn@cisco.com>
+ *
+ * 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.
+ */
+
+/*******************************************************************************
+ *
+ * This utility reads in an ASCII hexdump of this common format:
+ *
+ * 00000000 00 E0 1E A7 05 6F 00 10 5A A0 B9 12 08 00 46 00 .....o..Z.....F.
+ * 00000010 03 68 00 00 00 00 0A 2E EE 33 0F 19 08 7F 0F 19 .h.......3......
+ * 00000020 03 80 94 04 00 00 10 01 16 A2 0A 00 03 50 00 0C .............P..
+ * 00000030 01 01 0F 19 03 80 11 01 1E 61 00 0C 03 01 0F 19 .........a......
+ *
+ * Each bytestring line consists of an offset, one or more bytes, and
+ * text at the end. An offset is defined as a hex string of more than
+ * two characters. A byte is defined as a hex string of exactly two
+ * characters. The text at the end is ignored, as is any text before
+ * the offset. Bytes read from a bytestring line are added to the
+ * current packet only if all the following conditions are satisfied:
+ *
+ * - No text appears between the offset and the bytes (any bytes appearing after
+ * such text would be ignored)
+ *
+ * - The offset must be arithmetically correct, i.e. if the offset is 00000020, then
+ * exactly 32 bytes must have been read into this packet before this. If the offset
+ * is wrong, the packet is immediately terminated
+ *
+ * A packet start is signalled by a zero offset.
+ *
+ * Lines starting with #TEXT2PCAP are directives. These allow the user
+ * to embed instructions into the capture file which allows text2pcap
+ * to take some actions (e.g. specifying the encapsulation
+ * etc.). Currently no directives are implemented.
+ *
+ * Lines beginning with # which are not directives are ignored as
+ * comments. Currently all non-hexdump text is ignored by text2pcap;
+ * in the future, text processing may be added, but lines prefixed
+ * with '#' will still be ignored.
+ *
+ * The output is a libpcap packet containing Ethernet frames by
+ * default. This program takes options which allow the user to add
+ * dummy Ethernet, IP and UDP or TCP headers to the packets in order
+ * to allow dumps of L3 or higher protocols to be decoded.
+ *
+ * Considerable flexibility is built into this code to read hexdumps
+ * of slightly different formats. For example, any text prefixing the
+ * hexdump line is dropped (including mail forwarding '>'). The offset
+ * can be any hex number of four digits or greater.
+ *
+ * This converter cannot read a single packet greater than 64K. Packet
+ * snaplength is automatically set to 64K.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/*
+ * Just make sure we include the prototype for strptime as well
+ * (needed for glibc 2.2) but make sure we do this only if not
+ * yet defined.
+ */
+#ifndef __USE_XOPEN
+# define __USE_XOPEN
+#endif
+#ifndef _XOPEN_SOURCE
+# define _XOPEN_SOURCE
+#endif
+
+/*
+ * Defining _XOPEN_SOURCE is needed on some platforms, e.g. platforms
+ * using glibc, to expand the set of things system header files define.
+ *
+ * Unfortunately, on other platforms, such as some versions of Solaris
+ * (including Solaris 10), it *reduces* that set as well, causing
+ * strptime() not to be declared, presumably because the version of the
+ * X/Open spec that _XOPEN_SOURCE implies doesn't include strptime() and
+ * blah blah blah namespace pollution blah blah blah.
+ *
+ * So we define __EXTENSIONS__ so that "strptime()" is declared.
+ */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wsutil/file_util.h>
+
+#include <time.h>
+#include <glib.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <errno.h>
+#include <assert.h>
+
+#include <epan/tvbuff.h>
+#include <epan/crc32.h>
+#include <epan/in_cksum.h>
+
+#ifdef NEED_STRPTIME_H
+# include "wsutil/strptime.h"
+#endif
+
+#include "text_import.h"
+
+/*--- Options --------------------------------------------------------------------*/
+
+/* Debug level */
+static int debug = 0;
+
+/* Dummy Ethernet header */
+static int hdr_ethernet = FALSE;
+static unsigned long hdr_ethernet_proto = 0;
+
+/* Dummy IP header */
+static int hdr_ip = FALSE;
+static long hdr_ip_proto = 0;
+
+/* Dummy UDP header */
+static int hdr_udp = FALSE;
+static unsigned long hdr_dest_port = 0;
+static unsigned long hdr_src_port = 0;
+
+/* Dummy TCP header */
+static int hdr_tcp = FALSE;
+
+/* Dummy SCTP header */
+static int hdr_sctp = FALSE;
+static unsigned long hdr_sctp_src = 0;
+static unsigned long hdr_sctp_dest = 0;
+static unsigned long hdr_sctp_tag = 0;
+
+/* Dummy DATA chunk header */
+static int hdr_data_chunk = FALSE;
+static unsigned char hdr_data_chunk_type = 0;
+static unsigned char hdr_data_chunk_bits = 3;
+static unsigned long hdr_data_chunk_tsn = 0;
+static unsigned short hdr_data_chunk_sid = 0;
+static unsigned short hdr_data_chunk_ssn = 0;
+static unsigned long hdr_data_chunk_ppid = 0;
+
+
+/*--- Local data -----------------------------------------------------------------*/
+
+/* This is where we store the packet currently being built */
+static unsigned char *packet_buf;
+static unsigned long curr_offset = 0;
+static unsigned long max_offset = IMPORT_MAX_PACKET;
+static unsigned long packet_start = 0;
+static void start_new_packet (void);
+
+/* This buffer contains strings present before the packet offset 0 */
+#define PACKET_PREAMBLE_MAX_LEN 2048
+static unsigned char packet_preamble[PACKET_PREAMBLE_MAX_LEN+1];
+static int packet_preamble_len = 0;
+
+/* Time code of packet, derived from packet_preamble */
+static time_t ts_sec = 0;
+static guint32 ts_usec = 0;
+static char *ts_fmt = NULL;
+static struct tm timecode_default;
+
+static wtap_dumper* wdh;
+
+/* HDR_ETH Offset base to parse */
+static unsigned long offset_base = 16;
+
+/* ----- State machine -----------------------------------------------------------*/
+
+/* Current state of parser */
+typedef enum {
+ INIT, /* Waiting for start of new packet */
+ START_OF_LINE, /* Starting from beginning of line */
+ READ_OFFSET, /* Just read the offset */
+ READ_BYTE, /* Just read a byte */
+ READ_TEXT /* Just read text - ignore until EOL */
+} parser_state_t;
+static parser_state_t state = INIT;
+
+static const char *state_str[] = {"Init",
+ "Start-of-line",
+ "Offset",
+ "Byte",
+ "Text"
+};
+
+static const char *token_str[] = {"",
+ "Byte",
+ "Offset",
+ "Directive",
+ "Text",
+ "End-of-line"
+};
+
+/* ----- Skeleton Packet Headers --------------------------------------------------*/
+
+typedef struct {
+ guint8 dest_addr[6];
+ guint8 src_addr[6];
+ guint16 l3pid;
+} hdr_ethernet_t;
+
+static hdr_ethernet_t HDR_ETHERNET = {
+ {0x20, 0x52, 0x45, 0x43, 0x56, 0x00},
+ {0x20, 0x53, 0x45, 0x4E, 0x44, 0x00},
+ 0};
+
+typedef struct {
+ guint8 ver_hdrlen;
+ guint8 dscp;
+ guint16 packet_length;
+ guint16 identification;
+ guint8 flags;
+ guint8 fragment;
+ guint8 ttl;
+ guint8 protocol;
+ guint16 hdr_checksum;
+ guint32 src_addr;
+ guint32 dest_addr;
+} hdr_ip_t;
+
+static hdr_ip_t HDR_IP =
+ {0x45, 0, 0, 0x3412, 0, 0, 0xff, 0, 0, 0x01010101, 0x02020202};
+
+static struct { /* pseudo header for checksum calculation */
+ guint32 src_addr;
+ guint32 dest_addr;
+ guint8 zero;
+ guint8 protocol;
+ guint16 length;
+} pseudoh;
+
+typedef struct {
+ guint16 source_port;
+ guint16 dest_port;
+ guint16 length;
+ guint16 checksum;
+} hdr_udp_t;
+
+static hdr_udp_t HDR_UDP = {0, 0, 0, 0};
+
+typedef struct {
+ guint16 source_port;
+ guint16 dest_port;
+ guint32 seq_num;
+ guint32 ack_num;
+ guint8 hdr_length;
+ guint8 flags;
+ guint16 window;
+ guint16 checksum;
+ guint16 urg;
+} hdr_tcp_t;
+
+static hdr_tcp_t HDR_TCP = {0, 0, 0, 0, 0x50, 0, 0, 0, 0};
+
+typedef struct {
+ guint16 src_port;
+ guint16 dest_port;
+ guint32 tag;
+ guint32 checksum;
+} hdr_sctp_t;
+
+static hdr_sctp_t HDR_SCTP = {0, 0, 0, 0};
+
+typedef struct {
+ guint8 type;
+ guint8 bits;
+ guint16 length;
+ guint32 tsn;
+ guint16 sid;
+ guint16 ssn;
+ guint32 ppid;
+} hdr_data_chunk_t;
+
+static hdr_data_chunk_t HDR_DATA_CHUNK = {0, 0, 0, 0, 0, 0, 0};
+
+/* Link-layer type; see net/bpf.h for details */
+static unsigned long pcap_link_type = 1; /* Default is DLT-EN10MB */
+
+/*----------------------------------------------------------------------
+ * Parse a single hex number
+ * Will abort the program if it can't parse the number
+ * Pass in TRUE if this is an offset, FALSE if not
+ */
+static unsigned long
+parse_num (const char *str, int offset)
+{
+ unsigned long num;
+ char *c;
+
+ num = strtoul(str, &c, offset ? offset_base : 16);
+ if (c==str) {
+ fprintf(stderr, "FATAL ERROR: Bad hex number? [%s]\n", str);
+ }
+ return num;
+}
+
+/*----------------------------------------------------------------------
+ * Write this byte into current packet
+ */
+static void
+write_byte (const char *str)
+{
+ unsigned long num;
+
+ num = parse_num(str, FALSE);
+ packet_buf[curr_offset] = (unsigned char) num;
+ curr_offset ++;
+ if (curr_offset >= max_offset) /* packet full */
+ start_new_packet();
+}
+
+/*----------------------------------------------------------------------
+ * Remove bytes from the current packet
+ */
+static void
+unwrite_bytes (unsigned long nbytes)
+{
+ curr_offset -= nbytes;
+}
+
+/*----------------------------------------------------------------------
+ * Determin SCTP chunk padding length
+ */
+static unsigned long
+number_of_padding_bytes (unsigned long length)
+{
+ unsigned long remainder;
+
+ remainder = length % 4;
+
+ if (remainder == 0)
+ return 0;
+ else
+ return 4 - remainder;
+}
+
+/*----------------------------------------------------------------------
+ * Write current packet out
+ */
+void
+write_current_packet (void)
+{
+ int prefix_length = 0;
+ int proto_length = 0;
+ int ip_length = 0;
+ int eth_trailer_length = 0;
+ int prefix_index = 0;
+ int i, padding_length;
+
+ if (curr_offset > 0) {
+ /* Write the packet */
+
+ /* Compute packet length */
+ prefix_length = 0;
+ if (hdr_data_chunk) { prefix_length += sizeof(HDR_DATA_CHUNK); }
+ if (hdr_sctp) { prefix_length += sizeof(HDR_SCTP); }
+ if (hdr_udp) { prefix_length += sizeof(HDR_UDP); proto_length = prefix_length + curr_offset; }
+ if (hdr_tcp) { prefix_length += sizeof(HDR_TCP); proto_length = prefix_length + curr_offset; }
+ if (hdr_ip) {
+ prefix_length += sizeof(HDR_IP);
+ ip_length = prefix_length + curr_offset + ((hdr_data_chunk) ? number_of_padding_bytes(curr_offset) : 0);
+ }
+ if (hdr_ethernet) { prefix_length += sizeof(HDR_ETHERNET); }
+
+ /* Make room for dummy header */
+ memmove(&packet_buf[prefix_length], packet_buf, curr_offset);
+
+ if (hdr_ethernet) {
+ /* Pad trailer */
+ if (prefix_length + curr_offset < 60) {
+ eth_trailer_length = 60 - (prefix_length + curr_offset);
+ }
+ }
+
+ /* Write Ethernet header */
+ if (hdr_ethernet) {
+ HDR_ETHERNET.l3pid = g_htons(hdr_ethernet_proto);
+ memcpy(&packet_buf[prefix_index], &HDR_ETHERNET, sizeof(HDR_ETHERNET));
+ prefix_index += sizeof(HDR_ETHERNET);
+ }
+
+ /* Write IP header */
+ if (hdr_ip) {
+ vec_t cksum_vector[1];
+
+ HDR_IP.packet_length = g_htons(ip_length);
+ HDR_IP.protocol = (guint8) hdr_ip_proto;
+ HDR_IP.hdr_checksum = 0;
+ cksum_vector[0].ptr = (guint8 *)&HDR_IP; cksum_vector[0].len = sizeof(HDR_IP);
+ HDR_IP.hdr_checksum = in_cksum(cksum_vector, 1);
+
+ memcpy(&packet_buf[prefix_index], &HDR_IP, sizeof(HDR_IP));
+ prefix_index += sizeof(HDR_IP);
+ }
+
+ /* initialize pseudo header for checksum calculation */
+ pseudoh.src_addr = HDR_IP.src_addr;
+ pseudoh.dest_addr = HDR_IP.dest_addr;
+ pseudoh.zero = 0;
+ pseudoh.protocol = (guint8) hdr_ip_proto;
+ pseudoh.length = g_htons(proto_length);
+
+ /* Write UDP header */
+ if (hdr_udp) {
+ vec_t cksum_vector[3];
+
+ HDR_UDP.source_port = g_htons(hdr_src_port);
+ HDR_UDP.dest_port = g_htons(hdr_dest_port);
+ HDR_UDP.length = g_htons(proto_length);
+
+ HDR_UDP.checksum = 0;
+ cksum_vector[0].ptr = (guint8 *)&pseudoh; cksum_vector[0].len = sizeof(pseudoh);
+ cksum_vector[1].ptr = (guint8 *)&HDR_UDP; cksum_vector[1].len = sizeof(HDR_UDP);
+ cksum_vector[2].ptr = &packet_buf[prefix_length]; cksum_vector[2].len = curr_offset;
+ HDR_UDP.checksum = in_cksum(cksum_vector, 3);
+
+ memcpy(&packet_buf[prefix_index], &HDR_UDP, sizeof(HDR_UDP));
+ prefix_index += sizeof(HDR_UDP);
+ }
+
+ /* Write TCP header */
+ if (hdr_tcp) {
+ vec_t cksum_vector[3];
+
+ HDR_TCP.source_port = g_htons(hdr_src_port);
+ HDR_TCP.dest_port = g_htons(hdr_dest_port);
+ /* HDR_TCP.seq_num already correct */
+ HDR_TCP.window = g_htons(0x2000);
+
+ HDR_TCP.checksum = 0;
+ cksum_vector[0].ptr = (guint8 *)&pseudoh; cksum_vector[0].len = sizeof(pseudoh);
+ cksum_vector[1].ptr = (guint8 *)&HDR_TCP; cksum_vector[1].len = sizeof(HDR_TCP);
+ cksum_vector[2].ptr = &packet_buf[prefix_length]; cksum_vector[2].len = curr_offset;
+ HDR_TCP.checksum = in_cksum(cksum_vector, 3);
+
+ memcpy(&packet_buf[prefix_index], &HDR_TCP, sizeof(HDR_TCP));
+ prefix_index += sizeof(HDR_TCP);
+ }
+
+ /* Compute DATA chunk header and append padding */
+ if (hdr_data_chunk) {
+ HDR_DATA_CHUNK.type = hdr_data_chunk_type;
+ HDR_DATA_CHUNK.bits = hdr_data_chunk_bits;
+ HDR_DATA_CHUNK.length = g_htons(curr_offset + sizeof(HDR_DATA_CHUNK));
+ HDR_DATA_CHUNK.tsn = g_htonl(hdr_data_chunk_tsn);
+ HDR_DATA_CHUNK.sid = g_htons(hdr_data_chunk_sid);
+ HDR_DATA_CHUNK.ssn = g_htons(hdr_data_chunk_ssn);
+ HDR_DATA_CHUNK.ppid = g_htonl(hdr_data_chunk_ppid);
+
+ padding_length = number_of_padding_bytes(curr_offset);
+ for (i=0; i<padding_length; i++)
+ packet_buf[prefix_length+curr_offset+i] = 0;
+ curr_offset += padding_length;
+ }
+
+ /* Write SCTP header */
+ if (hdr_sctp) {
+ HDR_SCTP.src_port = g_htons(hdr_sctp_src);
+ HDR_SCTP.dest_port = g_htons(hdr_sctp_dest);
+ HDR_SCTP.tag = g_htonl(hdr_sctp_tag);
+ HDR_SCTP.checksum = g_htonl(0);
+
+ HDR_SCTP.checksum = crc32c_calculate(&HDR_SCTP, sizeof(HDR_SCTP), CRC32C_PRELOAD);
+ if (hdr_data_chunk)
+ HDR_SCTP.checksum = crc32c_calculate(&HDR_DATA_CHUNK, sizeof(HDR_DATA_CHUNK), HDR_SCTP.checksum);
+ HDR_SCTP.checksum = g_htonl(~crc32c_calculate(&packet_buf[prefix_length], curr_offset, HDR_SCTP.checksum));
+
+ memcpy(&packet_buf[prefix_index], &HDR_SCTP, sizeof(HDR_SCTP));
+ prefix_index += sizeof(HDR_SCTP);
+ }
+
+ /* Write DATA chunk header */
+ if (hdr_data_chunk) {
+ memcpy(&packet_buf[prefix_index], &HDR_DATA_CHUNK, sizeof(HDR_DATA_CHUNK));
+ prefix_index += sizeof(HDR_DATA_CHUNK);
+ }
+
+ /* Write Ethernet trailer */
+ if (hdr_ethernet && eth_trailer_length > 0) {
+ memset(&packet_buf[prefix_length+curr_offset], 0, eth_trailer_length);
+ }
+
+ HDR_TCP.seq_num = g_htonl(g_ntohl(HDR_TCP.seq_num) + curr_offset);
+
+ {
+ /* Write the packet */
+ struct wtap_pkthdr pkthdr;
+ int err;
+
+ pkthdr.ts.secs = (guint32)ts_sec;
+ pkthdr.ts.nsecs = ts_usec * 1000;
+ if (ts_fmt == NULL) { ts_usec++; } /* fake packet counter */
+ pkthdr.caplen = pkthdr.len = prefix_length + curr_offset + eth_trailer_length;;
+ pkthdr.pkt_encap = pcap_link_type;
+
+ wtap_dump(wdh, &pkthdr, NULL, packet_buf, &err);
+ }
+ }
+
+ packet_start += curr_offset;
+ curr_offset = 0;
+}
+
+
+/*----------------------------------------------------------------------
+ * Append a token to the packet preamble.
+ */
+static void
+append_to_preamble(char *str)
+{
+ size_t toklen;
+
+ if (packet_preamble_len != 0) {
+ if (packet_preamble_len == PACKET_PREAMBLE_MAX_LEN)
+ return; /* no room to add more preamble */
+ /* Add a blank separator between the previous token and this token. */
+ packet_preamble[packet_preamble_len++] = ' ';
+ }
+ toklen = strlen(str);
+ if (toklen != 0) {
+ if (packet_preamble_len + toklen > PACKET_PREAMBLE_MAX_LEN)
+ return; /* no room to add the token to the preamble */
+ g_strlcpy(&packet_preamble[packet_preamble_len], str, PACKET_PREAMBLE_MAX_LEN);
+ packet_preamble_len += (int) toklen;
+ if (debug >= 2) {
+ char *c;
+ char xs[PACKET_PREAMBLE_MAX_LEN];
+ g_strlcpy(xs, packet_preamble, PACKET_PREAMBLE_MAX_LEN);
+ while ((c = strchr(xs, '\r')) != NULL) *c=' ';
+ fprintf (stderr, "[[append_to_preamble: \"%s\"]]", xs);
+ }
+ }
+}
+
+/*----------------------------------------------------------------------
+ * Parse the preamble to get the timecode.
+ */
+
+static void
+parse_preamble (void)
+{
+ struct tm timecode;
+ char *subsecs;
+ char *p;
+ int subseclen;
+ int i;
+
+ /*
+ * If no "-t" flag was specified, don't attempt to parse a packet
+ * preamble to extract a time stamp.
+ */
+ if (ts_fmt == NULL)
+ return;
+
+ /*
+ * Initialize to today localtime, just in case not all fields
+ * of the date and time are specified.
+ */
+
+ timecode = timecode_default;
+ ts_usec = 0;
+
+ /*
+ * Null-terminate the preamble.
+ */
+ packet_preamble[packet_preamble_len] = '\0';
+
+ /* Ensure preamble has more than two chars before atempting to parse.
+ * This should cover line breaks etc that get counted.
+ */
+ if ( strlen(packet_preamble) > 2 ) {
+ /* Get Time leaving subseconds */
+ subsecs = strptime( packet_preamble, ts_fmt, &timecode );
+ if (subsecs != NULL) {
+ /* Get the long time from the tm structure */
+ /* (will return -1 if failure) */
+ ts_sec = mktime( &timecode );
+ } else
+ ts_sec = -1; /* we failed to parse it */
+
+ /* This will ensure incorrectly parsed dates get set to zero */
+ if ( -1 == ts_sec )
+ {
+ /* Sanitize - remove all '\r' */
+ char *c;
+ while ((c = strchr(packet_preamble, '\r')) != NULL) *c=' ';
+ fprintf (stderr, "Failure processing time \"%s\" using time format \"%s\"\n (defaulting to Jan 1,1970 00:00:00 GMT)\n",
+ packet_preamble, ts_fmt);
+ if (debug >= 2) {
+ fprintf(stderr, "timecode: %02d/%02d/%d %02d:%02d:%02d %d\n",
+ timecode.tm_mday, timecode.tm_mon, timecode.tm_year,
+ timecode.tm_hour, timecode.tm_min, timecode.tm_sec, timecode.tm_isdst);
+ }
+ ts_sec = 0; /* Jan 1,1970: 00:00 GMT; tshark/wireshark will display date/time as adjusted by timezone */
+ ts_usec = 0;
+ }
+ else
+ {
+ /* Parse subseconds */
+ ts_usec = strtol(subsecs, &p, 10);
+ if (subsecs == p) {
+ /* Error */
+ ts_usec = 0;
+ } else {
+ /*
+ * Convert that number to a number
+ * of microseconds; if it's N digits
+ * long, it's in units of 10^(-N) seconds,
+ * so, to convert it to units of
+ * 10^-6 seconds, we multiply by
+ * 10^(6-N).
+ */
+ subseclen = (int) (p - subsecs);
+ if (subseclen > 6) {
+ /*
+ * *More* than 6 digits; 6-N is
+ * negative, so we divide by
+ * 10^(N-6).
+ */
+ for (i = subseclen - 6; i != 0; i--)
+ ts_usec /= 10;
+ } else if (subseclen < 6) {
+ for (i = 6 - subseclen; i != 0; i--)
+ ts_usec *= 10;
+ }
+ }
+ }
+ }
+ if (debug >= 2) {
+ char *c;
+ while ((c = strchr(packet_preamble, '\r')) != NULL) *c=' ';
+ fprintf(stderr, "[[parse_preamble: \"%s\"]]\n", packet_preamble);
+ fprintf(stderr, "Format(%s), time(%u), subsecs(%u)\n", ts_fmt, (guint32)ts_sec, ts_usec);
+ }
+
+
+ /* Clear Preamble */
+ packet_preamble_len = 0;
+}
+
+/*----------------------------------------------------------------------
+ * Start a new packet
+ */
+static void
+start_new_packet (void)
+{
+ if (debug>=1)
+ fprintf(stderr, "Start new packet\n");
+
+ /* Write out the current packet, if required */
+ write_current_packet();
+
+ /* Ensure we parse the packet preamble as it may contain the time */
+ parse_preamble();
+}
+
+/*----------------------------------------------------------------------
+ * Process a directive
+ */
+static void
+process_directive (char *str)
+{
+ fprintf(stderr, "\n--- Directive [%s] currently unsupported ---\n", str+10);
+
+}
+
+/*----------------------------------------------------------------------
+ * Parse a single token (called from the scanner)
+ */
+void
+parse_token (token_t token, char *str)
+{
+ unsigned long num;
+
+ /*
+ * This is implemented as a simple state machine of five states.
+ * State transitions are caused by tokens being received from the
+ * scanner. The code should be self_documenting.
+ */
+
+ if (debug>=2) {
+ /* Sanitize - remove all '\r' */
+ char *c;
+ if (str!=NULL) { while ((c = strchr(str, '\r')) != NULL) *c=' '; }
+
+ fprintf(stderr, "(%s, %s \"%s\") -> (",
+ state_str[state], token_str[token], str ? str : "");
+ }
+
+ switch(state) {
+
+ /* ----- Waiting for new packet -------------------------------------------*/
+ case INIT:
+ switch(token) {
+ case T_TEXT:
+ append_to_preamble(str);
+ break;
+ case T_DIRECTIVE:
+ process_directive(str);
+ break;
+ case T_OFFSET:
+ num = parse_num(str, TRUE);
+ if (num==0) {
+ /* New packet starts here */
+ start_new_packet();
+ state = READ_OFFSET;
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /* ----- Processing packet, start of new line -----------------------------*/
+ case START_OF_LINE:
+ switch(token) {
+ case T_TEXT:
+ append_to_preamble(str);
+ break;
+ case T_DIRECTIVE:
+ process_directive(str);
+ break;
+ case T_OFFSET:
+ num = parse_num(str, TRUE);
+ if (num==0) {
+ /* New packet starts here */
+ start_new_packet();
+ packet_start = 0;
+ state = READ_OFFSET;
+ } else if ((num - packet_start) != curr_offset) {
+ /*
+ * The offset we read isn't the one we expected.
+ * This may only mean that we mistakenly interpreted
+ * some text as byte values (e.g., if the text dump
+ * of packet data included a number with spaces around
+ * it). If the offset is less than what we expected,
+ * assume that's the problem, and throw away the putative
+ * extra byte values.
+ */
+ if (num < curr_offset) {
+ unwrite_bytes(curr_offset - num);
+ state = READ_OFFSET;
+ } else {
+ /* Bad offset; switch to INIT state */
+ if (debug>=1)
+ fprintf(stderr, "Inconsistent offset. Expecting %0lX, got %0lX. Ignoring rest of packet\n",
+ curr_offset, num);
+ write_current_packet();
+ state = INIT;
+ }
+ } else
+ state = READ_OFFSET;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /* ----- Processing packet, read offset -----------------------------------*/
+ case READ_OFFSET:
+ switch(token) {
+ case T_BYTE:
+ /* Record the byte */
+ state = READ_BYTE;
+ write_byte(str);
+ break;
+ case T_TEXT:
+ case T_DIRECTIVE:
+ case T_OFFSET:
+ state = READ_TEXT;
+ break;
+ case T_EOL:
+ state = START_OF_LINE;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /* ----- Processing packet, read byte -------------------------------------*/
+ case READ_BYTE:
+ switch(token) {
+ case T_BYTE:
+ /* Record the byte */
+ write_byte(str);
+ break;
+ case T_TEXT:
+ case T_DIRECTIVE:
+ case T_OFFSET:
+ state = READ_TEXT;
+ break;
+ case T_EOL:
+ state = START_OF_LINE;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ /* ----- Processing packet, read text -------------------------------------*/
+ case READ_TEXT:
+ switch(token) {
+ case T_EOL:
+ state = START_OF_LINE;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ default:
+ fprintf(stderr, "FATAL ERROR: Bad state (%d)", state);
+ exit(-1);
+ }
+
+ if (debug>=2)
+ fprintf(stderr, ", %s)\n", state_str[state]);
+
+}
+
+/*----------------------------------------------------------------------
+ * take in the import config information
+ */
+void
+text_import_setup(text_import_info_t *info)
+{
+ packet_buf = (unsigned char *)g_malloc(sizeof(HDR_ETHERNET) + sizeof(HDR_IP) +
+ sizeof(HDR_SCTP) + sizeof(HDR_DATA_CHUNK) +
+ IMPORT_MAX_PACKET);
+
+ if (!packet_buf)
+ {
+ fprintf(stderr, "FATAL ERROR: no memory for packet buffer");
+ exit(-1);
+ }
+
+ /* Lets start from the beginning */
+ state = INIT;
+ curr_offset = 0;
+ packet_start = 0;
+ packet_preamble_len = 0;
+ ts_sec = time(0); /* initialize to current time */
+ timecode_default = *localtime(&ts_sec);
+ timecode_default.tm_isdst = -1; /* Unknown for now, depends on time given to the strptime() function */
+ ts_usec = 0;
+
+ /* Dummy headers */
+ hdr_ethernet = FALSE;
+ hdr_ip = FALSE;
+ hdr_udp = FALSE;
+ hdr_tcp = FALSE;
+ hdr_sctp = FALSE;
+ hdr_data_chunk = FALSE;
+
+ offset_base = (info->offset_type == OFFSET_HEX) ? 16 :
+ (info->offset_type == OFFSET_OCT) ? 8 :
+ (info->offset_type == OFFSET_DEC) ? 10 :
+ 16;
+
+ if (info->date_timestamp)
+ {
+ ts_fmt = info->date_timestamp_format;
+ }
+
+ pcap_link_type = info->encapsulation;
+
+ wdh = info->wdh;
+
+ switch (info->dummy_header_type)
+ {
+ case HEADER_ETH:
+ hdr_ethernet = TRUE;
+ hdr_ethernet_proto = info->pid;
+ break;
+
+ case HEADER_IPV4:
+ hdr_ip = TRUE;
+ hdr_ip_proto = info->protocol;
+ hdr_ethernet = TRUE;
+ hdr_ethernet_proto = 0x800;
+ break;
+
+ case HEADER_UDP:
+ hdr_udp = TRUE;
+ hdr_tcp = FALSE;
+ hdr_src_port = info->src_port;
+ hdr_dest_port = info->dst_port;
+ hdr_ip = TRUE;
+ hdr_ip_proto = 17;
+ hdr_ethernet = TRUE;
+ hdr_ethernet_proto = 0x800;
+ break;
+
+ case HEADER_TCP:
+ hdr_tcp = TRUE;
+ hdr_udp = FALSE;
+ hdr_src_port = info->src_port;
+ hdr_dest_port = info->dst_port;
+ hdr_ip = TRUE;
+ hdr_ip_proto = 6;
+ hdr_ethernet = TRUE;
+ hdr_ethernet_proto = 0x800;
+ break;
+
+ case HEADER_SCTP:
+ hdr_sctp = TRUE;
+ hdr_sctp_src = info->src_port;
+ hdr_sctp_dest = info->dst_port;
+ hdr_sctp_tag = info->tag;
+ hdr_ip = TRUE;
+ hdr_ip_proto = 132;
+ hdr_ethernet = TRUE;
+ hdr_ethernet_proto = 0x800;
+ break;
+
+ case HEADER_SCTP_DATA:
+ hdr_sctp = TRUE;
+ hdr_data_chunk = TRUE;
+ hdr_sctp_src = info->src_port;
+ hdr_sctp_dest = info->dst_port;
+ hdr_data_chunk_ppid = info->ppi;
+ hdr_ip = TRUE;
+ hdr_ip_proto = 132;
+ hdr_ethernet = TRUE;
+ hdr_ethernet_proto = 0x800;
+ break;
+
+ default:
+ break;
+ }
+
+ max_offset = info->max_frame_length;
+}
+
+/*----------------------------------------------------------------------
+ * Clean up after text import
+ */
+void
+text_import_cleanup(void)
+{
+ g_free(packet_buf);
+} \ No newline at end of file
diff --git a/gtk/text_import.h b/gtk/text_import.h
new file mode 100644
index 0000000000..651893622e
--- /dev/null
+++ b/gtk/text_import.h
@@ -0,0 +1,103 @@
+/**-*-C-*-**********************************************************************
+ * text_import.h
+ * State machine for text import
+ * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * Based on text2pcap.h by Ashok Narayanan <ashokn@cisco.com>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *******************************************************************************/
+
+
+#ifndef TEXT_IMPORT_H
+#define TEXT_IMPORT_H
+
+#include "glib.h"
+#include "wtap.h"
+
+#define IMPORT_MAX_PACKET 64000
+
+/* The parameter interface */
+
+enum offset_type
+{
+ OFFSET_HEX,
+ OFFSET_OCT,
+ OFFSET_DEC
+};
+
+enum dummy_header_type
+{
+ HEADER_NONE,
+ HEADER_ETH,
+ HEADER_IPV4,
+ HEADER_UDP,
+ HEADER_TCP,
+ HEADER_SCTP,
+ HEADER_SCTP_DATA
+};
+
+typedef struct
+{
+ /* Input info */
+ guchar *import_text_filename;
+ FILE *import_text_file;
+ enum offset_type offset_type;
+ gboolean date_timestamp;
+ guchar *date_timestamp_format;
+
+ /* Import info */
+ guint encapsulation;
+ wtap_dumper* wdh;
+
+ /* Dummy header info (if encapsulation == 1) */
+ enum dummy_header_type dummy_header_type;
+ guint pid;
+ guint protocol;
+ guint src_port;
+ guint dst_port;
+ guint tag;
+ guint ppi;
+
+ guint max_frame_length;
+} text_import_info_t;
+
+void text_import_setup(text_import_info_t *info);
+void text_import_cleanup();
+
+/* The lexical parser interface */
+
+typedef enum {
+ T_BYTE = 1,
+ T_OFFSET,
+ T_DIRECTIVE,
+ T_TEXT,
+ T_EOL
+} token_t;
+
+void parse_token(token_t token, char *str);
+void write_current_packet(void);
+
+void text_importset_in(FILE *input_file);
+int text_importlex(void);
+
+#endif
diff --git a/gtk/text_import_scanner.l b/gtk/text_import_scanner.l
new file mode 100644
index 0000000000..81a9e59a4c
--- /dev/null
+++ b/gtk/text_import_scanner.l
@@ -0,0 +1,101 @@
+/* -*-mode: flex-*- */
+
+/*
+ * We don't use unput, so don't generate code for it.
+ */
+%option nounput noinput
+
+/*
+ * We don't read from the terminal.
+ */
+%option never-interactive
+
+/*
+ * Prefix scanner routines with "text_import" rather than "yy", so this scanner
+ * can coexist with other scanners.
+ */
+%option prefix="text_import"
+
+%{
+
+/********************************************************************************
+ *
+ * text_import_scanner.l
+ * Scanner for text import
+ * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "text_import.h"
+
+/*
+ * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
+ */
+#ifdef _WIN32
+#define YY_NO_UNISTD_H
+#endif
+
+#ifdef _WIN32
+/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */
+/* with YY_INPUT code generated by flex versions such as 2.5.35. */
+#pragma warning (disable:4018)
+#endif
+
+%}
+
+hexdigit [0-9A-Fa-f]
+directive #TEXT2PCAP.*
+comment #[^W].*
+byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
+byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
+offset [0-9A-Fa-f]+[: \t]
+offset_eol [0-9A-Fa-f]+\r?\n
+text [^ \n\t]+
+mailfwd >
+eol \r?\n\r?
+
+%%
+
+{byte} { parse_token(T_BYTE, yytext); }
+{byte_eol} { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
+{offset} { parse_token(T_OFFSET, yytext); }
+{offset_eol} { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
+{mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
+{eol} { parse_token(T_EOL, NULL); }
+[ \t] ; /* ignore whitespace */
+{directive} { parse_token(T_DIRECTIVE, yytext); }
+{comment} ; /* ignore comments */
+{text} { parse_token(T_TEXT, yytext); }
+
+<<EOF>> { write_current_packet(); yyterminate(); }
+
+%%
+int yywrap()
+{
+ return 1;
+}