2 * Dialog to setup for import of a text file, like text2pcap
3 * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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,
39 #include "pcap-encap.h"
41 #include <epan/prefs.h>
46 #include "simple_dialog.h"
47 #include "alert_box.h"
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"
57 #include "gtk/file_import_dlg.h"
58 #include "gtk/text_import.h"
61 #include "wsutil/file_util.h"
64 #define INPUT_FRM_KEY "input_frame"
66 #define INPUT_FILENAME_TE_KEY "input_filename_text"
68 #define INPUT_OFFSET_HEX_RB_KEY "input_offset_hex_radio"
69 #define INPUT_OFFSET_OCT_RB_KEY "input_offset_oct_radio"
70 #define INPUT_OFFSET_DEC_RB_KEY "input_offset_dec_radio"
72 #define INPUT_DATETIME_CB_KEY "input_datetime_checkbox"
73 #define INPUT_TIMEFMT_LBL_KEY "input_timeformat_label"
74 #define INPUT_TIMEFMT_TE_KEY "input_timeformat_entry"
76 #define IMPORT_FRM_KEY "import_frame"
77 #define IMPORT_ENCAP_CO_KEY "import_encap_combo"
79 #define IMPORT_HEADER_FRM_KEY "import_header_frame"
80 #define IMPORT_HEADER_CB_KEY "import_header_checkbox"
81 #define IMPORT_HEADER_ETH_RB_KEY "import_header_ethernet_radio"
82 #define IMPORT_HEADER_ETYPE_LBL_KEY "import_header_etype_label"
83 #define IMPORT_HEADER_ETYPE_TE_KEY "import_header_etype_text"
84 #define IMPORT_HEADER_IPV4_RB_KEY "import_header_ipv4_radio"
85 #define IMPORT_HEADER_PROT_LBL_KEY "import_header_prot_label"
86 #define IMPORT_HEADER_PROT_TE_KEY "import_header_prot_text"
87 #define IMPORT_HEADER_UDP_RB_KEY "import_header_udp_radio"
88 #define IMPORT_HEADER_SRC_PORT_LBL_KEY "import_header_src_port_label"
89 #define IMPORT_HEADER_SRC_PORT_TE_KEY "import_header_src_port_text"
90 #define IMPORT_HEADER_TCP_RB_KEY "import_header_tcp_radio"
91 #define IMPORT_HEADER_DST_PORT_LBL_KEY "import_header_dst_port_label"
92 #define IMPORT_HEADER_DST_PORT_TE_KEY "import_header_dst_port_text"
93 #define IMPORT_HEADER_SCTP_RB_KEY "import_header_sctp_radio"
94 #define IMPORT_HEADER_TAG_LBL_KEY "import_header_tag_label"
95 #define IMPORT_HEADER_TAG_TE_KEY "import_header_tag_text"
96 #define IMPORT_HEADER_SCTP_D_RB_KEY "import_header_sctp_data_radio"
97 #define IMPORT_HEADER_PPI_LBL_KEY "import_header_ppi_label"
98 #define IMPORT_HEADER_PPI_TE_KEY "import_header_ppi_text"
100 #define IMPORT_FRAME_LENGTH_TE_KEY "import_frame_length_text"
102 static GtkWidget *file_import_dlg_w = NULL;
103 static GtkListStore *encap_list_store = NULL;
105 /*****************************************************************************/
108 file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
110 file_import_dlg_w = NULL;
113 /*****************************************************************************/
116 browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
118 file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Text",
119 FILE_SELECTION_READ_BROWSE);
123 timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
125 GtkWidget *timefmt_lbl, *timefmt_te;
128 timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
129 timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
131 apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
132 gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
133 gtk_widget_set_sensitive(timefmt_te, apply_fmt);
136 /*****************************************************************************/
138 create_encap_list_store(void)
144 encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
146 /* Scan all Wiretap encapsulation types */
147 for (encap = 1; encap < wtap_get_num_encap_types(); encap++)
149 /* Check if we can write it to a PCAP file */
150 if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) &&
152 * Exclude wtap encapsulations that require a pseudo header,
153 * because we won't setup one from the text we import and
154 * wiretap doesn't allow us to write 'raw' frames
156 !((encap == WTAP_ENCAP_ATM_PDUS) ||
157 (encap == WTAP_ENCAP_IRDA) ||
158 (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
159 (encap == WTAP_ENCAP_LINUX_LAPD) ||
160 (encap == WTAP_ENCAP_SITA) ||
161 (encap == WTAP_ENCAP_ERF) ||
162 (encap == WTAP_ENCAP_I2C) ||
163 (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
164 (encap == WTAP_ENCAP_PPP_WITH_PHDR)
167 /* If it has got a name */
168 if ((name = wtap_encap_string(encap)))
170 gtk_list_store_append(encap_list_store, &iter);
171 gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
179 fill_encap_combo(void)
181 GtkWidget *encap_co = NULL;
182 GtkCellRenderer *cell;
184 encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
185 cell = gtk_cell_renderer_text_new();
186 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
187 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
192 static void header_frm_child_set(GtkWidget *widget, gpointer data);
195 encap_co_changed(GtkComboBox *widget, gpointer data)
199 GtkWidget *header_cb;
201 result = gtk_combo_box_get_active_iter(widget, &iter);
206 GtkTreeModel *model = gtk_combo_box_get_model(widget);
207 gtk_tree_model_get(model, &iter, 1, &encap, -1);
209 if (encap != WTAP_ENCAP_ETHERNET)
215 header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
216 g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
218 gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
222 /*****************************************************************************/
225 header_frm_child_set(GtkWidget *widget, gpointer data)
227 gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
231 header_cb_toggle(GtkWidget *widget, gpointer data)
233 gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
234 GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
235 /* The frame's checkbox must stay sensitive, of course... */
236 gtk_widget_set_sensitive(widget, TRUE);
240 * Header radio button toggle handlers
243 header_eth_rb_toggle(GtkWidget *widget, gpointer data)
245 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
246 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
247 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
248 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
249 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
250 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
251 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
252 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
253 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
254 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
255 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
256 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
258 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
260 gtk_widget_set_sensitive(etype_lbl, TRUE);
261 gtk_widget_set_sensitive(etype_te, TRUE);
262 gtk_widget_set_sensitive(prot_lbl, FALSE);
263 gtk_widget_set_sensitive(prot_te, FALSE);
264 gtk_widget_set_sensitive(src_port_lbl, FALSE);
265 gtk_widget_set_sensitive(src_port_te, FALSE);
266 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
267 gtk_widget_set_sensitive(dst_port_te, FALSE);
268 gtk_widget_set_sensitive(tag_lbl, FALSE);
269 gtk_widget_set_sensitive(tag_te, FALSE);
270 gtk_widget_set_sensitive(ppi_lbl, FALSE);
271 gtk_widget_set_sensitive(ppi_te, FALSE);
275 gtk_widget_set_sensitive(etype_lbl, FALSE);
276 gtk_widget_set_sensitive(etype_te, FALSE);
281 header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
283 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
284 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
285 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
286 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
287 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
288 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
289 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
290 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
291 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
292 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
293 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
294 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
296 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
298 gtk_widget_set_sensitive(etype_lbl, FALSE);
299 gtk_widget_set_sensitive(etype_te, FALSE);
300 gtk_widget_set_sensitive(prot_lbl, TRUE);
301 gtk_widget_set_sensitive(prot_te, TRUE);
302 gtk_widget_set_sensitive(src_port_lbl, FALSE);
303 gtk_widget_set_sensitive(src_port_te, FALSE);
304 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
305 gtk_widget_set_sensitive(dst_port_te, FALSE);
306 gtk_widget_set_sensitive(tag_lbl, FALSE);
307 gtk_widget_set_sensitive(tag_te, FALSE);
308 gtk_widget_set_sensitive(ppi_lbl, FALSE);
309 gtk_widget_set_sensitive(ppi_te, FALSE);
313 gtk_widget_set_sensitive(prot_lbl, FALSE);
314 gtk_widget_set_sensitive(prot_te, FALSE);
319 header_udp_rb_toggle(GtkWidget *widget, gpointer data)
321 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
322 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
323 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
324 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
325 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
326 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
327 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
328 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
329 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
330 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
331 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
332 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
334 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
336 gtk_widget_set_sensitive(etype_lbl, FALSE);
337 gtk_widget_set_sensitive(etype_te, FALSE);
338 gtk_widget_set_sensitive(prot_lbl, FALSE);
339 gtk_widget_set_sensitive(prot_te, FALSE);
340 gtk_widget_set_sensitive(src_port_lbl, TRUE);
341 gtk_widget_set_sensitive(src_port_te, TRUE);
342 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
343 gtk_widget_set_sensitive(dst_port_te, TRUE);
344 gtk_widget_set_sensitive(tag_lbl, FALSE);
345 gtk_widget_set_sensitive(tag_te, FALSE);
346 gtk_widget_set_sensitive(ppi_lbl, FALSE);
347 gtk_widget_set_sensitive(ppi_te, FALSE);
351 gtk_widget_set_sensitive(src_port_lbl, FALSE);
352 gtk_widget_set_sensitive(src_port_te, FALSE);
353 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
354 gtk_widget_set_sensitive(dst_port_te, FALSE);
359 header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
361 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
362 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
363 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
364 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
365 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
366 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
367 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
368 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
369 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
370 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
371 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
372 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
374 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
376 gtk_widget_set_sensitive(etype_lbl, FALSE);
377 gtk_widget_set_sensitive(etype_te, FALSE);
378 gtk_widget_set_sensitive(prot_lbl, FALSE);
379 gtk_widget_set_sensitive(prot_te, FALSE);
380 gtk_widget_set_sensitive(src_port_lbl, TRUE);
381 gtk_widget_set_sensitive(src_port_te, TRUE);
382 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
383 gtk_widget_set_sensitive(dst_port_te, TRUE);
384 gtk_widget_set_sensitive(tag_lbl, FALSE);
385 gtk_widget_set_sensitive(tag_te, FALSE);
386 gtk_widget_set_sensitive(ppi_lbl, FALSE);
387 gtk_widget_set_sensitive(ppi_te, FALSE);
391 gtk_widget_set_sensitive(src_port_lbl, FALSE);
392 gtk_widget_set_sensitive(src_port_te, FALSE);
393 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
394 gtk_widget_set_sensitive(dst_port_te, FALSE);
399 header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
401 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
402 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
403 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
404 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
405 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
406 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
407 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
408 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
409 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
410 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
411 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
412 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
414 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
416 gtk_widget_set_sensitive(etype_lbl, FALSE);
417 gtk_widget_set_sensitive(etype_te, FALSE);
418 gtk_widget_set_sensitive(prot_lbl, FALSE);
419 gtk_widget_set_sensitive(prot_te, FALSE);
420 gtk_widget_set_sensitive(src_port_lbl, TRUE);
421 gtk_widget_set_sensitive(src_port_te, TRUE);
422 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
423 gtk_widget_set_sensitive(dst_port_te, TRUE);
424 gtk_widget_set_sensitive(tag_lbl, TRUE);
425 gtk_widget_set_sensitive(tag_te, TRUE);
426 gtk_widget_set_sensitive(ppi_lbl, FALSE);
427 gtk_widget_set_sensitive(ppi_te, FALSE);
431 gtk_widget_set_sensitive(src_port_lbl, FALSE);
432 gtk_widget_set_sensitive(src_port_te, FALSE);
433 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
434 gtk_widget_set_sensitive(dst_port_te, FALSE);
435 gtk_widget_set_sensitive(tag_lbl, FALSE);
436 gtk_widget_set_sensitive(tag_te, FALSE);
441 header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
443 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
444 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
445 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
446 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
447 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
448 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
449 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
450 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
451 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
452 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
453 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
454 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
456 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
458 gtk_widget_set_sensitive(etype_lbl, FALSE);
459 gtk_widget_set_sensitive(etype_te, FALSE);
460 gtk_widget_set_sensitive(prot_lbl, FALSE);
461 gtk_widget_set_sensitive(prot_te, FALSE);
462 gtk_widget_set_sensitive(src_port_lbl, TRUE);
463 gtk_widget_set_sensitive(src_port_te, TRUE);
464 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
465 gtk_widget_set_sensitive(dst_port_te, TRUE);
466 gtk_widget_set_sensitive(tag_lbl, FALSE);
467 gtk_widget_set_sensitive(tag_te, FALSE);
468 gtk_widget_set_sensitive(ppi_lbl, TRUE);
469 gtk_widget_set_sensitive(ppi_te, TRUE);
473 gtk_widget_set_sensitive(src_port_lbl, FALSE);
474 gtk_widget_set_sensitive(src_port_te, FALSE);
475 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
476 gtk_widget_set_sensitive(dst_port_te, FALSE);
477 gtk_widget_set_sensitive(ppi_lbl, FALSE);
478 gtk_widget_set_sensitive(ppi_te, FALSE);
482 /*****************************************************************************/
485 file_import_open(text_import_info_t *info)
488 char *tmpname, *capfile_name = NULL;
491 /* Choose a random name for the temporary import buffer */
492 import_file_fd = create_tempfile(&tmpname, "import");
493 capfile_name = g_strdup(tmpname);
495 info->wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_PCAP, info->encapsulation, info->max_frame_length, FALSE, &err);
496 if (info->wdh == NULL) {
497 open_failure_alert_box(capfile_name, err, TRUE);
498 fclose(info->import_text_file);
502 text_import_setup(info);
504 text_importset_in(info->import_text_file);
507 text_import_cleanup();
509 if (fclose(info->import_text_file))
511 read_failure_alert_box(info->import_text_filename, errno);
514 if (!wtap_dump_close(info->wdh, &err))
516 write_failure_alert_box(capfile_name, err);
519 if (cf_open(&cfile, capfile_name, TRUE /* temporary file */, &err) != CF_OK)
521 open_failure_alert_box(capfile_name, err, FALSE);
525 switch (cf_read(&cfile, FALSE)) {
528 /* Just because we got an error, that doesn't mean we were unable
529 to read any of the file; we handle what we could get from the
533 case CF_READ_ABORTED:
534 /* The user bailed out of re-reading the capture file; the
535 capture file has been closed - just free the capture file name
536 string and return (without changing the last containing
542 g_free(info->import_text_filename);
543 g_free(info->date_timestamp_format);
545 g_free(capfile_name);
546 window_destroy(file_import_dlg_w);
549 static text_import_info_t *
550 setup_file_import(GtkWidget *main_w)
552 GtkWidget *input_frm, *import_frm;
554 text_import_info_t *text_import_info = g_malloc0(sizeof(text_import_info_t));
556 /* Retrieve the input and import settings from the dialog */
558 /* First the main components */
559 input_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
560 import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
562 /* Then the input frame controls of interest */
564 GtkWidget *filename_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
565 GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
566 GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
567 GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
568 GtkWidget *timefmt_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
569 GtkWidget *timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
571 text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
573 /* Try to open the input file */
574 text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
575 if (!text_import_info->import_text_file) {
576 open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
577 g_free(text_import_info->import_text_filename);
578 g_free(text_import_info->date_timestamp_format);
579 g_free(text_import_info);
583 text_import_info->offset_type =
584 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
585 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
586 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
588 text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
589 text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
592 /* Then the import frame controls of interest */
594 GtkWidget *encap_co = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
595 GtkWidget *header_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
596 GtkWidget *framelen_te = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
598 /* Then the header frame controls of interest */
599 GtkWidget *header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
601 GtkWidget *header_eth_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
602 GtkWidget *header_ipv4_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
603 GtkWidget *header_udp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
604 GtkWidget *header_tcp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
605 GtkWidget *header_sctp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
606 GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
608 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
609 GtkWidget *protocol_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
610 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
611 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
612 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
613 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
617 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter))
619 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
620 gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
623 if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
624 (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb))))
626 text_import_info->dummy_header_type =
627 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb)) ? HEADER_ETH :
628 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb)) ? HEADER_IPV4 :
629 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb)) ? HEADER_UDP :
630 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb)) ? HEADER_TCP :
631 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb)) ? HEADER_SCTP :
632 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
635 switch (text_import_info->dummy_header_type)
638 text_import_info->pid = strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
639 if (text_import_info->pid > 0xffff)
641 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
642 text_import_info->pid);
643 g_free(text_import_info->import_text_filename);
644 fclose(text_import_info->import_text_file);
645 g_free(text_import_info->date_timestamp_format);
646 g_free(text_import_info);
652 text_import_info->protocol = strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
653 if (text_import_info->protocol > 0xff)
655 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
656 text_import_info->protocol);
657 g_free(text_import_info->import_text_filename);
658 fclose(text_import_info->import_text_file);
659 g_free(text_import_info->date_timestamp_format);
660 g_free(text_import_info);
667 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
668 if (text_import_info->src_port > 0xffff)
670 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
671 text_import_info->src_port);
672 g_free(text_import_info->import_text_filename);
673 fclose(text_import_info->import_text_file);
674 g_free(text_import_info->date_timestamp_format);
675 g_free(text_import_info);
678 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
679 if (text_import_info->dst_port > 0xffff)
681 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
682 text_import_info->dst_port);
683 g_free(text_import_info->import_text_filename);
684 fclose(text_import_info->import_text_file);
685 g_free(text_import_info->date_timestamp_format);
686 g_free(text_import_info);
692 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
693 if (text_import_info->src_port > 0xffff)
695 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
696 text_import_info->src_port);
697 g_free(text_import_info->import_text_filename);
698 fclose(text_import_info->import_text_file);
699 g_free(text_import_info->date_timestamp_format);
700 g_free(text_import_info);
703 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
704 if (text_import_info->dst_port > 0xffff)
706 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
707 text_import_info->dst_port);
708 g_free(text_import_info->import_text_filename);
709 fclose(text_import_info->import_text_file);
710 g_free(text_import_info->date_timestamp_format);
711 g_free(text_import_info);
714 text_import_info->tag = strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
717 case HEADER_SCTP_DATA:
718 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
719 if (text_import_info->src_port > 0xffff)
721 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
722 text_import_info->src_port);
723 g_free(text_import_info->import_text_filename);
724 fclose(text_import_info->import_text_file);
725 g_free(text_import_info->date_timestamp_format);
726 g_free(text_import_info);
729 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
730 if (text_import_info->dst_port > 0xffff)
732 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
733 text_import_info->dst_port);
734 g_free(text_import_info->import_text_filename);
735 fclose(text_import_info->import_text_file);
736 g_free(text_import_info->date_timestamp_format);
737 g_free(text_import_info);
740 text_import_info->ppi = strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
747 text_import_info->dummy_header_type = HEADER_NONE;
750 text_import_info->max_frame_length = strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
751 if (text_import_info->max_frame_length == 0) {
752 text_import_info->max_frame_length = IMPORT_MAX_PACKET;
754 else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET)
756 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
757 text_import_info->max_frame_length);
758 g_free(text_import_info->import_text_filename);
759 fclose(text_import_info->import_text_file);
760 g_free(text_import_info->date_timestamp_format);
761 g_free(text_import_info);
766 return text_import_info;
769 /*****************************************************************************/
772 file_import_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
774 text_import_info_t *text_import_info;
778 /* save file first */
779 file_save_as_cmd(after_save_no_action, NULL);
781 case ESD_BTN_DONT_SAVE:
787 g_assert_not_reached();
790 text_import_info = setup_file_import(data);
791 if (text_import_info)
792 file_import_open(text_import_info);
796 file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
798 text_import_info_t *text_import_info;
800 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
802 /* user didn't save his current file, ask him */
803 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
804 "%sSave capture file before opening a new one?%s\n\n"
805 "If you open a new capture file without saving, your capture data will be discarded.",
806 simple_dialog_primary_start(), simple_dialog_primary_end());
807 simple_dialog_set_cb(dialog, file_import_answered_cb, data);
809 /* unchanged file, just open a new one */
810 text_import_info = setup_file_import(data);
811 if (text_import_info)
812 file_import_open(text_import_info);
817 /*****************************************************************************/
823 file_import_dlg_new()
825 GtkWidget *main_w, *main_vb,
826 *input_frm, *input_tb, *input_vb,
827 *filename_hb, *filename_lbl, *filename_te, *browse_bt,
828 *offset_hb, *offset_lbl_vb, *offset_lbl, *offset_rb_vb,
829 *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
830 *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
831 *import_frm, *import_vb,
832 *encap_hb, *encap_lbl, *encap_co,
833 *header_cb, *header_frm, *header_hb,
834 *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
835 *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
837 *header_rblbl_1_hb, *header_rblbl_1_lbl,
838 *header_rblbl_2_hb, *header_rblbl_2_lbl,
839 *header_rblbl_3_hb, *header_rblbl_3_lbl,
840 *header_rblbl_4_hb, *header_rblbl_4_lbl,
841 *header_rblbl_5_hb, *header_rblbl_5_lbl,
842 *header_rblbl_6_hb, *header_rblbl_6_lbl,
844 *etype_te, *protocol_te, *src_port_te,
845 *dst_port_te, *tag_te, *ppi_te,
846 *framelen_hb, *framelen_lbl, *framelen_te,
847 *bbox, *help_bt, *close_bt, *ok_bt;
849 GSList *offset_grp, /* Offset radio button group */
850 *header_grp; /* Dummy header radio button group */
852 #if GTK_CHECK_VERSION(2,12,0)
854 GtkTooltips *tooltips = gtk_tooltips_new();
857 /* Setup the dialog */
859 main_w = dlg_window_new("Wireshark: Import from Text");
860 gtk_window_set_default_size(GTK_WINDOW(main_w), 400, 300);
862 main_vb = gtk_vbox_new(FALSE, 0);
863 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
864 gtk_container_add(GTK_CONTAINER(main_w), main_vb);
866 /* Setup the input frame */
868 input_frm = gtk_frame_new("Input");
869 gtk_box_pack_start(GTK_BOX(main_vb), input_frm, FALSE, FALSE, 0);
871 g_object_set_data(G_OBJECT(main_w), INPUT_FRM_KEY, input_frm);
873 input_vb = gtk_vbox_new(FALSE, 0);
874 gtk_container_add(GTK_CONTAINER(input_frm), input_vb);
876 input_tb = gtk_table_new(2, 3, FALSE);
877 gtk_container_set_border_width(GTK_CONTAINER(input_tb), 5);
878 gtk_box_pack_start(GTK_BOX(input_vb), input_tb, FALSE, FALSE, 0);
879 gtk_table_set_row_spacings(GTK_TABLE(input_tb), 5);
880 gtk_table_set_col_spacings(GTK_TABLE(input_tb), 5);
883 filename_hb = gtk_hbox_new(FALSE, 3);
884 gtk_container_set_border_width(GTK_CONTAINER(filename_hb), 3);
886 filename_lbl = gtk_label_new("Filename:");
887 gtk_table_attach(GTK_TABLE(input_tb), filename_lbl, 0, 1, 0, 1, 0, 0, 0, 0);
889 filename_te = gtk_entry_new();
890 #if GTK_CHECK_VERSION(2,12,0)
891 gtk_widget_set_tooltip_text(filename_te, "Set name of text file to import");
893 gtk_tooltips_set_tip(tooltips, filename_te, "Set name of text file to import", NULL);
895 gtk_table_attach_defaults(GTK_TABLE(input_tb), filename_te, 1, 2, 0, 1);
897 g_object_set_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY, filename_te);
899 browse_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
900 #if GTK_CHECK_VERSION(2,12,0)
901 gtk_widget_set_tooltip_text(browse_bt, "Browse for text file to import");
903 gtk_tooltips_set_tip(tooltips, browse_bt, "Browse for text file to import", NULL);
905 gtk_table_attach(GTK_TABLE(input_tb), browse_bt, 2, 3, 0, 1, 0, 0, 0, 0);
907 g_signal_connect(browse_bt, "clicked", G_CALLBACK(browse_file_cb), filename_te);
910 offset_hb = gtk_hbox_new(FALSE, 3);
911 gtk_container_set_border_width(GTK_CONTAINER(offset_hb), 3);
912 gtk_box_pack_start(GTK_BOX(input_vb), offset_hb, FALSE, FALSE, 0);
914 offset_lbl_vb = gtk_vbox_new(FALSE, 0);
915 gtk_box_pack_start(GTK_BOX(offset_hb), offset_lbl_vb, FALSE, FALSE, 0);
917 offset_lbl = gtk_label_new("Offsets:");
918 gtk_misc_set_alignment(GTK_MISC(offset_lbl), 1.0f, 0.0f);
919 gtk_table_attach(GTK_TABLE(input_tb), offset_lbl, 0, 1, 1, 2, 0, 0, 0, 0);
921 offset_rb_vb = gtk_vbox_new(FALSE, 0);
922 gtk_table_attach_defaults(GTK_TABLE(input_tb), offset_rb_vb, 1, 2, 1, 2);
924 offset_hex_rb = gtk_radio_button_new_with_label(NULL, "Hexadecimal");
925 #if GTK_CHECK_VERSION(2,12,0)
926 gtk_widget_set_tooltip_text(offset_hex_rb, "Offsets in the text file are in hexadecimal notation");
928 gtk_tooltips_set_tip(tooltips, offset_hex_rb, "Offsets in the text file are in hexadecimal notation", NULL);
930 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_hex_rb, FALSE, FALSE, 0);
932 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY, offset_hex_rb);
934 offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_hex_rb));
935 offset_oct_rb = gtk_radio_button_new_with_label(offset_grp, "Octal");
936 #if GTK_CHECK_VERSION(2,12,0)
937 gtk_widget_set_tooltip_text(offset_oct_rb, "Offsets in the text file are in octal notation");
939 gtk_tooltips_set_tip(tooltips, offset_oct_rb, "Offsets in the text file are in octal notation", NULL);
941 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_oct_rb, FALSE, FALSE, 0);
943 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY, offset_oct_rb);
945 offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_oct_rb));
946 offset_dec_rb = gtk_radio_button_new_with_label(offset_grp, "Decimal");
947 #if GTK_CHECK_VERSION(2,12,0)
948 gtk_widget_set_tooltip_text(offset_dec_rb, "Offsets in the text file are in decimal notation");
950 gtk_tooltips_set_tip(tooltips, offset_dec_rb, "Offsets in the text file are in decimal notation", NULL);
952 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_dec_rb, FALSE, FALSE, 0);
954 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY, offset_dec_rb);
957 timefmt_hb = gtk_hbox_new(FALSE, 3);
958 gtk_container_set_border_width(GTK_CONTAINER(timefmt_hb), 3);
959 gtk_box_pack_start(GTK_BOX(input_vb), timefmt_hb, FALSE, FALSE, 0);
961 timefmt_cb = gtk_check_button_new_with_label("Date/Time");
962 #if GTK_CHECK_VERSION(2,12,0)
963 gtk_widget_set_tooltip_text(timefmt_cb, "Whether or not the text file contains timestamp information");
965 gtk_tooltips_set_tip(tooltips, timefmt_cb, "Whether or not the text file contains timestamp information", NULL);
967 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_cb, FALSE, FALSE, 0);
969 g_object_set_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY, timefmt_cb);
971 timefmt_lbl = gtk_label_new(" Format:");
972 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_lbl, FALSE, FALSE, 0);
974 g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_LBL_KEY, timefmt_lbl);
976 timefmt_te = gtk_entry_new();
977 #if GTK_CHECK_VERSION(2,12,0)
978 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)");
980 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);
982 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_te, FALSE, FALSE, 0);
984 g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_TE_KEY, timefmt_te);
985 g_object_set_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY, timefmt_te);
987 g_signal_connect(timefmt_cb, "toggled", G_CALLBACK(timefmt_cb_toggle), NULL);
988 g_signal_emit_by_name(G_OBJECT(timefmt_cb), "toggled", NULL);
990 /* Setup the import frame */
992 import_frm = gtk_frame_new("Import");
993 gtk_box_pack_start(GTK_BOX(main_vb), import_frm, TRUE, TRUE, 3);
995 g_object_set_data(G_OBJECT(main_w), IMPORT_FRM_KEY, import_frm);
997 import_vb = gtk_vbox_new(FALSE, 0);
998 gtk_container_add(GTK_CONTAINER(import_frm), import_vb);
1001 encap_hb = gtk_hbox_new(FALSE, 3);
1002 gtk_container_set_border_width(GTK_CONTAINER(encap_hb), 3);
1003 gtk_box_pack_start(GTK_BOX(import_vb), encap_hb, FALSE, FALSE, 0);
1005 encap_lbl = gtk_label_new("Encapsulation type:");
1006 gtk_box_pack_start(GTK_BOX(encap_hb), encap_lbl, FALSE, FALSE, 0);
1008 encap_co = fill_encap_combo();
1009 #if GTK_CHECK_VERSION(2,12,0)
1010 gtk_widget_set_tooltip_text(encap_co, "Encapsulation type for the frames in the import capture file");
1012 gtk_tooltips_set_tip(tooltips, encap_co, "Encapsulation type for the frames in the import capture file", NULL);
1014 gtk_box_pack_start(GTK_BOX(encap_hb), encap_co, FALSE, FALSE, 0);
1016 g_object_set_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY, encap_co);
1019 header_frm = gtk_frame_new(NULL);
1020 header_cb = gtk_check_button_new_with_label("Dummy header");
1021 #if GTK_CHECK_VERSION(2,12,0)
1022 gtk_widget_set_tooltip_text(header_cb, "Whether or not to prefix a dummy header to the frames");
1024 gtk_tooltips_set_tip(tooltips, header_cb, "Whether or not to prefix a dummy header to the frames", NULL);
1026 gtk_frame_set_label_widget(GTK_FRAME(header_frm), header_cb);
1027 gtk_container_set_border_width(GTK_CONTAINER(header_frm), 3);
1028 gtk_box_pack_start(GTK_BOX(import_vb), header_frm, FALSE, FALSE, 0);
1030 g_object_set_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY, header_frm);
1031 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY, header_cb);
1033 header_hb = gtk_hbox_new(FALSE, 3);
1034 gtk_container_set_border_width(GTK_CONTAINER(header_hb), 3);
1035 gtk_container_add(GTK_CONTAINER(header_frm), header_hb);
1037 header_rblbl_vb = gtk_vbox_new(FALSE, 0);
1038 gtk_box_pack_start(GTK_BOX(header_hb), header_rblbl_vb, TRUE, TRUE, 0);
1040 header_entries_vb = gtk_vbox_new(FALSE, 0);
1041 gtk_box_pack_start(GTK_BOX(header_hb), header_entries_vb, FALSE, FALSE, 0);
1044 header_rblbl_1_hb = gtk_hbox_new(FALSE, 0);
1045 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_1_hb, FALSE, FALSE, 2);
1047 header_eth_rb = gtk_radio_button_new_with_label(NULL, "Ethernet");
1048 #if GTK_CHECK_VERSION(2,12,0)
1049 gtk_widget_set_tooltip_text(header_eth_rb, "Prefix an Ethernet header to the frames");
1051 gtk_tooltips_set_tip(tooltips, header_eth_rb, "Prefix an Ethernet header to the frames", NULL);
1053 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_eth_rb));
1054 g_signal_connect(header_eth_rb, "toggled", G_CALLBACK(header_eth_rb_toggle), header_frm);
1055 gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_eth_rb, FALSE, FALSE, 0);
1057 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY, header_eth_rb);
1059 header_rblbl_1_lbl = gtk_label_new(" Ethertype (hex):");
1060 gtk_box_pack_end(GTK_BOX(header_rblbl_1_hb), header_rblbl_1_lbl, TRUE, TRUE, 0);
1061 gtk_misc_set_alignment(GTK_MISC(header_rblbl_1_lbl), 1.0f, 0.5f);
1063 etype_te = gtk_entry_new();
1064 #if GTK_CHECK_VERSION(2,12,0)
1065 gtk_widget_set_tooltip_text(etype_te, "The type to set in the Ethernet header");
1067 gtk_tooltips_set_tip(tooltips, etype_te, "The type to set in the Ethernet header", NULL);
1069 gtk_box_pack_start(GTK_BOX(header_entries_vb), etype_te, FALSE, FALSE, 0);
1071 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_LBL_KEY, header_rblbl_1_lbl);
1072 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY, etype_te);
1075 header_rblbl_2_hb = gtk_hbox_new(FALSE, 0);
1076 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_2_hb, FALSE, FALSE, 2);
1078 header_ipv4_rb = gtk_radio_button_new_with_label(header_grp, "IPv4");
1079 #if GTK_CHECK_VERSION(2,12,0)
1080 gtk_widget_set_tooltip_text(header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames");
1082 gtk_tooltips_set_tip(tooltips, header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames", NULL);
1084 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_ipv4_rb));
1085 g_signal_connect(header_ipv4_rb, "toggled", G_CALLBACK(header_ipv4_rb_toggle), header_frm);
1086 gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_ipv4_rb, FALSE, FALSE, 0);
1088 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY, header_ipv4_rb);
1090 header_rblbl_2_lbl = gtk_label_new(" Protocol (dec):");
1091 gtk_box_pack_end(GTK_BOX(header_rblbl_2_hb), header_rblbl_2_lbl, TRUE, TRUE, 0);
1092 gtk_misc_set_alignment(GTK_MISC(header_rblbl_2_lbl), 1.0f, 0.5f);
1094 protocol_te = gtk_entry_new();
1095 #if GTK_CHECK_VERSION(2,12,0)
1096 gtk_widget_set_tooltip_text(protocol_te, "The protocol id to set in the IPv4 header");
1098 gtk_tooltips_set_tip(tooltips, protocol_te, "The protocol id to set in the IPv4 header", NULL);
1100 gtk_box_pack_start(GTK_BOX(header_entries_vb), protocol_te, FALSE, FALSE, 0);
1102 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_LBL_KEY, header_rblbl_2_lbl);
1103 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY, protocol_te);
1106 header_rblbl_3_hb = gtk_hbox_new(FALSE, 0);
1107 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_3_hb, FALSE, FALSE, 2);
1109 header_udp_rb = gtk_radio_button_new_with_label(header_grp, "UDP");
1110 #if GTK_CHECK_VERSION(2,12,0)
1111 gtk_widget_set_tooltip_text(header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames");
1113 gtk_tooltips_set_tip(tooltips, header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames", NULL);
1115 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_udp_rb));
1116 g_signal_connect(header_udp_rb, "toggled", G_CALLBACK(header_udp_rb_toggle), header_frm);
1117 gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_udp_rb, FALSE, FALSE, 0);
1119 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY, header_udp_rb);
1121 header_rblbl_3_lbl = gtk_label_new(" Source port:");
1122 gtk_box_pack_end(GTK_BOX(header_rblbl_3_hb), header_rblbl_3_lbl, TRUE, TRUE, 0);
1123 gtk_misc_set_alignment(GTK_MISC(header_rblbl_3_lbl), 1.0f, 0.5f);
1125 src_port_te = gtk_entry_new();
1126 #if GTK_CHECK_VERSION(2,12,0)
1127 gtk_widget_set_tooltip_text(src_port_te, "The source port to set in the UDP, TCP or SCTP header");
1129 gtk_tooltips_set_tip(tooltips, src_port_te, "The source port to set in the UDP, TCP or SCTP header", NULL);
1131 gtk_box_pack_start(GTK_BOX(header_entries_vb), src_port_te, FALSE, FALSE, 0);
1133 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_LBL_KEY, header_rblbl_3_lbl);
1134 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY, src_port_te);
1137 header_rblbl_4_hb = gtk_hbox_new(FALSE, 0);
1138 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_4_hb, FALSE, FALSE, 2);
1140 header_tcp_rb = gtk_radio_button_new_with_label(header_grp, "TCP");
1141 #if GTK_CHECK_VERSION(2,12,0)
1142 gtk_widget_set_tooltip_text(header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames");
1144 gtk_tooltips_set_tip(tooltips, header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames", NULL);
1146 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_tcp_rb));
1147 g_signal_connect(header_tcp_rb, "toggled", G_CALLBACK(header_tcp_rb_toggle), header_frm);
1148 gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_tcp_rb, FALSE, FALSE, 0);
1150 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY, header_tcp_rb);
1152 header_rblbl_4_lbl = gtk_label_new(" Destination port:");
1153 gtk_box_pack_end(GTK_BOX(header_rblbl_4_hb), header_rblbl_4_lbl, TRUE, TRUE, 0);
1154 gtk_misc_set_alignment(GTK_MISC(header_rblbl_4_lbl), 1.0f, 0.5f);
1156 dst_port_te = gtk_entry_new();
1157 #if GTK_CHECK_VERSION(2,12,0)
1158 gtk_widget_set_tooltip_text(dst_port_te, "The destination port to set in the UDP, TCP or SCTP header");
1160 gtk_tooltips_set_tip(tooltips, dst_port_te, "The destination port to set in the UDP, TCP or SCTP header", NULL);
1162 gtk_box_pack_start(GTK_BOX(header_entries_vb), dst_port_te, FALSE, FALSE, 0);
1164 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_LBL_KEY, header_rblbl_4_lbl);
1165 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY, dst_port_te);
1168 header_rblbl_5_hb = gtk_hbox_new(FALSE, 0);
1169 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_5_hb, FALSE, FALSE, 2);
1171 header_sctp_rb = gtk_radio_button_new_with_label(header_grp, "SCTP");
1172 #if GTK_CHECK_VERSION(2,12,0)
1173 gtk_widget_set_tooltip_text(header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames");
1175 gtk_tooltips_set_tip(tooltips, header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames", NULL);
1177 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_rb));
1178 g_signal_connect(header_sctp_rb, "toggled", G_CALLBACK(header_sctp_rb_toggle), header_frm);
1179 gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_sctp_rb, FALSE, FALSE, 0);
1181 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY, header_sctp_rb);
1183 header_rblbl_5_lbl = gtk_label_new(" Tag:");
1184 gtk_box_pack_end(GTK_BOX(header_rblbl_5_hb), header_rblbl_5_lbl, TRUE, TRUE, 0);
1185 gtk_misc_set_alignment(GTK_MISC(header_rblbl_5_lbl), 1.0f, 0.5f);
1187 tag_te = gtk_entry_new();
1188 #if GTK_CHECK_VERSION(2,12,0)
1189 gtk_widget_set_tooltip_text(tag_te, "The verification tag to set in the SCTP header");
1191 gtk_tooltips_set_tip(tooltips, tag_te, "The verification tag to set in the SCTP header", NULL);
1193 gtk_box_pack_start(GTK_BOX(header_entries_vb), tag_te, FALSE, FALSE, 0);
1195 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_LBL_KEY, header_rblbl_5_lbl);
1196 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY, tag_te);
1199 header_rblbl_6_hb = gtk_hbox_new(FALSE, 0);
1200 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_6_hb, FALSE, FALSE, 2);
1202 header_sctp_data_rb = gtk_radio_button_new_with_label(header_grp, "SCTP (DATA)");
1203 #if GTK_CHECK_VERSION(2,12,0)
1204 gtk_widget_set_tooltip_text(header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames");
1206 gtk_tooltips_set_tip(tooltips, header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames", NULL);
1208 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_data_rb));
1209 g_signal_connect(header_sctp_data_rb, "toggled", G_CALLBACK(header_sctp_data_rb_toggle), header_frm);
1210 gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_sctp_data_rb, FALSE, FALSE, 0);
1212 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY, header_sctp_data_rb);
1214 header_rblbl_6_lbl = gtk_label_new(" PPI:");
1215 gtk_box_pack_end(GTK_BOX(header_rblbl_6_hb), header_rblbl_6_lbl, TRUE, TRUE, 0);
1216 gtk_misc_set_alignment(GTK_MISC(header_rblbl_6_lbl), 1.0f, 0.5f);
1218 ppi_te = gtk_entry_new();
1219 #if GTK_CHECK_VERSION(2,12,0)
1220 gtk_widget_set_tooltip_text(ppi_te, "The payload protocol identifier to set in the SCTP DATA header");
1222 gtk_tooltips_set_tip(tooltips, ppi_te, "The payload protocol identifier to set in the SCTP DATA header", NULL);
1224 gtk_box_pack_start(GTK_BOX(header_entries_vb), ppi_te, FALSE, FALSE, 0);
1226 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_LBL_KEY, header_rblbl_6_lbl);
1227 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY, ppi_te);
1229 /* Set sensitivity */
1230 g_signal_connect(header_cb, "toggled", G_CALLBACK(header_cb_toggle), header_frm);
1231 g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", header_frm);
1233 g_signal_emit_by_name(G_OBJECT(header_eth_rb), "toggled", header_frm);
1235 g_signal_connect(encap_co, "changed", G_CALLBACK(encap_co_changed), header_frm);
1236 gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
1239 framelen_hb = gtk_hbox_new(FALSE, 3);
1240 gtk_container_set_border_width(GTK_CONTAINER(framelen_hb), 3);
1241 gtk_box_pack_start(GTK_BOX(import_vb), framelen_hb, FALSE, FALSE, 0);
1243 framelen_lbl = gtk_label_new("Max. frame length:");
1244 gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_lbl, FALSE, FALSE, 0);
1246 framelen_te = gtk_entry_new();
1247 #if GTK_CHECK_VERSION(2,12,0)
1248 gtk_widget_set_tooltip_text(framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)");
1250 gtk_tooltips_set_tip(tooltips, framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)", NULL);
1252 gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_te, FALSE, FALSE, 0);
1254 g_object_set_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY, framelen_te);
1256 /* Setup the button row */
1258 bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1259 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
1261 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1262 /* TODO: Create a Help chapter, make a proper reference, add it to help_dlg */
1263 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_CONTENT);
1264 #if GTK_CHECK_VERSION(2,12,0)
1265 gtk_widget_set_tooltip_text(help_bt, "Show topic specific help");
1267 gtk_tooltips_set_tip(tooltips, help_bt, "Show topic specific help", NULL);
1270 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1271 window_set_cancel_button(main_w, close_bt, window_cancel_button_cb);
1272 #if GTK_CHECK_VERSION(2,12,0)
1273 gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
1275 gtk_tooltips_set_tip(tooltips, close_bt, "Close this dialog", NULL);
1278 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1279 g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_import_ok_cb), main_w);
1280 gtk_widget_grab_default(ok_bt);
1281 #if GTK_CHECK_VERSION(2,12,0)
1282 gtk_widget_set_tooltip_text(ok_bt, "Import the selected file into a temporary capture file");
1284 gtk_tooltips_set_tip(tooltips, ok_bt, "Import the selected file into a temporary capture file", NULL);
1287 /* Setup widget handling */
1289 g_signal_connect(main_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1290 g_signal_connect(main_w, "destroy", G_CALLBACK(file_import_dlg_destroy_cb), NULL);
1292 gtk_widget_show_all(main_w);
1293 window_present(main_w);
1299 file_import_cmd_cb(GtkWidget *widget _U_)
1301 /* Do we have an encapsulation type list? */
1302 if (!encap_list_store)
1304 /* No. Create one. */
1305 create_encap_list_store();
1308 /* Has a file import dialog already been opened? */
1309 if (file_import_dlg_w)
1311 /* Yes. Just re-activate that dialog box. */
1312 reactivate_window(file_import_dlg_w);
1314 /* No. Create one */
1315 file_import_dlg_w = file_import_dlg_new();