Replace "svn" with "git" all over the place.
[metze/wireshark/wip.git] / ui / gtk / file_import_dlg.c
1 /* file_import_dlg.c
2  * Dialog to setup for import of a text file, like text2pcap
3  * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
24  * USA.
25  */
26
27 #include "config.h"
28
29 #include <gtk/gtk.h>
30
31 #include <stdlib.h>
32
33 #include "globals.h"
34 #include "wtap.h"
35 #include "pcap-encap.h"
36 #include "version_info.h"
37
38 #include "ui/simple_dialog.h"
39 #include "ui/alert_box.h"
40
41 #include "ui/gtk/stock_icons.h"
42 #include "ui/gtk/dlg_utils.h"
43 #include "ui/gtk/gui_utils.h"
44 #include "ui/gtk/file_dlg.h"
45 #include "ui/gtk/capture_file_dlg.h"
46 #include "ui/gtk/help_dlg.h"
47
48 #include "ui/gtk/file_import_dlg.h"
49 #include "ui/text_import.h"
50 #include "ui/text_import_scanner.h"
51
52 #include "file.h"
53 #include "wsutil/file_util.h"
54 #include "wsutil/tempfile.h"
55
56 #define INPUT_FRM_KEY                   "input_frame"
57
58 #define INPUT_FILENAME_TE_KEY           "input_filename_text"
59
60 #define INPUT_OFFSET_HEX_RB_KEY         "input_offset_hex_radio"
61 #define INPUT_OFFSET_OCT_RB_KEY         "input_offset_oct_radio"
62 #define INPUT_OFFSET_DEC_RB_KEY         "input_offset_dec_radio"
63
64 #define INPUT_DATETIME_CB_KEY           "input_datetime_checkbox"
65 #define INPUT_TIMEFMT_LBL_KEY           "input_timeformat_label"
66 #define INPUT_TIMEFMT_TE_KEY            "input_timeformat_entry"
67
68 #define INPUT_DIR_CB_KEY                "input_direction_indication_checkbox"
69
70 #define IMPORT_FRM_KEY                  "import_frame"
71 #define IMPORT_ENCAP_CO_KEY             "import_encap_combo"
72
73 #define IMPORT_HEADER_FRM_KEY           "import_header_frame"
74 #define IMPORT_HEADER_CB_KEY            "import_header_checkbox"
75 #define IMPORT_HEADER_ETH_RB_KEY        "import_header_ethernet_radio"
76 #define IMPORT_HEADER_ETYPE_LBL_KEY     "import_header_etype_label"
77 #define IMPORT_HEADER_ETYPE_TE_KEY      "import_header_etype_text"
78 #define IMPORT_HEADER_IPV4_RB_KEY       "import_header_ipv4_radio"
79 #define IMPORT_HEADER_PROT_LBL_KEY      "import_header_prot_label"
80 #define IMPORT_HEADER_PROT_TE_KEY       "import_header_prot_text"
81 #define IMPORT_HEADER_UDP_RB_KEY        "import_header_udp_radio"
82 #define IMPORT_HEADER_SRC_PORT_LBL_KEY  "import_header_src_port_label"
83 #define IMPORT_HEADER_SRC_PORT_TE_KEY   "import_header_src_port_text"
84 #define IMPORT_HEADER_TCP_RB_KEY        "import_header_tcp_radio"
85 #define IMPORT_HEADER_DST_PORT_LBL_KEY  "import_header_dst_port_label"
86 #define IMPORT_HEADER_DST_PORT_TE_KEY   "import_header_dst_port_text"
87 #define IMPORT_HEADER_SCTP_RB_KEY       "import_header_sctp_radio"
88 #define IMPORT_HEADER_TAG_LBL_KEY       "import_header_tag_label"
89 #define IMPORT_HEADER_TAG_TE_KEY        "import_header_tag_text"
90 #define IMPORT_HEADER_SCTP_D_RB_KEY     "import_header_sctp_data_radio"
91 #define IMPORT_HEADER_PPI_LBL_KEY       "import_header_ppi_label"
92 #define IMPORT_HEADER_PPI_TE_KEY        "import_header_ppi_text"
93
94 #define IMPORT_FRAME_LENGTH_TE_KEY      "import_frame_length_text"
95
96 static GtkWidget    *file_import_dlg_w = NULL;
97 static GtkListStore *encap_list_store  = NULL;
98
99 /*****************************************************************************/
100
101 static void
102 file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
103 {
104     file_import_dlg_w = NULL;
105 }
106
107 /*****************************************************************************/
108
109 static void
110 browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
111 {
112     file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Hex Dump",
113         FILE_SELECTION_READ_BROWSE);
114 }
115
116 static void
117 timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
118 {
119     GtkWidget *timefmt_lbl, *timefmt_te;
120     gboolean   apply_fmt;
121
122     timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
123     timefmt_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
124
125     apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
126     gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
127     gtk_widget_set_sensitive(timefmt_te, apply_fmt);
128 }
129
130 enum
131 {
132     ENCAP_NAME_COLUMN,
133     ENCAP_VALUE_COLUMN
134 };
135
136 /*****************************************************************************/
137 static void
138 create_encap_list_store(void)
139 {
140     GtkTreeIter  iter;
141     gint         encap;
142     const gchar *name;
143     GtkTreeSortable *sortable;
144     GtkSortType order = GTK_SORT_ASCENDING;
145
146     encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
147     sortable = GTK_TREE_SORTABLE(encap_list_store);
148     gtk_tree_sortable_set_sort_func(sortable, ENCAP_NAME_COLUMN,
149         str_ptr_sort_func, GINT_TO_POINTER(ENCAP_NAME_COLUMN), NULL);
150     gtk_tree_sortable_set_sort_column_id(sortable, ENCAP_NAME_COLUMN, order);
151
152     /* Scan all Wiretap encapsulation types */
153     for (encap = 1; encap < wtap_get_num_encap_types(); encap++) {
154         /* Check if we can write to a PCAP file
155          *
156          * Exclude wtap encapsulations that require a pseudo header,
157          * because we won't setup one from the text we import and
158          * wiretap doesn't allow us to write 'raw' frames
159          */
160         if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) && !wtap_encap_requires_phdr(encap)) {
161             /* If it has got a name */
162             if ((name = wtap_encap_string(encap))) {
163                 gtk_list_store_append(encap_list_store, &iter);
164                 gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
165             }
166         }
167     }
168 }
169
170 static GtkWidget *
171 fill_encap_combo(void)
172 {
173     GtkWidget       *encap_co;
174     GtkCellRenderer *cell;
175
176     encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
177     cell = gtk_cell_renderer_text_new();
178     gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
179     gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
180
181     return encap_co;
182 }
183
184 static void header_frm_child_set(GtkWidget *widget, gpointer data);
185
186 static void
187 encap_co_changed(GtkComboBox *widget, gpointer data)
188 {
189     GtkTreeIter  iter;
190     gboolean     result;
191     GtkWidget   *header_cb;
192
193     result = gtk_combo_box_get_active_iter(widget, &iter);
194
195     if (result) {
196         guint encap;
197         GtkTreeModel *model = gtk_combo_box_get_model(widget);
198         gtk_tree_model_get(model, &iter, ENCAP_VALUE_COLUMN, &encap, -1);
199
200         if (encap != WTAP_ENCAP_ETHERNET)
201             result = FALSE;
202     }
203
204     if (result) {
205         header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
206         g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
207     } else {
208         gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
209     }
210 }
211
212 /*****************************************************************************/
213
214 static void
215 header_frm_child_set(GtkWidget *widget, gpointer data)
216 {
217     gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
218 }
219
220 static void
221 header_cb_toggle(GtkWidget *widget, gpointer data)
222 {
223     gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
224         GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
225     /* The frame's checkbox must stay sensitive, of course... */
226     gtk_widget_set_sensitive(widget, TRUE);
227 }
228
229 /*
230  * Header radio button toggle handlers
231  */
232 static void
233 header_eth_rb_toggle(GtkWidget *widget, gpointer data)
234 {
235     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
236     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
237     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
238     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
239     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
240     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
241     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
242     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
243     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
244     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
245     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
246     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
247
248     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
249         gtk_widget_set_sensitive(etype_lbl,    TRUE);
250         gtk_widget_set_sensitive(etype_te,     TRUE);
251         gtk_widget_set_sensitive(prot_lbl,     FALSE);
252         gtk_widget_set_sensitive(prot_te,      FALSE);
253         gtk_widget_set_sensitive(src_port_lbl, FALSE);
254         gtk_widget_set_sensitive(src_port_te,  FALSE);
255         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
256         gtk_widget_set_sensitive(dst_port_te,  FALSE);
257         gtk_widget_set_sensitive(tag_lbl,      FALSE);
258         gtk_widget_set_sensitive(tag_te,       FALSE);
259         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
260         gtk_widget_set_sensitive(ppi_te,       FALSE);
261     } else {
262         gtk_widget_set_sensitive(etype_lbl,    FALSE);
263         gtk_widget_set_sensitive(etype_te,     FALSE);
264     }
265 }
266
267 static void
268 header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
269 {
270     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
271     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
272     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
273     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
274     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
275     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
276     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
277     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
278     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
279     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
280     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
281     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
282
283     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
284         gtk_widget_set_sensitive(etype_lbl,    FALSE);
285         gtk_widget_set_sensitive(etype_te,     FALSE);
286         gtk_widget_set_sensitive(prot_lbl,     TRUE);
287         gtk_widget_set_sensitive(prot_te,      TRUE);
288         gtk_widget_set_sensitive(src_port_lbl, FALSE);
289         gtk_widget_set_sensitive(src_port_te,  FALSE);
290         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
291         gtk_widget_set_sensitive(dst_port_te,  FALSE);
292         gtk_widget_set_sensitive(tag_lbl,      FALSE);
293         gtk_widget_set_sensitive(tag_te,       FALSE);
294         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
295         gtk_widget_set_sensitive(ppi_te,       FALSE);
296     } else {
297         gtk_widget_set_sensitive(prot_lbl,     FALSE);
298         gtk_widget_set_sensitive(prot_te,      FALSE);
299     }
300 }
301
302 static void
303 header_udp_rb_toggle(GtkWidget *widget, gpointer data)
304 {
305     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
306     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
307     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
308     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
309     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
310     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
311     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
312     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
313     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
314     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
315     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
316     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
317
318     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
319         gtk_widget_set_sensitive(etype_lbl,    FALSE);
320         gtk_widget_set_sensitive(etype_te,     FALSE);
321         gtk_widget_set_sensitive(prot_lbl,     FALSE);
322         gtk_widget_set_sensitive(prot_te,      FALSE);
323         gtk_widget_set_sensitive(src_port_lbl, TRUE);
324         gtk_widget_set_sensitive(src_port_te,  TRUE);
325         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
326         gtk_widget_set_sensitive(dst_port_te,  TRUE);
327         gtk_widget_set_sensitive(tag_lbl,      FALSE);
328         gtk_widget_set_sensitive(tag_te,       FALSE);
329         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
330         gtk_widget_set_sensitive(ppi_te,       FALSE);
331     } else {
332         gtk_widget_set_sensitive(src_port_lbl, FALSE);
333         gtk_widget_set_sensitive(src_port_te,  FALSE);
334         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
335         gtk_widget_set_sensitive(dst_port_te,  FALSE);
336     }
337 }
338
339 static void
340 header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
341 {
342     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
343     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
344     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
345     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
346     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
347     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
348     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
349     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
350     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
351     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
352     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
353     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
354
355     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
356         gtk_widget_set_sensitive(etype_lbl,    FALSE);
357         gtk_widget_set_sensitive(etype_te,     FALSE);
358         gtk_widget_set_sensitive(prot_lbl,     FALSE);
359         gtk_widget_set_sensitive(prot_te,      FALSE);
360         gtk_widget_set_sensitive(src_port_lbl, TRUE);
361         gtk_widget_set_sensitive(src_port_te,  TRUE);
362         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
363         gtk_widget_set_sensitive(dst_port_te,  TRUE);
364         gtk_widget_set_sensitive(tag_lbl,      FALSE);
365         gtk_widget_set_sensitive(tag_te,       FALSE);
366         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
367         gtk_widget_set_sensitive(ppi_te,       FALSE);
368     } else {
369         gtk_widget_set_sensitive(src_port_lbl, FALSE);
370         gtk_widget_set_sensitive(src_port_te,  FALSE);
371         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
372         gtk_widget_set_sensitive(dst_port_te,  FALSE);
373     }
374 }
375
376 static void
377 header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
378 {
379     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
380     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
381     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
382     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
383     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
384     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
385     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
386     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
387     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
388     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
389     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
390     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
391
392     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
393         gtk_widget_set_sensitive(etype_lbl,    FALSE);
394         gtk_widget_set_sensitive(etype_te,     FALSE);
395         gtk_widget_set_sensitive(prot_lbl,     FALSE);
396         gtk_widget_set_sensitive(prot_te,      FALSE);
397         gtk_widget_set_sensitive(src_port_lbl, TRUE);
398         gtk_widget_set_sensitive(src_port_te,  TRUE);
399         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
400         gtk_widget_set_sensitive(dst_port_te,  TRUE);
401         gtk_widget_set_sensitive(tag_lbl,      TRUE);
402         gtk_widget_set_sensitive(tag_te,       TRUE);
403         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
404         gtk_widget_set_sensitive(ppi_te,       FALSE);
405     } else {
406         gtk_widget_set_sensitive(src_port_lbl, FALSE);
407         gtk_widget_set_sensitive(src_port_te,  FALSE);
408         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
409         gtk_widget_set_sensitive(dst_port_te,  FALSE);
410         gtk_widget_set_sensitive(tag_lbl,      FALSE);
411         gtk_widget_set_sensitive(tag_te,       FALSE);
412     }
413 }
414
415 static void
416 header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
417 {
418     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
419     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
420     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
421     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
422     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
423     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
424     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
425     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
426     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
427     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
428     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
429     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
430
431     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
432         gtk_widget_set_sensitive(etype_lbl,    FALSE);
433         gtk_widget_set_sensitive(etype_te,     FALSE);
434         gtk_widget_set_sensitive(prot_lbl,     FALSE);
435         gtk_widget_set_sensitive(prot_te,      FALSE);
436         gtk_widget_set_sensitive(src_port_lbl, TRUE);
437         gtk_widget_set_sensitive(src_port_te,  TRUE);
438         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
439         gtk_widget_set_sensitive(dst_port_te,  TRUE);
440         gtk_widget_set_sensitive(tag_lbl,      FALSE);
441         gtk_widget_set_sensitive(tag_te,       FALSE);
442         gtk_widget_set_sensitive(ppi_lbl,      TRUE);
443         gtk_widget_set_sensitive(ppi_te,       TRUE);
444     } else {
445         gtk_widget_set_sensitive(src_port_lbl, FALSE);
446         gtk_widget_set_sensitive(src_port_te,  FALSE);
447         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
448         gtk_widget_set_sensitive(dst_port_te,  FALSE);
449         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
450         gtk_widget_set_sensitive(ppi_te,       FALSE);
451     }
452 }
453
454 /*****************************************************************************/
455
456 static void
457 file_import_open(text_import_info_t *info)
458 {
459     int   import_file_fd;
460     char *tmpname, *capfile_name;
461     int   err;
462
463     /* pcapng defs */
464     wtapng_section_t            *shb_hdr;
465     wtapng_iface_descriptions_t *idb_inf;
466     wtapng_if_descr_t            int_data;
467     GString                     *os_info_str;
468     char                         appname[100];
469
470     /* Choose a random name for the temporary import buffer */
471     import_file_fd = create_tempfile(&tmpname, "import");
472     capfile_name = g_strdup(tmpname);
473
474     /* Create data for SHB  */
475     os_info_str = g_string_new("");
476     get_os_version_info(os_info_str);
477
478     g_snprintf(appname, sizeof(appname), "Wireshark " VERSION "%s", wireshark_gitversion);
479
480     shb_hdr = g_new(wtapng_section_t,1);
481     shb_hdr->section_length = -1;
482     /* options */
483     shb_hdr->opt_comment    = g_strdup_printf("File created by File->Import of file %s", info->import_text_filename);
484     shb_hdr->shb_hardware   = NULL;                    /* UTF-8 string containing the
485                                                        * description of the hardware used to create this section.
486                                                        */
487     shb_hdr->shb_os         = os_info_str->str;        /* UTF-8 string containing the name
488                                                        * of the operating system used to create this section.
489                                                        */
490     g_string_free(os_info_str, FALSE);                /* The actual string is not freed */
491     shb_hdr->shb_user_appl  = appname;                /* UTF-8 string containing the name
492                                                        *  of the application used to create this section.
493                                                        */
494
495
496     /* Create fake IDB info */
497     idb_inf = g_new(wtapng_iface_descriptions_t,1);
498     idb_inf->number_of_interfaces = 1;
499     idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t));
500
501     /* create the fake interface data */
502     int_data.wtap_encap            = info->encapsulation;
503     int_data.time_units_per_second = 1000000; /* default microsecond resolution */
504     int_data.link_type             = wtap_wtap_encap_to_pcap_encap(info->encapsulation);
505     int_data.snap_len              = WTAP_MAX_PACKET_SIZE;
506     int_data.if_name               = g_strdup("Fake IF File->Import");
507     int_data.opt_comment           = NULL;
508     int_data.if_description        = NULL;
509     int_data.if_speed              = 0;
510     int_data.if_tsresol            = 6;
511     int_data.if_filter_str         = NULL;
512     int_data.bpf_filter_len        = 0;
513     int_data.if_filter_bpf_bytes   = NULL;
514     int_data.if_os                 = NULL;
515     int_data.if_fcslen             = -1;
516     int_data.num_stat_entries      = 0;          /* Number of ISB:s */
517     int_data.interface_statistics  = NULL;
518
519     g_array_append_val(idb_inf->interface_data, int_data);
520
521     info->wdh = wtap_dump_fdopen_ng(import_file_fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG, info->encapsulation, info->max_frame_length, FALSE, shb_hdr, idb_inf, &err);
522     if (info->wdh == NULL) {
523         open_failure_alert_box(capfile_name, err, TRUE);
524         fclose(info->import_text_file);
525         goto end;
526     }
527
528     text_import_setup(info);
529
530     text_importin = info->import_text_file;
531
532     text_importlex();
533
534     text_import_cleanup();
535
536     if (fclose(info->import_text_file)) {
537         read_failure_alert_box(info->import_text_filename, errno);
538     }
539
540     if (!wtap_dump_close(info->wdh, &err)) {
541         write_failure_alert_box(capfile_name, err);
542     }
543
544     if (cf_open(&cfile, capfile_name, TRUE /* temporary file */, &err) != CF_OK) {
545         open_failure_alert_box(capfile_name, err, FALSE);
546         goto end;
547     }
548
549     switch (cf_read(&cfile, FALSE)) {
550     case CF_READ_OK:
551     case CF_READ_ERROR:
552     /* Just because we got an error, that doesn't mean we were unable
553        to read any of the file; we handle what we could get from the
554        file. */
555     break;
556
557     case CF_READ_ABORTED:
558     /* The user bailed out of re-reading the capture file; the
559        capture file has been closed - just free the capture file name
560        string and return (without changing the last containing
561        directory). */
562     break;
563     }
564
565 end:
566     g_free(info->import_text_filename);
567     g_free(info->date_timestamp_format);
568     g_free(info);
569     g_free(capfile_name);
570     window_destroy(file_import_dlg_w);
571 }
572
573 static text_import_info_t *
574 setup_file_import(GtkWidget *main_w)
575 {
576     GtkWidget *input_frm, *import_frm;
577
578     text_import_info_t *text_import_info = (text_import_info_t *)g_malloc0(sizeof(text_import_info_t));
579
580     /* Retrieve the input and import settings from the dialog */
581
582     /* First the main components */
583     input_frm  = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
584     import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
585
586     /* Then the input frame controls of interest */
587     {
588         GtkWidget *filename_te   = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
589         GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
590         GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
591         GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
592         GtkWidget *timefmt_cb    = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
593         GtkWidget *timefmt_te    = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
594         GtkWidget *dir_cb        = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DIR_CB_KEY));
595
596         text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
597
598         /* Try to open the input file */
599         text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
600         if (!text_import_info->import_text_file) {
601             open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
602             g_free(text_import_info->import_text_filename);
603             g_free(text_import_info->date_timestamp_format);
604             g_free(text_import_info);
605             return NULL;
606         }
607
608         text_import_info->offset_type =
609             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
610             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
611             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
612             OFFSET_NONE;
613         text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
614         text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
615         text_import_info->has_direction = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dir_cb));
616     }
617
618     /* Then the import frame controls of interest */
619     {
620         GtkWidget *encap_co            = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
621         GtkWidget *header_frm          = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
622         GtkWidget *framelen_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
623
624         /* Then the header frame controls of interest */
625         GtkWidget *header_cb           = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
626
627         GtkWidget *header_eth_rb       = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
628         GtkWidget *header_ipv4_rb      = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
629         GtkWidget *header_udp_rb       = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
630         GtkWidget *header_tcp_rb       = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
631         GtkWidget *header_sctp_rb      = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
632         GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
633
634         GtkWidget *etype_te            = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
635         GtkWidget *protocol_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
636         GtkWidget *src_port_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
637         GtkWidget *dst_port_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
638         GtkWidget *tag_te              = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
639         GtkWidget *ppi_te              = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
640
641         GtkTreeIter iter;
642
643         if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter)) {
644             GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
645             gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
646         }
647
648         if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
649             (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb)))) {
650             text_import_info->dummy_header_type =
651                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb))       ? HEADER_ETH :
652                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb))      ? HEADER_IPV4 :
653                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb))       ? HEADER_UDP :
654                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb))       ? HEADER_TCP :
655                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb))      ? HEADER_SCTP :
656                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
657                 HEADER_NONE;
658
659             switch (text_import_info->dummy_header_type) {
660             case HEADER_ETH:
661                 text_import_info->pid = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
662                 if (text_import_info->pid > 0xffff) {
663                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
664                         text_import_info->pid);
665                     g_free(text_import_info->import_text_filename);
666                     fclose(text_import_info->import_text_file);
667                     g_free(text_import_info->date_timestamp_format);
668                     g_free(text_import_info);
669                     return NULL;
670                 }
671                 break;
672
673             case HEADER_IPV4:
674                 text_import_info->protocol = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
675                 if (text_import_info->protocol > 0xff) {
676                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
677                         text_import_info->protocol);
678                     g_free(text_import_info->import_text_filename);
679                     fclose(text_import_info->import_text_file);
680                     g_free(text_import_info->date_timestamp_format);
681                     g_free(text_import_info);
682                     return NULL;
683                 }
684                 break;
685
686             case HEADER_UDP:
687             case HEADER_TCP:
688                 text_import_info->src_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
689                 if (text_import_info->src_port > 0xffff) {
690                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
691                         text_import_info->src_port);
692                     g_free(text_import_info->import_text_filename);
693                     fclose(text_import_info->import_text_file);
694                     g_free(text_import_info->date_timestamp_format);
695                     g_free(text_import_info);
696                     return NULL;
697                 }
698                 text_import_info->dst_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
699                 if (text_import_info->dst_port > 0xffff) {
700                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
701                         text_import_info->dst_port);
702                     g_free(text_import_info->import_text_filename);
703                     fclose(text_import_info->import_text_file);
704                     g_free(text_import_info->date_timestamp_format);
705                     g_free(text_import_info);
706                     return NULL;
707                 }
708                 break;
709
710             case HEADER_SCTP:
711                 text_import_info->src_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
712                 if (text_import_info->src_port > 0xffff) {
713                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
714                         text_import_info->src_port);
715                     g_free(text_import_info->import_text_filename);
716                     fclose(text_import_info->import_text_file);
717                     g_free(text_import_info->date_timestamp_format);
718                     g_free(text_import_info);
719                     return NULL;
720                 }
721                 text_import_info->dst_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
722                 if (text_import_info->dst_port > 0xffff) {
723                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
724                         text_import_info->dst_port);
725                     g_free(text_import_info->import_text_filename);
726                     fclose(text_import_info->import_text_file);
727                     g_free(text_import_info->date_timestamp_format);
728                     g_free(text_import_info);
729                     return NULL;
730                 }
731                 text_import_info->tag = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
732                 break;
733
734             case HEADER_SCTP_DATA:
735                 text_import_info->src_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
736                 if (text_import_info->src_port > 0xffff) {
737                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
738                         text_import_info->src_port);
739                     g_free(text_import_info->import_text_filename);
740                     fclose(text_import_info->import_text_file);
741                     g_free(text_import_info->date_timestamp_format);
742                     g_free(text_import_info);
743                     return NULL;
744                 }
745                 text_import_info->dst_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
746                 if (text_import_info->dst_port > 0xffff) {
747                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
748                         text_import_info->dst_port);
749                     g_free(text_import_info->import_text_filename);
750                     fclose(text_import_info->import_text_file);
751                     g_free(text_import_info->date_timestamp_format);
752                     g_free(text_import_info);
753                     return NULL;
754                 }
755                 text_import_info->ppi = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
756                 break;
757
758             default:
759                 break;
760             }
761         } else {
762             text_import_info->dummy_header_type = HEADER_NONE;
763         }
764
765         text_import_info->max_frame_length = (guint)strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
766         if (text_import_info->max_frame_length == 0) {
767             text_import_info->max_frame_length = IMPORT_MAX_PACKET;
768         } else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET) {
769             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
770                 text_import_info->max_frame_length);
771             g_free(text_import_info->import_text_filename);
772             fclose(text_import_info->import_text_file);
773             g_free(text_import_info->date_timestamp_format);
774             g_free(text_import_info);
775             return NULL;
776         }
777     }
778
779     return text_import_info;
780 }
781
782 /*****************************************************************************/
783
784 static void
785 file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
786 {
787     text_import_info_t *text_import_info;
788
789     /* If there's unsaved data, let the user save it first.
790        If they cancel out of it, don't open the file. */
791     if (do_file_close(&cfile, FALSE, " before opening a new capture file")) {
792         /* open the new file */
793         text_import_info = setup_file_import((GtkWidget *)data);
794         if (text_import_info) {
795             file_import_open(text_import_info);
796         }
797     }
798 }
799
800 static void
801 set_default_encap(GtkWidget *encap_co, guint default_encap)
802 {
803     gboolean result;
804     GtkTreeIter iter;
805     GtkTreeModel *model;
806     gboolean more_items = TRUE;
807     guint encap_value;
808
809     gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
810     result = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter);
811     if (result) {
812         model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
813         do {
814             gtk_tree_model_get(model, &iter, ENCAP_VALUE_COLUMN, &encap_value, -1);
815             if (encap_value == default_encap) {
816                 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(encap_co), &iter);
817                 more_items = FALSE;
818             }
819             else
820                 more_items = gtk_tree_model_iter_next(model, &iter);
821         } while (more_items);
822     }
823 }
824
825 /*****************************************************************************/
826
827 /*
828  * Dialog creator
829  */
830 static GtkWidget *
831 file_import_dlg_new(void)
832 {
833     GtkWidget  *main_w, *main_vb,
834                *input_frm, *input_grid, *input_vb,
835                *filename_lbl, *filename_te, *browse_bt,
836                *offset_lbl, *offset_rb_vb,
837                *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
838                *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
839                *dir_hb, *dir_cb,
840                *import_frm, *import_vb,
841                *encap_hb, *encap_lbl, *encap_co,
842                *header_cb, *header_frm, *header_hb,
843                *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
844                *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
845                *header_rblbl_vb,
846                *header_rblbl_1_hb, *header_rblbl_1_lbl,
847                *header_rblbl_2_hb, *header_rblbl_2_lbl,
848                *header_rblbl_3_hb, *header_rblbl_3_lbl,
849                *header_rblbl_4_hb, *header_rblbl_4_lbl,
850                *header_rblbl_5_hb, *header_rblbl_5_lbl,
851                *header_rblbl_6_hb, *header_rblbl_6_lbl,
852                *etype_te, *protocol_te, *src_port_te,
853                *dst_port_te, *tag_te, *ppi_te,
854                *framelen_hb, *framelen_lbl, *framelen_te,
855                *bbox, *help_bt, *close_bt, *ok_bt;
856
857     /* Setup the dialog */
858
859     main_w = dlg_window_new("Wireshark: Import from Hex Dump");
860     gtk_window_set_default_size(GTK_WINDOW(main_w), 400, 300);
861
862     main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
863     gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
864     gtk_container_add(GTK_CONTAINER(main_w), main_vb);
865
866     /* Setup the input frame */
867
868     input_frm = gtk_frame_new("Input");
869     gtk_box_pack_start(GTK_BOX(main_vb), input_frm, FALSE, FALSE, 0);
870
871     g_object_set_data(G_OBJECT(main_w), INPUT_FRM_KEY, input_frm);
872
873     input_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
874     gtk_container_add(GTK_CONTAINER(input_frm), input_vb);
875
876     input_grid = ws_gtk_grid_new();
877     gtk_container_set_border_width(GTK_CONTAINER(input_grid), 5);
878     gtk_box_pack_start(GTK_BOX(input_vb), input_grid, FALSE, FALSE, 0);
879     ws_gtk_grid_set_row_spacing(GTK_GRID(input_grid), 5);
880     ws_gtk_grid_set_column_spacing(GTK_GRID(input_grid), 5);
881
882     /* Filename */
883     filename_lbl = gtk_label_new("Filename:");
884     ws_gtk_grid_attach(GTK_GRID(input_grid), filename_lbl, 0, 0, 1, 1);
885
886     filename_te = gtk_entry_new();
887     gtk_widget_set_tooltip_text(filename_te, "Set name of text file to import");
888     ws_gtk_grid_attach_defaults(GTK_GRID(input_grid), filename_te, 1, 0, 1, 1);
889
890     g_object_set_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY, filename_te);
891
892     browse_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
893     gtk_widget_set_tooltip_text(browse_bt, "Browse for text file to import");
894     ws_gtk_grid_attach(GTK_GRID(input_grid), browse_bt, 2, 0, 1, 1);
895
896     g_signal_connect(browse_bt, "clicked", G_CALLBACK(browse_file_cb), filename_te);
897
898     /* Offsets */
899
900     offset_lbl = gtk_label_new("Offsets:");
901     gtk_misc_set_alignment(GTK_MISC(offset_lbl), 1.0f, 0.0f);
902     ws_gtk_grid_attach(GTK_GRID(input_grid), offset_lbl, 0, 1, 1, 1);
903
904     offset_rb_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
905     ws_gtk_grid_attach_defaults(GTK_GRID(input_grid), offset_rb_vb, 1, 1, 1, 1);
906
907     /* First entry in the group */
908     offset_hex_rb = gtk_radio_button_new_with_label(NULL, "Hexadecimal");
909     gtk_widget_set_tooltip_text(offset_hex_rb, "Offsets in the text file are in hexadecimal notation");
910     gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_hex_rb, FALSE, FALSE, 0);
911
912     g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY, offset_hex_rb);
913
914     offset_oct_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(offset_hex_rb), "Octal");
915     gtk_widget_set_tooltip_text(offset_oct_rb, "Offsets in the text file are in octal notation");
916     gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_oct_rb, FALSE, FALSE, 0);
917
918     g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY, offset_oct_rb);
919
920     offset_dec_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(offset_hex_rb), "Decimal");
921     gtk_widget_set_tooltip_text(offset_dec_rb, "Offsets in the text file are in decimal notation");
922     gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_dec_rb, FALSE, FALSE, 0);
923
924     g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY, offset_dec_rb);
925
926     /* Time format */
927     timefmt_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
928     gtk_container_set_border_width(GTK_CONTAINER(timefmt_hb), 3);
929     gtk_box_pack_start(GTK_BOX(input_vb), timefmt_hb, FALSE, FALSE, 0);
930
931     timefmt_cb = gtk_check_button_new_with_label("Date/Time");
932     gtk_widget_set_tooltip_text(timefmt_cb, "Whether or not the text file contains timestamp information");
933     gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_cb, FALSE, FALSE, 0);
934
935     g_object_set_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY, timefmt_cb);
936
937     timefmt_lbl = gtk_label_new("   Format:");
938     gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_lbl, FALSE, FALSE, 0);
939
940     g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_LBL_KEY, timefmt_lbl);
941
942     timefmt_te = gtk_entry_new();
943     gtk_entry_set_text(GTK_ENTRY(timefmt_te), "%F %T.");
944     gtk_widget_set_tooltip_text(timefmt_te,
945                                 "The format in which to parse timestamps in the text file (eg. %F %T.)."
946                                 " Format specifiers are based on strptime(3)");
947     gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_te, FALSE, FALSE, 0);
948
949     g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_TE_KEY, timefmt_te);
950     g_object_set_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY, timefmt_te);
951
952     g_signal_connect(timefmt_cb, "toggled", G_CALLBACK(timefmt_cb_toggle), NULL);
953     g_signal_emit_by_name(G_OBJECT(timefmt_cb), "toggled", NULL);
954
955     /* Direction indication */
956     dir_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
957     gtk_container_set_border_width(GTK_CONTAINER(dir_hb), 3);
958     gtk_box_pack_start(GTK_BOX(input_vb), dir_hb, FALSE, FALSE, 0);
959
960     dir_cb = gtk_check_button_new_with_label("Direction indication");
961     gtk_widget_set_tooltip_text(dir_cb, "Whether or not the file contains information indicating the direction "
962                                 " (inbound or outbound) of the packet");
963     gtk_box_pack_start(GTK_BOX(dir_hb), dir_cb, FALSE, FALSE, 0);
964
965     g_object_set_data(G_OBJECT(input_frm), INPUT_DIR_CB_KEY, dir_cb);
966
967     /* Setup the import frame */
968
969     import_frm = gtk_frame_new("Import");
970     gtk_box_pack_start(GTK_BOX(main_vb), import_frm, TRUE, TRUE, 3);
971
972     g_object_set_data(G_OBJECT(main_w), IMPORT_FRM_KEY, import_frm);
973
974     import_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
975     gtk_container_add(GTK_CONTAINER(import_frm), import_vb);
976
977     /* Encapsulation */
978     encap_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
979     gtk_container_set_border_width(GTK_CONTAINER(encap_hb), 3);
980     gtk_box_pack_start(GTK_BOX(import_vb), encap_hb, FALSE, FALSE, 0);
981
982     encap_lbl = gtk_label_new("Encapsulation type:");
983     gtk_box_pack_start(GTK_BOX(encap_hb), encap_lbl, FALSE, FALSE, 0);
984
985     encap_co = fill_encap_combo();
986     gtk_widget_set_tooltip_text(encap_co, "Encapsulation type for the frames in the import capture file");
987     gtk_box_pack_start(GTK_BOX(encap_hb), encap_co, FALSE, FALSE, 0);
988
989     g_object_set_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY, encap_co);
990
991     /* Dummy header */
992     header_frm = gtk_frame_new(NULL);
993     header_cb = gtk_check_button_new_with_label("Dummy header");
994     gtk_widget_set_tooltip_text(header_cb, "Whether or not to prefix a dummy header to the frames");
995     gtk_frame_set_label_widget(GTK_FRAME(header_frm), header_cb);
996     gtk_container_set_border_width(GTK_CONTAINER(header_frm), 3);
997     gtk_box_pack_start(GTK_BOX(import_vb), header_frm, FALSE, FALSE, 0);
998
999     g_object_set_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY, header_frm);
1000     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY, header_cb);
1001
1002     header_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
1003     gtk_container_set_border_width(GTK_CONTAINER(header_hb), 3);
1004     gtk_container_add(GTK_CONTAINER(header_frm), header_hb);
1005
1006     header_rblbl_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
1007     gtk_box_pack_start(GTK_BOX(header_hb), header_rblbl_vb, TRUE, TRUE, 0);
1008
1009     /* Line 1 */
1010     header_rblbl_1_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
1011     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_1_hb, FALSE, FALSE, 2);
1012
1013     /* First entry in the group */
1014     header_eth_rb = gtk_radio_button_new_with_label(NULL, "Ethernet");
1015     gtk_widget_set_tooltip_text(header_eth_rb, "Prefix an Ethernet header to the frames");
1016     g_signal_connect(header_eth_rb, "toggled", G_CALLBACK(header_eth_rb_toggle), header_frm);
1017     gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_eth_rb, FALSE, FALSE, 0);
1018
1019     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY, header_eth_rb);
1020
1021     header_rblbl_1_lbl = gtk_label_new("  Ethertype (hex):");
1022     gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_rblbl_1_lbl, TRUE, TRUE, 0);
1023     gtk_misc_set_alignment(GTK_MISC(header_rblbl_1_lbl), 1.0f, 0.5f);
1024
1025     etype_te = gtk_entry_new();
1026     gtk_widget_set_tooltip_text(etype_te, "The type to set in the Ethernet header");
1027     gtk_box_pack_end(GTK_BOX(header_rblbl_1_hb), etype_te, FALSE, FALSE, 0);
1028
1029     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_LBL_KEY, header_rblbl_1_lbl);
1030     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY, etype_te);
1031
1032     /* Line 2 */
1033     header_rblbl_2_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
1034     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_2_hb, FALSE, FALSE, 2);
1035
1036     header_ipv4_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "IPv4");
1037     gtk_widget_set_tooltip_text(header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames");
1038     g_signal_connect(header_ipv4_rb, "toggled", G_CALLBACK(header_ipv4_rb_toggle), header_frm);
1039     gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_ipv4_rb, FALSE, FALSE, 0);
1040
1041     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY, header_ipv4_rb);
1042
1043     header_rblbl_2_lbl = gtk_label_new("  Protocol (dec):");
1044     gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_rblbl_2_lbl, TRUE, TRUE, 0);
1045     gtk_misc_set_alignment(GTK_MISC(header_rblbl_2_lbl), 1.0f, 0.5f);
1046
1047     protocol_te = gtk_entry_new();
1048     gtk_widget_set_tooltip_text(protocol_te, "The protocol id to set in the IPv4 header");
1049     gtk_box_pack_end(GTK_BOX(header_rblbl_2_hb), protocol_te, FALSE, FALSE, 0);
1050
1051     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_LBL_KEY, header_rblbl_2_lbl);
1052     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY, protocol_te);
1053
1054     /* Line 3 */
1055     header_rblbl_3_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
1056     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_3_hb, FALSE, FALSE, 2);
1057
1058     header_udp_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "UDP");
1059     gtk_widget_set_tooltip_text(header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames");
1060     g_signal_connect(header_udp_rb, "toggled", G_CALLBACK(header_udp_rb_toggle), header_frm);
1061     gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_udp_rb, FALSE, FALSE, 0);
1062
1063     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY, header_udp_rb);
1064
1065     header_rblbl_3_lbl = gtk_label_new("  Source port:");
1066     gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_rblbl_3_lbl, TRUE, TRUE, 0);
1067     gtk_misc_set_alignment(GTK_MISC(header_rblbl_3_lbl), 1.0f, 0.5f);
1068
1069     src_port_te = gtk_entry_new();
1070     gtk_widget_set_tooltip_text(src_port_te, "The source port to set in the UDP, TCP or SCTP header");
1071     gtk_box_pack_end(GTK_BOX(header_rblbl_3_hb), src_port_te, FALSE, FALSE, 0);
1072
1073     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_LBL_KEY, header_rblbl_3_lbl);
1074     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY, src_port_te);
1075
1076     /* Line 4 */
1077     header_rblbl_4_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
1078     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_4_hb, FALSE, FALSE, 2);
1079
1080     header_tcp_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "TCP");
1081     gtk_widget_set_tooltip_text(header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames");
1082     g_signal_connect(header_tcp_rb, "toggled", G_CALLBACK(header_tcp_rb_toggle), header_frm);
1083     gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_tcp_rb, FALSE, FALSE, 0);
1084
1085     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY, header_tcp_rb);
1086
1087     header_rblbl_4_lbl = gtk_label_new("  Destination port:");
1088     gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_rblbl_4_lbl, TRUE, TRUE, 0);
1089     gtk_misc_set_alignment(GTK_MISC(header_rblbl_4_lbl), 1.0f, 0.5f);
1090
1091     dst_port_te = gtk_entry_new();
1092     gtk_widget_set_tooltip_text(dst_port_te, "The destination port to set in the UDP, TCP or SCTP header");
1093     gtk_box_pack_end(GTK_BOX(header_rblbl_4_hb), dst_port_te, FALSE, FALSE, 0);
1094
1095     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_LBL_KEY, header_rblbl_4_lbl);
1096     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY, dst_port_te);
1097
1098     /* Line 5 */
1099     header_rblbl_5_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
1100     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_5_hb, FALSE, FALSE, 2);
1101
1102     header_sctp_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "SCTP");
1103     gtk_widget_set_tooltip_text(header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames");
1104     g_signal_connect(header_sctp_rb, "toggled", G_CALLBACK(header_sctp_rb_toggle), header_frm);
1105     gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_sctp_rb, FALSE, FALSE, 0);
1106
1107     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY, header_sctp_rb);
1108
1109     header_rblbl_5_lbl = gtk_label_new("  Tag:");
1110     gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_rblbl_5_lbl, TRUE, TRUE, 0);
1111     gtk_misc_set_alignment(GTK_MISC(header_rblbl_5_lbl), 1.0f, 0.5f);
1112
1113     tag_te = gtk_entry_new();
1114     gtk_widget_set_tooltip_text(tag_te, "The verification tag to set in the SCTP header");
1115     gtk_box_pack_end(GTK_BOX(header_rblbl_5_hb), tag_te, FALSE, FALSE, 0);
1116
1117     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_LBL_KEY, header_rblbl_5_lbl);
1118     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY, tag_te);
1119
1120     /* Line 6 */
1121     header_rblbl_6_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
1122     gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_6_hb, FALSE, FALSE, 2);
1123
1124     header_sctp_data_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "SCTP (DATA)");
1125     gtk_widget_set_tooltip_text(header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames");
1126     g_signal_connect(header_sctp_data_rb, "toggled", G_CALLBACK(header_sctp_data_rb_toggle), header_frm);
1127     gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_sctp_data_rb, FALSE, FALSE, 0);
1128
1129     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY, header_sctp_data_rb);
1130
1131     header_rblbl_6_lbl = gtk_label_new("  PPI:");
1132     gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_rblbl_6_lbl, TRUE, TRUE, 0);
1133     gtk_misc_set_alignment(GTK_MISC(header_rblbl_6_lbl), 1.0f, 0.5f);
1134
1135     ppi_te = gtk_entry_new();
1136     gtk_widget_set_tooltip_text(ppi_te, "The payload protocol identifier to set in the SCTP DATA header");
1137     gtk_box_pack_end(GTK_BOX(header_rblbl_6_hb), ppi_te, FALSE, FALSE, 0);
1138
1139     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_LBL_KEY, header_rblbl_6_lbl);
1140     g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY, ppi_te);
1141
1142     /* Set sensitivity */
1143     g_signal_connect(header_cb, "toggled", G_CALLBACK(header_cb_toggle), header_frm);
1144     g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", header_frm);
1145
1146     g_signal_emit_by_name(G_OBJECT(header_eth_rb), "toggled", header_frm);
1147     set_default_encap(encap_co, WTAP_ENCAP_ETHERNET);
1148     g_signal_connect(encap_co, "changed", G_CALLBACK(encap_co_changed), header_frm);
1149
1150     /* Frame length */
1151     framelen_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
1152     gtk_container_set_border_width(GTK_CONTAINER(framelen_hb), 3);
1153     gtk_box_pack_start(GTK_BOX(import_vb), framelen_hb, FALSE, FALSE, 0);
1154
1155     framelen_lbl = gtk_label_new("Max. frame length:");
1156     gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_lbl, FALSE, FALSE, 0);
1157
1158     framelen_te = gtk_entry_new();
1159     gtk_widget_set_tooltip_text(framelen_te,
1160                                 "The maximum size of the frames to write to the import capture file (max 65535)");
1161     gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_te, FALSE, FALSE, 0);
1162
1163     g_object_set_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY, framelen_te);
1164
1165     /* Setup the button row */
1166
1167     bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1168     gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
1169
1170     help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1171     g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_IMPORT_DIALOG);
1172     gtk_widget_set_tooltip_text(help_bt, "Show topic specific help");
1173
1174     close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1175     window_set_cancel_button(main_w, close_bt, window_cancel_button_cb);
1176     gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
1177
1178     ok_bt =  (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1179     g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_import_ok_cb), main_w);
1180     gtk_widget_grab_default(ok_bt);
1181     gtk_widget_set_tooltip_text(ok_bt, "Import the selected file into a temporary capture file");
1182
1183     /* Setup widget handling */
1184
1185     g_signal_connect(main_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1186     g_signal_connect(main_w, "destroy", G_CALLBACK(file_import_dlg_destroy_cb), NULL);
1187
1188     gtk_widget_show_all(main_w);
1189     window_present(main_w);
1190
1191     return main_w;
1192 }
1193
1194 void
1195 file_import_cmd_cb(GtkWidget *widget _U_)
1196 {
1197     /* Do we have an encapsulation type list? */
1198     if (!encap_list_store) {
1199         /* No. Create one. */
1200         create_encap_list_store();
1201     }
1202
1203     /* Has a file import dialog already been opened? */
1204     if (file_import_dlg_w) {
1205         /* Yes. Just re-activate that dialog box. */
1206         reactivate_window(file_import_dlg_w);
1207     } else {
1208         /* No. Create one */
1209         file_import_dlg_w = file_import_dlg_new();
1210     }
1211 }
1212
1213 /*
1214  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
1215  *
1216  * Local variables:
1217  * c-basic-offset: 4
1218  * tab-width: 4
1219  * indent-tabs-mode: nil
1220  * End:
1221  *
1222  * vi: set shiftwidth=4 tabstop=4 expandtab:
1223  * :indentSize=4:tabSize=4:noTabs=true:
1224  */