Rename "ws_version_info.h", also .c
[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 "version_info.h"
51 #include "wiretap/wtap_opttypes.h"
52 #include "wiretap/pcapng.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     char *tmpname, *capfile_name;
458     int   err;
459
460     /* pcapng defs */
461     wtap_block_t                 shb_hdr;
462     GArray                      *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
463     wtapng_iface_descriptions_t *idb_inf;
464     wtap_block_t                 int_data;
465     wtapng_if_descr_mandatory_t *int_data_mand;
466     GString                     *os_info_str;
467     gsize                        opt_len;
468     gchar                       *opt_str;
469
470     /* Create data for SHB  */
471     os_info_str = g_string_new("");
472     get_os_version_info(os_info_str);
473
474     shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
475
476     /* options */
477     wtap_block_add_string_option_format(shb_hdr, OPT_COMMENT, "File created by File->Import of file %s", info->import_text_filename);
478
479     /*
480      * UTF-8 string containing the name of the operating system used to create
481      * this section.
482      */
483     opt_len = os_info_str->len;
484     opt_str = g_string_free(os_info_str, FALSE);
485     if (opt_str) {
486         wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, opt_str, opt_len);
487         g_free(opt_str);
488     }
489     /*
490      * UTF-8 string containing the name of the application used to create
491      * this section.
492      */
493     wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
494
495     /* Create fake IDB info */
496     idb_inf = g_new(wtapng_iface_descriptions_t,1);
497     idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
498
499     /* create the fake interface data */
500     int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
501     int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
502     int_data_mand->wtap_encap            = info->encapsulation;
503     int_data_mand->time_units_per_second = 1000000; /* default microsecond resolution */
504     int_data_mand->snap_len              = WTAP_MAX_PACKET_SIZE_STANDARD;
505     wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF File->Import", strlen("Fake IF File->Import"));
506
507     g_array_append_val(idb_inf->interface_data, int_data);
508     g_array_append_val(shb_hdrs, shb_hdr);
509
510     /* Use a random name for the temporary import buffer */
511     info->wdh = wtap_dump_open_tempfile_ng(&tmpname, "import",
512                                            WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
513                                            info->encapsulation,
514                                            info->max_frame_length, FALSE,
515                                            shb_hdrs, idb_inf, NULL, &err);
516     capfile_name = g_strdup(tmpname);
517     if (info->wdh == NULL) {
518         cfile_dump_open_failure_alert_box(tmpname ? tmpname : "temporary file",
519                                           err, WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
520         fclose(info->import_text_file);
521         goto end;
522     }
523
524     err = text_import(info);
525     if (err != 0) {
526         failure_alert_box("Can't initialize scanner: %s", g_strerror(err));
527         fclose(info->import_text_file);
528         goto end;
529     }
530
531     if (fclose(info->import_text_file)) {
532         read_failure_alert_box(info->import_text_filename, errno);
533     }
534
535     if (!wtap_dump_close(info->wdh, &err)) {
536         cfile_close_failure_alert_box(capfile_name, err);
537     }
538
539     if (cf_open(&cfile, capfile_name, WTAP_TYPE_AUTO, TRUE /* temporary file */, &err) != CF_OK) {
540         /* cf_open() put up a dialog box here */
541         goto end;
542     }
543
544     switch (cf_read(&cfile, FALSE)) {
545     case CF_READ_OK:
546     case CF_READ_ERROR:
547         /* Just because we got an error, that doesn't mean we were unable
548            to read any of the file; we handle what we could get from the
549            file. */
550         break;
551
552     case CF_READ_ABORTED:
553         /* The user bailed out of re-reading the capture file; the
554            capture file has been closed - just free the capture file name
555            string and return (without changing the last containing
556            directory). */
557         break;
558     }
559
560 end:
561     g_free(info->import_text_filename);
562     g_free(info->date_timestamp_format);
563     g_free(info);
564     g_free(capfile_name);
565     wtap_block_array_free(shb_hdrs);
566     wtap_free_idb_info(idb_inf);
567     window_destroy(file_import_dlg_w);
568 }
569
570 static text_import_info_t *
571 setup_file_import(GtkWidget *main_w)
572 {
573     GtkWidget *input_frm, *import_frm;
574
575     text_import_info_t *text_import_info = (text_import_info_t *)g_malloc0(sizeof(text_import_info_t));
576
577     /* Retrieve the input and import settings from the dialog */
578
579     /* First the main components */
580     input_frm  = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
581     import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
582
583     /* Then the input frame controls of interest */
584     {
585         GtkWidget *filename_te   = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
586         GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
587         GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
588         GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
589         GtkWidget *timefmt_cb    = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
590         GtkWidget *timefmt_te    = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
591         GtkWidget *dir_cb        = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DIR_CB_KEY));
592
593         text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
594
595         /* Try to open the input file */
596         text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
597         if (!text_import_info->import_text_file) {
598             open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
599             g_free(text_import_info->import_text_filename);
600             g_free(text_import_info->date_timestamp_format);
601             g_free(text_import_info);
602             return NULL;
603         }
604
605         text_import_info->offset_type =
606             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
607             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
608             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
609             OFFSET_NONE;
610         text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
611         text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
612         text_import_info->has_direction = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dir_cb));
613     }
614
615     /* Then the import frame controls of interest */
616     {
617         GtkWidget *encap_co            = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
618         GtkWidget *header_frm          = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
619         GtkWidget *framelen_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
620
621         /* Then the header frame controls of interest */
622         GtkWidget *header_cb           = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
623
624         GtkWidget *header_eth_rb       = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
625         GtkWidget *header_ipv4_rb      = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
626         GtkWidget *header_udp_rb       = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
627         GtkWidget *header_tcp_rb       = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
628         GtkWidget *header_sctp_rb      = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
629         GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
630
631         GtkWidget *etype_te            = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
632         GtkWidget *protocol_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
633         GtkWidget *src_port_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
634         GtkWidget *dst_port_te         = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
635         GtkWidget *tag_te              = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
636         GtkWidget *ppi_te              = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
637
638         GtkTreeIter iter;
639
640         if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter)) {
641             GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
642             gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
643         }
644
645         if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
646             (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb)))) {
647             text_import_info->dummy_header_type =
648                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb))       ? HEADER_ETH :
649                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb))      ? HEADER_IPV4 :
650                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb))       ? HEADER_UDP :
651                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb))       ? HEADER_TCP :
652                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb))      ? HEADER_SCTP :
653                 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
654                 HEADER_NONE;
655
656             switch (text_import_info->dummy_header_type) {
657             case HEADER_ETH:
658                 text_import_info->pid = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
659                 if (text_import_info->pid > 0xffff) {
660                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
661                         text_import_info->pid);
662                     g_free(text_import_info->import_text_filename);
663                     fclose(text_import_info->import_text_file);
664                     g_free(text_import_info->date_timestamp_format);
665                     g_free(text_import_info);
666                     return NULL;
667                 }
668                 break;
669
670             case HEADER_IPV4:
671                 text_import_info->protocol = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
672                 if (text_import_info->protocol > 0xff) {
673                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
674                         text_import_info->protocol);
675                     g_free(text_import_info->import_text_filename);
676                     fclose(text_import_info->import_text_file);
677                     g_free(text_import_info->date_timestamp_format);
678                     g_free(text_import_info);
679                     return NULL;
680                 }
681                 break;
682
683             case HEADER_UDP:
684             case HEADER_TCP:
685                 text_import_info->src_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
686                 if (text_import_info->src_port > 0xffff) {
687                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
688                         text_import_info->src_port);
689                     g_free(text_import_info->import_text_filename);
690                     fclose(text_import_info->import_text_file);
691                     g_free(text_import_info->date_timestamp_format);
692                     g_free(text_import_info);
693                     return NULL;
694                 }
695                 text_import_info->dst_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
696                 if (text_import_info->dst_port > 0xffff) {
697                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
698                         text_import_info->dst_port);
699                     g_free(text_import_info->import_text_filename);
700                     fclose(text_import_info->import_text_file);
701                     g_free(text_import_info->date_timestamp_format);
702                     g_free(text_import_info);
703                     return NULL;
704                 }
705                 break;
706
707             case HEADER_SCTP:
708                 text_import_info->src_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
709                 if (text_import_info->src_port > 0xffff) {
710                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
711                         text_import_info->src_port);
712                     g_free(text_import_info->import_text_filename);
713                     fclose(text_import_info->import_text_file);
714                     g_free(text_import_info->date_timestamp_format);
715                     g_free(text_import_info);
716                     return NULL;
717                 }
718                 text_import_info->dst_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
719                 if (text_import_info->dst_port > 0xffff) {
720                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
721                         text_import_info->dst_port);
722                     g_free(text_import_info->import_text_filename);
723                     fclose(text_import_info->import_text_file);
724                     g_free(text_import_info->date_timestamp_format);
725                     g_free(text_import_info);
726                     return NULL;
727                 }
728                 text_import_info->tag = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
729                 break;
730
731             case HEADER_SCTP_DATA:
732                 text_import_info->src_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
733                 if (text_import_info->src_port > 0xffff) {
734                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
735                         text_import_info->src_port);
736                     g_free(text_import_info->import_text_filename);
737                     fclose(text_import_info->import_text_file);
738                     g_free(text_import_info->date_timestamp_format);
739                     g_free(text_import_info);
740                     return NULL;
741                 }
742                 text_import_info->dst_port = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
743                 if (text_import_info->dst_port > 0xffff) {
744                     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
745                         text_import_info->dst_port);
746                     g_free(text_import_info->import_text_filename);
747                     fclose(text_import_info->import_text_file);
748                     g_free(text_import_info->date_timestamp_format);
749                     g_free(text_import_info);
750                     return NULL;
751                 }
752                 text_import_info->ppi = (guint) strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
753                 break;
754
755             default:
756                 break;
757             }
758         } else {
759             text_import_info->dummy_header_type = HEADER_NONE;
760         }
761
762         text_import_info->max_frame_length = (guint)strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
763         if (text_import_info->max_frame_length == 0) {
764             text_import_info->max_frame_length = IMPORT_MAX_PACKET;
765         } else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET) {
766             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
767                 text_import_info->max_frame_length);
768             g_free(text_import_info->import_text_filename);
769             fclose(text_import_info->import_text_file);
770             g_free(text_import_info->date_timestamp_format);
771             g_free(text_import_info);
772             return NULL;
773         }
774     }
775
776     return text_import_info;
777 }
778
779 /*****************************************************************************/
780
781 static void
782 file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
783 {
784     text_import_info_t *text_import_info;
785
786     /* If there's unsaved data, let the user save it first.
787        If they cancel out of it, don't open the file. */
788     if (do_file_close(&cfile, FALSE, " before opening a new capture file")) {
789         /* open the new file */
790         text_import_info = setup_file_import((GtkWidget *)data);
791         if (text_import_info) {
792             file_import_open(text_import_info);
793         }
794     }
795 }
796
797 static void
798 set_default_encap(GtkWidget *encap_co, guint default_encap)
799 {
800     gboolean result;
801     GtkTreeIter iter;
802     GtkTreeModel *model;
803     gboolean more_items = TRUE;
804     guint encap_value;
805
806     gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
807     result = gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter);
808     if (result) {
809         model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
810         do {
811             gtk_tree_model_get(model, &iter, ENCAP_VALUE_COLUMN, &encap_value, -1);
812             if (encap_value == default_encap) {
813                 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(encap_co), &iter);
814                 more_items = FALSE;
815             }
816             else
817                 more_items = gtk_tree_model_iter_next(model, &iter);
818         } while (more_items);
819     }
820 }
821
822 /*****************************************************************************/
823
824 /*
825  * Dialog creator
826  */
827 static GtkWidget *
828 file_import_dlg_new(void)
829 {
830     GtkWidget  *main_w, *main_vb,
831                *input_frm, *input_grid, *input_vb,
832                *filename_lbl, *filename_te, *browse_bt,
833                *offset_lbl, *offset_rb_vb,
834                *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
835                *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
836                *dir_hb, *dir_cb,
837                *import_frm, *import_vb,
838                *encap_hb, *encap_lbl, *encap_co,
839                *header_cb, *header_frm, *header_hb,
840                *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
841                *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
842                *header_rblbl_vb,
843                *header_rblbl_1_hb, *header_rblbl_1_lbl,
844                *header_rblbl_2_hb, *header_rblbl_2_lbl,
845                *header_rblbl_3_hb, *header_rblbl_3_lbl,
846                *header_rblbl_4_hb, *header_rblbl_4_lbl,
847                *header_rblbl_5_hb, *header_rblbl_5_lbl,
848                *header_rblbl_6_hb, *header_rblbl_6_lbl,
849                *etype_te, *protocol_te, *src_port_te,
850                *dst_port_te, *tag_te, *ppi_te,
851                *framelen_hb, *framelen_lbl, *framelen_te,
852                *bbox, *help_bt, *close_bt, *ok_bt;
853     gchar *maxsize_msg;
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 = ws_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     maxsize_msg = g_strdup_printf("The maximum size of the frames to write to the import capture file (max %u)",
1158                                   WTAP_MAX_PACKET_SIZE_STANDARD);
1159     gtk_widget_set_tooltip_text(framelen_te, maxsize_msg);
1160     g_free(maxsize_msg);
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  */