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