86248d73fa054c275c8303bd99f4c25311598dd3
[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  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22  * USA.
23  */
24
25 #include "config.h"
26
27
28 #include <stdlib.h>
29
30 #include "globals.h"
31 #include "wiretap/pcap-encap.h"
32
33 #include "ui/simple_dialog.h"
34 #include "ui/alert_box.h"
35
36 #include "ui/gtk/stock_icons.h"
37 #include "ui/gtk/dlg_utils.h"
38 #include "ui/gtk/gui_utils.h"
39 #include "ui/gtk/file_dlg.h"
40 #include "ui/gtk/capture_file_dlg.h"
41 #include "ui/gtk/help_dlg.h"
42
43 #include "ui/gtk/file_import_dlg.h"
44 #include "ui/text_import.h"
45 #include "ui/text_import_scanner.h"
46
47 #include "wsutil/file_util.h"
48 #include "wsutil/tempfile.h"
49 #include "wsutil/os_version_info.h"
50 #include "wsutil/ws_version_info.h"
51
52 #define INPUT_FRM_KEY                   "input_frame"
53
54 #define INPUT_FILENAME_TE_KEY           "input_filename_text"
55
56 #define INPUT_OFFSET_HEX_RB_KEY         "input_offset_hex_radio"
57 #define INPUT_OFFSET_OCT_RB_KEY         "input_offset_oct_radio"
58 #define INPUT_OFFSET_DEC_RB_KEY         "input_offset_dec_radio"
59
60 #define INPUT_DATETIME_CB_KEY           "input_datetime_checkbox"
61 #define INPUT_TIMEFMT_LBL_KEY           "input_timeformat_label"
62 #define INPUT_TIMEFMT_TE_KEY            "input_timeformat_entry"
63
64 #define INPUT_DIR_CB_KEY                "input_direction_indication_checkbox"
65
66 #define IMPORT_FRM_KEY                  "import_frame"
67 #define IMPORT_ENCAP_CO_KEY             "import_encap_combo"
68
69 #define IMPORT_HEADER_FRM_KEY           "import_header_frame"
70 #define IMPORT_HEADER_CB_KEY            "import_header_checkbox"
71 #define IMPORT_HEADER_ETH_RB_KEY        "import_header_ethernet_radio"
72 #define IMPORT_HEADER_ETYPE_LBL_KEY     "import_header_etype_label"
73 #define IMPORT_HEADER_ETYPE_TE_KEY      "import_header_etype_text"
74 #define IMPORT_HEADER_IPV4_RB_KEY       "import_header_ipv4_radio"
75 #define IMPORT_HEADER_PROT_LBL_KEY      "import_header_prot_label"
76 #define IMPORT_HEADER_PROT_TE_KEY       "import_header_prot_text"
77 #define IMPORT_HEADER_UDP_RB_KEY        "import_header_udp_radio"
78 #define IMPORT_HEADER_SRC_PORT_LBL_KEY  "import_header_src_port_label"
79 #define IMPORT_HEADER_SRC_PORT_TE_KEY   "import_header_src_port_text"
80 #define IMPORT_HEADER_TCP_RB_KEY        "import_header_tcp_radio"
81 #define IMPORT_HEADER_DST_PORT_LBL_KEY  "import_header_dst_port_label"
82 #define IMPORT_HEADER_DST_PORT_TE_KEY   "import_header_dst_port_text"
83 #define IMPORT_HEADER_SCTP_RB_KEY       "import_header_sctp_radio"
84 #define IMPORT_HEADER_TAG_LBL_KEY       "import_header_tag_label"
85 #define IMPORT_HEADER_TAG_TE_KEY        "import_header_tag_text"
86 #define IMPORT_HEADER_SCTP_D_RB_KEY     "import_header_sctp_data_radio"
87 #define IMPORT_HEADER_PPI_LBL_KEY       "import_header_ppi_label"
88 #define IMPORT_HEADER_PPI_TE_KEY        "import_header_ppi_text"
89
90 #define IMPORT_FRAME_LENGTH_TE_KEY      "import_frame_length_text"
91
92 static GtkWidget    *file_import_dlg_w = NULL;
93 static GtkListStore *encap_list_store  = NULL;
94
95 /*****************************************************************************/
96
97 static void
98 file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
99 {
100     file_import_dlg_w = NULL;
101 }
102
103 /*****************************************************************************/
104
105 static void
106 browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
107 {
108     file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Hex Dump",
109         FILE_SELECTION_READ_BROWSE);
110 }
111
112 static void
113 timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
114 {
115     GtkWidget *timefmt_lbl, *timefmt_te;
116     gboolean   apply_fmt;
117
118     timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
119     timefmt_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
120
121     apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
122     gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
123     gtk_widget_set_sensitive(timefmt_te, apply_fmt);
124 }
125
126 enum
127 {
128     ENCAP_NAME_COLUMN,
129     ENCAP_VALUE_COLUMN
130 };
131
132 /*****************************************************************************/
133 static void
134 create_encap_list_store(void)
135 {
136     GtkTreeIter  iter;
137     gint         encap;
138     const gchar *name;
139     GtkTreeSortable *sortable;
140     GtkSortType order = GTK_SORT_ASCENDING;
141
142     encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
143     sortable = GTK_TREE_SORTABLE(encap_list_store);
144     gtk_tree_sortable_set_sort_func(sortable, ENCAP_NAME_COLUMN,
145         str_ptr_sort_func, GINT_TO_POINTER(ENCAP_NAME_COLUMN), NULL);
146     gtk_tree_sortable_set_sort_column_id(sortable, ENCAP_NAME_COLUMN, order);
147
148     /* Scan all Wiretap encapsulation types */
149     for (encap = 1; encap < wtap_get_num_encap_types(); encap++) {
150         /* Check if we can write to a PCAP file
151          *
152          * Exclude wtap encapsulations that require a pseudo header,
153          * because we won't setup one from the text we import and
154          * wiretap doesn't allow us to write 'raw' frames
155          */
156         if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) && !wtap_encap_requires_phdr(encap)) {
157             /* If it has got a name */
158             if ((name = wtap_encap_string(encap))) {
159                 gtk_list_store_append(encap_list_store, &iter);
160                 gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
161             }
162         }
163     }
164 }
165
166 static GtkWidget *
167 fill_encap_combo(void)
168 {
169     GtkWidget       *encap_co;
170     GtkCellRenderer *cell;
171
172     encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
173     cell = gtk_cell_renderer_text_new();
174     gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
175     gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
176
177     return encap_co;
178 }
179
180 static void header_frm_child_set(GtkWidget *widget, gpointer data);
181
182 static void
183 encap_co_changed(GtkComboBox *widget, gpointer data)
184 {
185     GtkTreeIter  iter;
186     gboolean     result;
187     GtkWidget   *header_cb;
188
189     result = gtk_combo_box_get_active_iter(widget, &iter);
190
191     if (result) {
192         guint encap;
193         GtkTreeModel *model = gtk_combo_box_get_model(widget);
194         gtk_tree_model_get(model, &iter, ENCAP_VALUE_COLUMN, &encap, -1);
195
196         if (encap != WTAP_ENCAP_ETHERNET)
197             result = FALSE;
198     }
199
200     if (result) {
201         header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
202         g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
203     } else {
204         gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
205     }
206 }
207
208 /*****************************************************************************/
209
210 static void
211 header_frm_child_set(GtkWidget *widget, gpointer data)
212 {
213     gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
214 }
215
216 static void
217 header_cb_toggle(GtkWidget *widget, gpointer data)
218 {
219     gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
220         GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
221     /* The frame's checkbox must stay sensitive, of course... */
222     gtk_widget_set_sensitive(widget, TRUE);
223 }
224
225 /*
226  * Header radio button toggle handlers
227  */
228 static void
229 header_eth_rb_toggle(GtkWidget *widget, gpointer data)
230 {
231     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
232     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
233     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
234     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
235     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
236     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
237     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
238     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
239     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
240     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
241     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
242     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
243
244     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
245         gtk_widget_set_sensitive(etype_lbl,    TRUE);
246         gtk_widget_set_sensitive(etype_te,     TRUE);
247         gtk_widget_set_sensitive(prot_lbl,     FALSE);
248         gtk_widget_set_sensitive(prot_te,      FALSE);
249         gtk_widget_set_sensitive(src_port_lbl, FALSE);
250         gtk_widget_set_sensitive(src_port_te,  FALSE);
251         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
252         gtk_widget_set_sensitive(dst_port_te,  FALSE);
253         gtk_widget_set_sensitive(tag_lbl,      FALSE);
254         gtk_widget_set_sensitive(tag_te,       FALSE);
255         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
256         gtk_widget_set_sensitive(ppi_te,       FALSE);
257     } else {
258         gtk_widget_set_sensitive(etype_lbl,    FALSE);
259         gtk_widget_set_sensitive(etype_te,     FALSE);
260     }
261 }
262
263 static void
264 header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
265 {
266     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
267     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
268     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
269     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
270     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
271     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
272     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
273     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
274     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
275     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
276     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
277     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
278
279     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
280         gtk_widget_set_sensitive(etype_lbl,    FALSE);
281         gtk_widget_set_sensitive(etype_te,     FALSE);
282         gtk_widget_set_sensitive(prot_lbl,     TRUE);
283         gtk_widget_set_sensitive(prot_te,      TRUE);
284         gtk_widget_set_sensitive(src_port_lbl, FALSE);
285         gtk_widget_set_sensitive(src_port_te,  FALSE);
286         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
287         gtk_widget_set_sensitive(dst_port_te,  FALSE);
288         gtk_widget_set_sensitive(tag_lbl,      FALSE);
289         gtk_widget_set_sensitive(tag_te,       FALSE);
290         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
291         gtk_widget_set_sensitive(ppi_te,       FALSE);
292     } else {
293         gtk_widget_set_sensitive(prot_lbl,     FALSE);
294         gtk_widget_set_sensitive(prot_te,      FALSE);
295     }
296 }
297
298 static void
299 header_udp_rb_toggle(GtkWidget *widget, gpointer data)
300 {
301     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
302     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
303     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
304     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
305     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
306     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
307     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
308     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
309     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
310     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
311     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
312     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
313
314     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
315         gtk_widget_set_sensitive(etype_lbl,    FALSE);
316         gtk_widget_set_sensitive(etype_te,     FALSE);
317         gtk_widget_set_sensitive(prot_lbl,     FALSE);
318         gtk_widget_set_sensitive(prot_te,      FALSE);
319         gtk_widget_set_sensitive(src_port_lbl, TRUE);
320         gtk_widget_set_sensitive(src_port_te,  TRUE);
321         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
322         gtk_widget_set_sensitive(dst_port_te,  TRUE);
323         gtk_widget_set_sensitive(tag_lbl,      FALSE);
324         gtk_widget_set_sensitive(tag_te,       FALSE);
325         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
326         gtk_widget_set_sensitive(ppi_te,       FALSE);
327     } else {
328         gtk_widget_set_sensitive(src_port_lbl, FALSE);
329         gtk_widget_set_sensitive(src_port_te,  FALSE);
330         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
331         gtk_widget_set_sensitive(dst_port_te,  FALSE);
332     }
333 }
334
335 static void
336 header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
337 {
338     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
339     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
340     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
341     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
342     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
343     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
344     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
345     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
346     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
347     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
348     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
349     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
350
351     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
352         gtk_widget_set_sensitive(etype_lbl,    FALSE);
353         gtk_widget_set_sensitive(etype_te,     FALSE);
354         gtk_widget_set_sensitive(prot_lbl,     FALSE);
355         gtk_widget_set_sensitive(prot_te,      FALSE);
356         gtk_widget_set_sensitive(src_port_lbl, TRUE);
357         gtk_widget_set_sensitive(src_port_te,  TRUE);
358         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
359         gtk_widget_set_sensitive(dst_port_te,  TRUE);
360         gtk_widget_set_sensitive(tag_lbl,      FALSE);
361         gtk_widget_set_sensitive(tag_te,       FALSE);
362         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
363         gtk_widget_set_sensitive(ppi_te,       FALSE);
364     } else {
365         gtk_widget_set_sensitive(src_port_lbl, FALSE);
366         gtk_widget_set_sensitive(src_port_te,  FALSE);
367         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
368         gtk_widget_set_sensitive(dst_port_te,  FALSE);
369     }
370 }
371
372 static void
373 header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
374 {
375     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
376     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
377     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
378     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
379     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
380     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
381     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
382     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
383     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
384     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
385     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
386     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
387
388     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
389         gtk_widget_set_sensitive(etype_lbl,    FALSE);
390         gtk_widget_set_sensitive(etype_te,     FALSE);
391         gtk_widget_set_sensitive(prot_lbl,     FALSE);
392         gtk_widget_set_sensitive(prot_te,      FALSE);
393         gtk_widget_set_sensitive(src_port_lbl, TRUE);
394         gtk_widget_set_sensitive(src_port_te,  TRUE);
395         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
396         gtk_widget_set_sensitive(dst_port_te,  TRUE);
397         gtk_widget_set_sensitive(tag_lbl,      TRUE);
398         gtk_widget_set_sensitive(tag_te,       TRUE);
399         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
400         gtk_widget_set_sensitive(ppi_te,       FALSE);
401     } else {
402         gtk_widget_set_sensitive(src_port_lbl, FALSE);
403         gtk_widget_set_sensitive(src_port_te,  FALSE);
404         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
405         gtk_widget_set_sensitive(dst_port_te,  FALSE);
406         gtk_widget_set_sensitive(tag_lbl,      FALSE);
407         gtk_widget_set_sensitive(tag_te,       FALSE);
408     }
409 }
410
411 static void
412 header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
413 {
414     GtkWidget *etype_lbl    = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
415     GtkWidget *etype_te     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
416     GtkWidget *prot_lbl     = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
417     GtkWidget *prot_te      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
418     GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
419     GtkWidget *src_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
420     GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
421     GtkWidget *dst_port_te  = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
422     GtkWidget *tag_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
423     GtkWidget *tag_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
424     GtkWidget *ppi_lbl      = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
425     GtkWidget *ppi_te       = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
426
427     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
428         gtk_widget_set_sensitive(etype_lbl,    FALSE);
429         gtk_widget_set_sensitive(etype_te,     FALSE);
430         gtk_widget_set_sensitive(prot_lbl,     FALSE);
431         gtk_widget_set_sensitive(prot_te,      FALSE);
432         gtk_widget_set_sensitive(src_port_lbl, TRUE);
433         gtk_widget_set_sensitive(src_port_te,  TRUE);
434         gtk_widget_set_sensitive(dst_port_lbl, TRUE);
435         gtk_widget_set_sensitive(dst_port_te,  TRUE);
436         gtk_widget_set_sensitive(tag_lbl,      FALSE);
437         gtk_widget_set_sensitive(tag_te,       FALSE);
438         gtk_widget_set_sensitive(ppi_lbl,      TRUE);
439         gtk_widget_set_sensitive(ppi_te,       TRUE);
440     } else {
441         gtk_widget_set_sensitive(src_port_lbl, FALSE);
442         gtk_widget_set_sensitive(src_port_te,  FALSE);
443         gtk_widget_set_sensitive(dst_port_lbl, FALSE);
444         gtk_widget_set_sensitive(dst_port_te,  FALSE);
445         gtk_widget_set_sensitive(ppi_lbl,      FALSE);
446         gtk_widget_set_sensitive(ppi_te,       FALSE);
447     }
448 }
449
450 /*****************************************************************************/
451
452 static void
453 file_import_open(text_import_info_t *info)
454 {
455     char *tmpname, *capfile_name;
456     int   err;
457
458     /* pcapng defs */
459     wtapng_section_t            *shb_hdr;
460     wtapng_iface_descriptions_t *idb_inf;
461     wtapng_if_descr_t            int_data;
462     GString                     *os_info_str;
463
464     /* Create data for SHB  */
465     os_info_str = g_string_new("");
466     get_os_version_info(os_info_str);
467
468     shb_hdr = g_new(wtapng_section_t,1);
469     shb_hdr->section_length = -1;
470     /* options */
471     shb_hdr->opt_comment    = g_strdup_printf("File created by File->Import of file %s", info->import_text_filename);
472     /*
473      * UTF-8 string containing the description of the hardware used to create
474      * this section.
475      */
476     shb_hdr->shb_hardware   = NULL;
477     /*
478      * UTF-8 string containing the name of the operating system used to create
479      * this section.
480      */
481     shb_hdr->shb_os         = g_string_free(os_info_str, FALSE);
482     /*
483      * UTF-8 string containing the name of the application used to create
484      * this section.
485      */
486     shb_hdr->shb_user_appl  = g_strdup_printf("Wireshark %s", get_ws_vcs_version_info());
487
488
489     /* Create fake IDB info */
490     idb_inf = g_new(wtapng_iface_descriptions_t,1);
491     idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t));
492
493     /* create the fake interface data */
494     int_data.wtap_encap            = info->encapsulation;
495     int_data.time_units_per_second = 1000000; /* default microsecond resolution */
496     int_data.link_type             = wtap_wtap_encap_to_pcap_encap(info->encapsulation);
497     int_data.snap_len              = WTAP_MAX_PACKET_SIZE;
498     int_data.if_name               = g_strdup("Fake IF File->Import");
499     int_data.opt_comment           = NULL;
500     int_data.if_description        = NULL;
501     int_data.if_speed              = 0;
502     int_data.if_tsresol            = 6;
503     int_data.if_filter_str         = NULL;
504     int_data.bpf_filter_len        = 0;
505     int_data.if_filter_bpf_bytes   = NULL;
506     int_data.if_os                 = NULL;
507     int_data.if_fcslen             = -1;
508     int_data.num_stat_entries      = 0;          /* Number of ISB:s */
509     int_data.interface_statistics  = NULL;
510
511     g_array_append_val(idb_inf->interface_data, int_data);
512
513     /* Use a random name for the temporary import buffer */
514     info->wdh = wtap_dump_open_tempfile_ng(&tmpname, "import",
515                                            WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
516                                            info->encapsulation,
517                                            info->max_frame_length, FALSE,
518                                            shb_hdr, idb_inf, NULL, &err);
519     capfile_name = g_strdup(tmpname);
520     if (info->wdh == NULL) {
521         open_failure_alert_box(tmpname ? tmpname : "temporary file", 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, WTAP_TYPE_AUTO, 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     wtap_free_shb(shb_hdr);
569     wtap_free_idb_info(idb_inf);
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 = ws_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: 8
1219  * indent-tabs-mode: nil
1220  * End:
1221  *
1222  * vi: set shiftwidth=4 tabstop=8 expandtab:
1223  * :indentSize=4:tabSize=8:noTabs=true:
1224  */