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