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>
47 #include "ui/simple_dialog.h"
48 #include "ui/alert_box.h"
50 #include "ui/gtk/gtkglobals.h"
51 #include "ui/gtk/stock_icons.h"
52 #include "ui/gtk/dlg_utils.h"
53 #include "ui/gtk/gui_utils.h"
54 #include "ui/gtk/file_dlg.h"
55 #include "ui/gtk/capture_file_dlg.h"
56 #include "ui/gtk/help_dlg.h"
58 #include "ui/gtk/file_import_dlg.h"
59 #include "ui/gtk/text_import.h"
60 #include "ui/gtk/text_import_scanner.h"
63 #include "wsutil/file_util.h"
66 #define INPUT_FRM_KEY "input_frame"
68 #define INPUT_FILENAME_TE_KEY "input_filename_text"
70 #define INPUT_OFFSET_HEX_RB_KEY "input_offset_hex_radio"
71 #define INPUT_OFFSET_OCT_RB_KEY "input_offset_oct_radio"
72 #define INPUT_OFFSET_DEC_RB_KEY "input_offset_dec_radio"
74 #define INPUT_DATETIME_CB_KEY "input_datetime_checkbox"
75 #define INPUT_TIMEFMT_LBL_KEY "input_timeformat_label"
76 #define INPUT_TIMEFMT_TE_KEY "input_timeformat_entry"
78 #define IMPORT_FRM_KEY "import_frame"
79 #define IMPORT_ENCAP_CO_KEY "import_encap_combo"
81 #define IMPORT_HEADER_FRM_KEY "import_header_frame"
82 #define IMPORT_HEADER_CB_KEY "import_header_checkbox"
83 #define IMPORT_HEADER_ETH_RB_KEY "import_header_ethernet_radio"
84 #define IMPORT_HEADER_ETYPE_LBL_KEY "import_header_etype_label"
85 #define IMPORT_HEADER_ETYPE_TE_KEY "import_header_etype_text"
86 #define IMPORT_HEADER_IPV4_RB_KEY "import_header_ipv4_radio"
87 #define IMPORT_HEADER_PROT_LBL_KEY "import_header_prot_label"
88 #define IMPORT_HEADER_PROT_TE_KEY "import_header_prot_text"
89 #define IMPORT_HEADER_UDP_RB_KEY "import_header_udp_radio"
90 #define IMPORT_HEADER_SRC_PORT_LBL_KEY "import_header_src_port_label"
91 #define IMPORT_HEADER_SRC_PORT_TE_KEY "import_header_src_port_text"
92 #define IMPORT_HEADER_TCP_RB_KEY "import_header_tcp_radio"
93 #define IMPORT_HEADER_DST_PORT_LBL_KEY "import_header_dst_port_label"
94 #define IMPORT_HEADER_DST_PORT_TE_KEY "import_header_dst_port_text"
95 #define IMPORT_HEADER_SCTP_RB_KEY "import_header_sctp_radio"
96 #define IMPORT_HEADER_TAG_LBL_KEY "import_header_tag_label"
97 #define IMPORT_HEADER_TAG_TE_KEY "import_header_tag_text"
98 #define IMPORT_HEADER_SCTP_D_RB_KEY "import_header_sctp_data_radio"
99 #define IMPORT_HEADER_PPI_LBL_KEY "import_header_ppi_label"
100 #define IMPORT_HEADER_PPI_TE_KEY "import_header_ppi_text"
102 #define IMPORT_FRAME_LENGTH_TE_KEY "import_frame_length_text"
104 static GtkWidget *file_import_dlg_w = NULL;
105 static GtkListStore *encap_list_store = NULL;
107 /*****************************************************************************/
110 file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
112 file_import_dlg_w = NULL;
115 /*****************************************************************************/
118 browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
120 file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Text",
121 FILE_SELECTION_READ_BROWSE);
125 timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
127 GtkWidget *timefmt_lbl, *timefmt_te;
130 timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
131 timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
133 apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
134 gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
135 gtk_widget_set_sensitive(timefmt_te, apply_fmt);
138 /*****************************************************************************/
140 create_encap_list_store(void)
146 encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
148 /* Scan all Wiretap encapsulation types */
149 for (encap = 1; encap < wtap_get_num_encap_types(); encap++)
151 /* Check if we can write it to a PCAP file */
152 if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) &&
154 * Exclude wtap encapsulations that require a pseudo header,
155 * because we won't setup one from the text we import and
156 * wiretap doesn't allow us to write 'raw' frames
158 !((encap == WTAP_ENCAP_ATM_PDUS) ||
159 (encap == WTAP_ENCAP_IRDA) ||
160 (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
161 (encap == WTAP_ENCAP_LINUX_LAPD) ||
162 (encap == WTAP_ENCAP_SITA) ||
163 (encap == WTAP_ENCAP_ERF) ||
164 (encap == WTAP_ENCAP_I2C) ||
165 (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
166 (encap == WTAP_ENCAP_PPP_WITH_PHDR)
169 /* If it has got a name */
170 if ((name = wtap_encap_string(encap)))
172 gtk_list_store_append(encap_list_store, &iter);
173 gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
181 fill_encap_combo(void)
183 GtkWidget *encap_co = NULL;
184 GtkCellRenderer *cell;
186 encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
187 cell = gtk_cell_renderer_text_new();
188 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
189 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
194 static void header_frm_child_set(GtkWidget *widget, gpointer data);
197 encap_co_changed(GtkComboBox *widget, gpointer data)
201 GtkWidget *header_cb;
203 result = gtk_combo_box_get_active_iter(widget, &iter);
208 GtkTreeModel *model = gtk_combo_box_get_model(widget);
209 gtk_tree_model_get(model, &iter, 1, &encap, -1);
211 if (encap != WTAP_ENCAP_ETHERNET)
217 header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
218 g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
220 gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
224 /*****************************************************************************/
227 header_frm_child_set(GtkWidget *widget, gpointer data)
229 gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
233 header_cb_toggle(GtkWidget *widget, gpointer data)
235 gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
236 GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
237 /* The frame's checkbox must stay sensitive, of course... */
238 gtk_widget_set_sensitive(widget, TRUE);
242 * Header radio button toggle handlers
245 header_eth_rb_toggle(GtkWidget *widget, gpointer data)
247 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
248 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
249 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
250 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
251 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
252 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
253 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
254 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
255 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
256 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
257 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
258 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
260 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
262 gtk_widget_set_sensitive(etype_lbl, TRUE);
263 gtk_widget_set_sensitive(etype_te, TRUE);
264 gtk_widget_set_sensitive(prot_lbl, FALSE);
265 gtk_widget_set_sensitive(prot_te, FALSE);
266 gtk_widget_set_sensitive(src_port_lbl, FALSE);
267 gtk_widget_set_sensitive(src_port_te, FALSE);
268 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
269 gtk_widget_set_sensitive(dst_port_te, FALSE);
270 gtk_widget_set_sensitive(tag_lbl, FALSE);
271 gtk_widget_set_sensitive(tag_te, FALSE);
272 gtk_widget_set_sensitive(ppi_lbl, FALSE);
273 gtk_widget_set_sensitive(ppi_te, FALSE);
277 gtk_widget_set_sensitive(etype_lbl, FALSE);
278 gtk_widget_set_sensitive(etype_te, FALSE);
283 header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
285 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
286 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
287 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
288 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
289 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
290 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
291 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
292 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
293 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
294 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
295 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
296 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
298 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
300 gtk_widget_set_sensitive(etype_lbl, FALSE);
301 gtk_widget_set_sensitive(etype_te, FALSE);
302 gtk_widget_set_sensitive(prot_lbl, TRUE);
303 gtk_widget_set_sensitive(prot_te, TRUE);
304 gtk_widget_set_sensitive(src_port_lbl, FALSE);
305 gtk_widget_set_sensitive(src_port_te, FALSE);
306 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
307 gtk_widget_set_sensitive(dst_port_te, FALSE);
308 gtk_widget_set_sensitive(tag_lbl, FALSE);
309 gtk_widget_set_sensitive(tag_te, FALSE);
310 gtk_widget_set_sensitive(ppi_lbl, FALSE);
311 gtk_widget_set_sensitive(ppi_te, FALSE);
315 gtk_widget_set_sensitive(prot_lbl, FALSE);
316 gtk_widget_set_sensitive(prot_te, FALSE);
321 header_udp_rb_toggle(GtkWidget *widget, gpointer data)
323 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
324 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
325 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
326 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
327 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
328 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
329 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
330 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
331 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
332 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
333 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
334 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
336 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
338 gtk_widget_set_sensitive(etype_lbl, FALSE);
339 gtk_widget_set_sensitive(etype_te, FALSE);
340 gtk_widget_set_sensitive(prot_lbl, FALSE);
341 gtk_widget_set_sensitive(prot_te, FALSE);
342 gtk_widget_set_sensitive(src_port_lbl, TRUE);
343 gtk_widget_set_sensitive(src_port_te, TRUE);
344 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
345 gtk_widget_set_sensitive(dst_port_te, TRUE);
346 gtk_widget_set_sensitive(tag_lbl, FALSE);
347 gtk_widget_set_sensitive(tag_te, FALSE);
348 gtk_widget_set_sensitive(ppi_lbl, FALSE);
349 gtk_widget_set_sensitive(ppi_te, FALSE);
353 gtk_widget_set_sensitive(src_port_lbl, FALSE);
354 gtk_widget_set_sensitive(src_port_te, FALSE);
355 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
356 gtk_widget_set_sensitive(dst_port_te, FALSE);
361 header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
363 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
364 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
365 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
366 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
367 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
368 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
369 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
370 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
371 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
372 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
373 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
374 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
376 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
378 gtk_widget_set_sensitive(etype_lbl, FALSE);
379 gtk_widget_set_sensitive(etype_te, FALSE);
380 gtk_widget_set_sensitive(prot_lbl, FALSE);
381 gtk_widget_set_sensitive(prot_te, FALSE);
382 gtk_widget_set_sensitive(src_port_lbl, TRUE);
383 gtk_widget_set_sensitive(src_port_te, TRUE);
384 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
385 gtk_widget_set_sensitive(dst_port_te, TRUE);
386 gtk_widget_set_sensitive(tag_lbl, FALSE);
387 gtk_widget_set_sensitive(tag_te, FALSE);
388 gtk_widget_set_sensitive(ppi_lbl, FALSE);
389 gtk_widget_set_sensitive(ppi_te, FALSE);
393 gtk_widget_set_sensitive(src_port_lbl, FALSE);
394 gtk_widget_set_sensitive(src_port_te, FALSE);
395 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
396 gtk_widget_set_sensitive(dst_port_te, FALSE);
401 header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
403 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
404 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
405 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
406 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
407 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
408 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
409 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
410 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
411 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
412 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
413 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
414 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
416 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
418 gtk_widget_set_sensitive(etype_lbl, FALSE);
419 gtk_widget_set_sensitive(etype_te, FALSE);
420 gtk_widget_set_sensitive(prot_lbl, FALSE);
421 gtk_widget_set_sensitive(prot_te, FALSE);
422 gtk_widget_set_sensitive(src_port_lbl, TRUE);
423 gtk_widget_set_sensitive(src_port_te, TRUE);
424 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
425 gtk_widget_set_sensitive(dst_port_te, TRUE);
426 gtk_widget_set_sensitive(tag_lbl, TRUE);
427 gtk_widget_set_sensitive(tag_te, TRUE);
428 gtk_widget_set_sensitive(ppi_lbl, FALSE);
429 gtk_widget_set_sensitive(ppi_te, FALSE);
433 gtk_widget_set_sensitive(src_port_lbl, FALSE);
434 gtk_widget_set_sensitive(src_port_te, FALSE);
435 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
436 gtk_widget_set_sensitive(dst_port_te, FALSE);
437 gtk_widget_set_sensitive(tag_lbl, FALSE);
438 gtk_widget_set_sensitive(tag_te, FALSE);
443 header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
445 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
446 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
447 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
448 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
449 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
450 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
451 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
452 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
453 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
454 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
455 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
456 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
458 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
460 gtk_widget_set_sensitive(etype_lbl, FALSE);
461 gtk_widget_set_sensitive(etype_te, FALSE);
462 gtk_widget_set_sensitive(prot_lbl, FALSE);
463 gtk_widget_set_sensitive(prot_te, FALSE);
464 gtk_widget_set_sensitive(src_port_lbl, TRUE);
465 gtk_widget_set_sensitive(src_port_te, TRUE);
466 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
467 gtk_widget_set_sensitive(dst_port_te, TRUE);
468 gtk_widget_set_sensitive(tag_lbl, FALSE);
469 gtk_widget_set_sensitive(tag_te, FALSE);
470 gtk_widget_set_sensitive(ppi_lbl, TRUE);
471 gtk_widget_set_sensitive(ppi_te, TRUE);
475 gtk_widget_set_sensitive(src_port_lbl, FALSE);
476 gtk_widget_set_sensitive(src_port_te, FALSE);
477 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
478 gtk_widget_set_sensitive(dst_port_te, FALSE);
479 gtk_widget_set_sensitive(ppi_lbl, FALSE);
480 gtk_widget_set_sensitive(ppi_te, FALSE);
484 /*****************************************************************************/
487 file_import_open(text_import_info_t *info)
490 char *tmpname, *capfile_name = NULL;
493 /* Choose a random name for the temporary import buffer */
494 import_file_fd = create_tempfile(&tmpname, "import");
495 capfile_name = g_strdup(tmpname);
497 info->wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_PCAP, info->encapsulation, info->max_frame_length, FALSE, &err);
498 if (info->wdh == NULL) {
499 open_failure_alert_box(capfile_name, err, TRUE);
500 fclose(info->import_text_file);
504 text_import_setup(info);
506 text_importin = info->import_text_file;
510 text_import_cleanup();
512 if (fclose(info->import_text_file))
514 read_failure_alert_box(info->import_text_filename, errno);
517 if (!wtap_dump_close(info->wdh, &err))
519 write_failure_alert_box(capfile_name, err);
522 if (cf_open(&cfile, capfile_name, TRUE /* temporary file */, &err) != CF_OK)
524 open_failure_alert_box(capfile_name, err, FALSE);
528 switch (cf_read(&cfile, FALSE)) {
531 /* Just because we got an error, that doesn't mean we were unable
532 to read any of the file; we handle what we could get from the
536 case CF_READ_ABORTED:
537 /* The user bailed out of re-reading the capture file; the
538 capture file has been closed - just free the capture file name
539 string and return (without changing the last containing
545 g_free(info->import_text_filename);
546 g_free(info->date_timestamp_format);
548 g_free(capfile_name);
549 window_destroy(file_import_dlg_w);
552 static text_import_info_t *
553 setup_file_import(GtkWidget *main_w)
555 GtkWidget *input_frm, *import_frm;
557 text_import_info_t *text_import_info = g_malloc0(sizeof(text_import_info_t));
559 /* Retrieve the input and import settings from the dialog */
561 /* First the main components */
562 input_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
563 import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
565 /* Then the input frame controls of interest */
567 GtkWidget *filename_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
568 GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
569 GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
570 GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
571 GtkWidget *timefmt_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
572 GtkWidget *timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
574 text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
576 /* Try to open the input file */
577 text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
578 if (!text_import_info->import_text_file) {
579 open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
580 g_free(text_import_info->import_text_filename);
581 g_free(text_import_info->date_timestamp_format);
582 g_free(text_import_info);
586 text_import_info->offset_type =
587 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
588 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
589 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
591 text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
592 text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
595 /* Then the import frame controls of interest */
597 GtkWidget *encap_co = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
598 GtkWidget *header_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
599 GtkWidget *framelen_te = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
601 /* Then the header frame controls of interest */
602 GtkWidget *header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
604 GtkWidget *header_eth_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
605 GtkWidget *header_ipv4_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
606 GtkWidget *header_udp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
607 GtkWidget *header_tcp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
608 GtkWidget *header_sctp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
609 GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
611 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
612 GtkWidget *protocol_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
613 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
614 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
615 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
616 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
620 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter))
622 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
623 gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
626 if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
627 (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb))))
629 text_import_info->dummy_header_type =
630 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb)) ? HEADER_ETH :
631 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb)) ? HEADER_IPV4 :
632 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb)) ? HEADER_UDP :
633 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb)) ? HEADER_TCP :
634 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb)) ? HEADER_SCTP :
635 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
638 switch (text_import_info->dummy_header_type)
641 text_import_info->pid = strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
642 if (text_import_info->pid > 0xffff)
644 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
645 text_import_info->pid);
646 g_free(text_import_info->import_text_filename);
647 fclose(text_import_info->import_text_file);
648 g_free(text_import_info->date_timestamp_format);
649 g_free(text_import_info);
655 text_import_info->protocol = strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
656 if (text_import_info->protocol > 0xff)
658 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
659 text_import_info->protocol);
660 g_free(text_import_info->import_text_filename);
661 fclose(text_import_info->import_text_file);
662 g_free(text_import_info->date_timestamp_format);
663 g_free(text_import_info);
670 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
671 if (text_import_info->src_port > 0xffff)
673 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
674 text_import_info->src_port);
675 g_free(text_import_info->import_text_filename);
676 fclose(text_import_info->import_text_file);
677 g_free(text_import_info->date_timestamp_format);
678 g_free(text_import_info);
681 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
682 if (text_import_info->dst_port > 0xffff)
684 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
685 text_import_info->dst_port);
686 g_free(text_import_info->import_text_filename);
687 fclose(text_import_info->import_text_file);
688 g_free(text_import_info->date_timestamp_format);
689 g_free(text_import_info);
695 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
696 if (text_import_info->src_port > 0xffff)
698 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
699 text_import_info->src_port);
700 g_free(text_import_info->import_text_filename);
701 fclose(text_import_info->import_text_file);
702 g_free(text_import_info->date_timestamp_format);
703 g_free(text_import_info);
706 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
707 if (text_import_info->dst_port > 0xffff)
709 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
710 text_import_info->dst_port);
711 g_free(text_import_info->import_text_filename);
712 fclose(text_import_info->import_text_file);
713 g_free(text_import_info->date_timestamp_format);
714 g_free(text_import_info);
717 text_import_info->tag = strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
720 case HEADER_SCTP_DATA:
721 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
722 if (text_import_info->src_port > 0xffff)
724 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
725 text_import_info->src_port);
726 g_free(text_import_info->import_text_filename);
727 fclose(text_import_info->import_text_file);
728 g_free(text_import_info->date_timestamp_format);
729 g_free(text_import_info);
732 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
733 if (text_import_info->dst_port > 0xffff)
735 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
736 text_import_info->dst_port);
737 g_free(text_import_info->import_text_filename);
738 fclose(text_import_info->import_text_file);
739 g_free(text_import_info->date_timestamp_format);
740 g_free(text_import_info);
743 text_import_info->ppi = strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
750 text_import_info->dummy_header_type = HEADER_NONE;
753 text_import_info->max_frame_length = strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
754 if (text_import_info->max_frame_length == 0) {
755 text_import_info->max_frame_length = IMPORT_MAX_PACKET;
757 else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET)
759 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
760 text_import_info->max_frame_length);
761 g_free(text_import_info->import_text_filename);
762 fclose(text_import_info->import_text_file);
763 g_free(text_import_info->date_timestamp_format);
764 g_free(text_import_info);
769 return text_import_info;
772 /*****************************************************************************/
775 file_import_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
777 text_import_info_t *text_import_info;
781 /* save file first */
782 file_save_as_cmd(after_save_no_action, NULL, FALSE);
784 case ESD_BTN_DONT_SAVE:
790 g_assert_not_reached();
793 text_import_info = setup_file_import(data);
794 if (text_import_info)
795 file_import_open(text_import_info);
799 file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
801 text_import_info_t *text_import_info;
803 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
805 /* user didn't save his current file, ask him */
806 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
807 "%sSave capture file before opening a new one?%s\n\n"
808 "If you open a new capture file without saving, your capture data will be discarded.",
809 simple_dialog_primary_start(), simple_dialog_primary_end());
810 simple_dialog_set_cb(dialog, file_import_answered_cb, data);
812 /* unchanged file, just open a new one */
813 text_import_info = setup_file_import(data);
814 if (text_import_info)
815 file_import_open(text_import_info);
820 /*****************************************************************************/
826 file_import_dlg_new(void)
828 GtkWidget *main_w, *main_vb,
829 *input_frm, *input_tb, *input_vb,
830 *filename_hb, *filename_lbl, *filename_te, *browse_bt,
831 *offset_hb, *offset_lbl_vb, *offset_lbl, *offset_rb_vb,
832 *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
833 *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
834 *import_frm, *import_vb,
835 *encap_hb, *encap_lbl, *encap_co,
836 *header_cb, *header_frm, *header_hb,
837 *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
838 *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
840 *header_rblbl_1_hb, *header_rblbl_1_lbl,
841 *header_rblbl_2_hb, *header_rblbl_2_lbl,
842 *header_rblbl_3_hb, *header_rblbl_3_lbl,
843 *header_rblbl_4_hb, *header_rblbl_4_lbl,
844 *header_rblbl_5_hb, *header_rblbl_5_lbl,
845 *header_rblbl_6_hb, *header_rblbl_6_lbl,
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;
851 /* Setup the dialog */
853 main_w = dlg_window_new("Wireshark: Import from Text");
854 gtk_window_set_default_size(GTK_WINDOW(main_w), 400, 300);
856 main_vb = gtk_vbox_new(FALSE, 0);
857 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
858 gtk_container_add(GTK_CONTAINER(main_w), main_vb);
860 /* Setup the input frame */
862 input_frm = gtk_frame_new("Input");
863 gtk_box_pack_start(GTK_BOX(main_vb), input_frm, FALSE, FALSE, 0);
865 g_object_set_data(G_OBJECT(main_w), INPUT_FRM_KEY, input_frm);
867 input_vb = gtk_vbox_new(FALSE, 0);
868 gtk_container_add(GTK_CONTAINER(input_frm), input_vb);
870 input_tb = gtk_table_new(2, 3, FALSE);
871 gtk_container_set_border_width(GTK_CONTAINER(input_tb), 5);
872 gtk_box_pack_start(GTK_BOX(input_vb), input_tb, FALSE, FALSE, 0);
873 gtk_table_set_row_spacings(GTK_TABLE(input_tb), 5);
874 gtk_table_set_col_spacings(GTK_TABLE(input_tb), 5);
877 filename_hb = gtk_hbox_new(FALSE, 3);
878 gtk_container_set_border_width(GTK_CONTAINER(filename_hb), 3);
880 filename_lbl = gtk_label_new("Filename:");
881 gtk_table_attach(GTK_TABLE(input_tb), filename_lbl, 0, 1, 0, 1, 0, 0, 0, 0);
883 filename_te = gtk_entry_new();
884 gtk_widget_set_tooltip_text(filename_te, "Set name of text file to import");
885 gtk_table_attach_defaults(GTK_TABLE(input_tb), filename_te, 1, 2, 0, 1);
887 g_object_set_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY, filename_te);
889 browse_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
890 gtk_widget_set_tooltip_text(browse_bt, "Browse for text file to import");
891 gtk_table_attach(GTK_TABLE(input_tb), browse_bt, 2, 3, 0, 1, 0, 0, 0, 0);
893 g_signal_connect(browse_bt, "clicked", G_CALLBACK(browse_file_cb), filename_te);
896 offset_hb = gtk_hbox_new(FALSE, 3);
897 gtk_container_set_border_width(GTK_CONTAINER(offset_hb), 3);
898 gtk_box_pack_start(GTK_BOX(input_vb), offset_hb, FALSE, FALSE, 0);
900 offset_lbl_vb = gtk_vbox_new(FALSE, 0);
901 gtk_box_pack_start(GTK_BOX(offset_hb), offset_lbl_vb, FALSE, FALSE, 0);
903 offset_lbl = gtk_label_new("Offsets:");
904 gtk_misc_set_alignment(GTK_MISC(offset_lbl), 1.0f, 0.0f);
905 gtk_table_attach(GTK_TABLE(input_tb), offset_lbl, 0, 1, 1, 2, 0, 0, 0, 0);
907 offset_rb_vb = gtk_vbox_new(FALSE, 0);
908 gtk_table_attach_defaults(GTK_TABLE(input_tb), offset_rb_vb, 1, 2, 1, 2);
910 /* First entry in the group */
911 offset_hex_rb = gtk_radio_button_new_with_label(NULL, "Hexadecimal");
912 gtk_widget_set_tooltip_text(offset_hex_rb, "Offsets in the text file are in hexadecimal notation");
913 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_hex_rb, FALSE, FALSE, 0);
915 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY, offset_hex_rb);
917 offset_oct_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(offset_hex_rb), "Octal");
918 gtk_widget_set_tooltip_text(offset_oct_rb, "Offsets in the text file are in octal notation");
919 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_oct_rb, FALSE, FALSE, 0);
921 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY, offset_oct_rb);
923 offset_dec_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(offset_hex_rb), "Decimal");
924 gtk_widget_set_tooltip_text(offset_dec_rb, "Offsets in the text file are in decimal notation");
925 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_dec_rb, FALSE, FALSE, 0);
927 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY, offset_dec_rb);
930 timefmt_hb = gtk_hbox_new(FALSE, 3);
931 gtk_container_set_border_width(GTK_CONTAINER(timefmt_hb), 3);
932 gtk_box_pack_start(GTK_BOX(input_vb), timefmt_hb, FALSE, FALSE, 0);
934 timefmt_cb = gtk_check_button_new_with_label("Date/Time");
935 gtk_widget_set_tooltip_text(timefmt_cb, "Whether or not the text file contains timestamp information");
936 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_cb, FALSE, FALSE, 0);
938 g_object_set_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY, timefmt_cb);
940 timefmt_lbl = gtk_label_new(" Format:");
941 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_lbl, FALSE, FALSE, 0);
943 g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_LBL_KEY, timefmt_lbl);
945 timefmt_te = gtk_entry_new();
946 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)");
947 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_te, FALSE, FALSE, 0);
949 g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_TE_KEY, timefmt_te);
950 g_object_set_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY, timefmt_te);
952 g_signal_connect(timefmt_cb, "toggled", G_CALLBACK(timefmt_cb_toggle), NULL);
953 g_signal_emit_by_name(G_OBJECT(timefmt_cb), "toggled", NULL);
955 /* Setup the import frame */
957 import_frm = gtk_frame_new("Import");
958 gtk_box_pack_start(GTK_BOX(main_vb), import_frm, TRUE, TRUE, 3);
960 g_object_set_data(G_OBJECT(main_w), IMPORT_FRM_KEY, import_frm);
962 import_vb = gtk_vbox_new(FALSE, 0);
963 gtk_container_add(GTK_CONTAINER(import_frm), import_vb);
966 encap_hb = gtk_hbox_new(FALSE, 3);
967 gtk_container_set_border_width(GTK_CONTAINER(encap_hb), 3);
968 gtk_box_pack_start(GTK_BOX(import_vb), encap_hb, FALSE, FALSE, 0);
970 encap_lbl = gtk_label_new("Encapsulation type:");
971 gtk_box_pack_start(GTK_BOX(encap_hb), encap_lbl, FALSE, FALSE, 0);
973 encap_co = fill_encap_combo();
974 gtk_widget_set_tooltip_text(encap_co, "Encapsulation type for the frames in the import capture file");
975 gtk_box_pack_start(GTK_BOX(encap_hb), encap_co, FALSE, FALSE, 0);
977 g_object_set_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY, encap_co);
980 header_frm = gtk_frame_new(NULL);
981 header_cb = gtk_check_button_new_with_label("Dummy header");
982 gtk_widget_set_tooltip_text(header_cb, "Whether or not to prefix a dummy header to the frames");
983 gtk_frame_set_label_widget(GTK_FRAME(header_frm), header_cb);
984 gtk_container_set_border_width(GTK_CONTAINER(header_frm), 3);
985 gtk_box_pack_start(GTK_BOX(import_vb), header_frm, FALSE, FALSE, 0);
987 g_object_set_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY, header_frm);
988 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY, header_cb);
990 header_hb = gtk_hbox_new(FALSE, 3);
991 gtk_container_set_border_width(GTK_CONTAINER(header_hb), 3);
992 gtk_container_add(GTK_CONTAINER(header_frm), header_hb);
994 header_rblbl_vb = gtk_vbox_new(FALSE, 0);
995 gtk_box_pack_start(GTK_BOX(header_hb), header_rblbl_vb, TRUE, TRUE, 0);
998 header_rblbl_1_hb = gtk_hbox_new(FALSE, 0);
999 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_1_hb, FALSE, FALSE, 2);
1001 /* First entry in the group */
1002 header_eth_rb = gtk_radio_button_new_with_label(NULL, "Ethernet");
1003 gtk_widget_set_tooltip_text(header_eth_rb, "Prefix an Ethernet header to the frames");
1004 g_signal_connect(header_eth_rb, "toggled", G_CALLBACK(header_eth_rb_toggle), header_frm);
1005 gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_eth_rb, FALSE, FALSE, 0);
1007 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY, header_eth_rb);
1009 header_rblbl_1_lbl = gtk_label_new(" Ethertype (hex):");
1010 gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_rblbl_1_lbl, TRUE, TRUE, 0);
1011 gtk_misc_set_alignment(GTK_MISC(header_rblbl_1_lbl), 1.0f, 0.5f);
1013 etype_te = gtk_entry_new();
1014 gtk_widget_set_tooltip_text(etype_te, "The type to set in the Ethernet header");
1015 gtk_box_pack_end(GTK_BOX(header_rblbl_1_hb), etype_te, FALSE, FALSE, 0);
1017 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_LBL_KEY, header_rblbl_1_lbl);
1018 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY, etype_te);
1021 header_rblbl_2_hb = gtk_hbox_new(FALSE, 0);
1022 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_2_hb, FALSE, FALSE, 2);
1024 header_ipv4_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "IPv4");
1025 gtk_widget_set_tooltip_text(header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames");
1026 g_signal_connect(header_ipv4_rb, "toggled", G_CALLBACK(header_ipv4_rb_toggle), header_frm);
1027 gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_ipv4_rb, FALSE, FALSE, 0);
1029 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY, header_ipv4_rb);
1031 header_rblbl_2_lbl = gtk_label_new(" Protocol (dec):");
1032 gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_rblbl_2_lbl, TRUE, TRUE, 0);
1033 gtk_misc_set_alignment(GTK_MISC(header_rblbl_2_lbl), 1.0f, 0.5f);
1035 protocol_te = gtk_entry_new();
1036 gtk_widget_set_tooltip_text(protocol_te, "The protocol id to set in the IPv4 header");
1037 gtk_box_pack_end(GTK_BOX(header_rblbl_2_hb), protocol_te, FALSE, FALSE, 0);
1039 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_LBL_KEY, header_rblbl_2_lbl);
1040 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY, protocol_te);
1043 header_rblbl_3_hb = gtk_hbox_new(FALSE, 0);
1044 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_3_hb, FALSE, FALSE, 2);
1046 header_udp_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "UDP");
1047 gtk_widget_set_tooltip_text(header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames");
1048 g_signal_connect(header_udp_rb, "toggled", G_CALLBACK(header_udp_rb_toggle), header_frm);
1049 gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_udp_rb, FALSE, FALSE, 0);
1051 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY, header_udp_rb);
1053 header_rblbl_3_lbl = gtk_label_new(" Source port:");
1054 gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_rblbl_3_lbl, TRUE, TRUE, 0);
1055 gtk_misc_set_alignment(GTK_MISC(header_rblbl_3_lbl), 1.0f, 0.5f);
1057 src_port_te = gtk_entry_new();
1058 gtk_widget_set_tooltip_text(src_port_te, "The source port to set in the UDP, TCP or SCTP header");
1059 gtk_box_pack_end(GTK_BOX(header_rblbl_3_hb), src_port_te, FALSE, FALSE, 0);
1061 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_LBL_KEY, header_rblbl_3_lbl);
1062 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY, src_port_te);
1065 header_rblbl_4_hb = gtk_hbox_new(FALSE, 0);
1066 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_4_hb, FALSE, FALSE, 2);
1068 header_tcp_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "TCP");
1069 gtk_widget_set_tooltip_text(header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames");
1070 g_signal_connect(header_tcp_rb, "toggled", G_CALLBACK(header_tcp_rb_toggle), header_frm);
1071 gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_tcp_rb, FALSE, FALSE, 0);
1073 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY, header_tcp_rb);
1075 header_rblbl_4_lbl = gtk_label_new(" Destination port:");
1076 gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_rblbl_4_lbl, TRUE, TRUE, 0);
1077 gtk_misc_set_alignment(GTK_MISC(header_rblbl_4_lbl), 1.0f, 0.5f);
1079 dst_port_te = gtk_entry_new();
1080 gtk_widget_set_tooltip_text(dst_port_te, "The destination port to set in the UDP, TCP or SCTP header");
1081 gtk_box_pack_end(GTK_BOX(header_rblbl_4_hb), dst_port_te, FALSE, FALSE, 0);
1083 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_LBL_KEY, header_rblbl_4_lbl);
1084 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY, dst_port_te);
1087 header_rblbl_5_hb = gtk_hbox_new(FALSE, 0);
1088 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_5_hb, FALSE, FALSE, 2);
1090 header_sctp_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "SCTP");
1091 gtk_widget_set_tooltip_text(header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames");
1092 g_signal_connect(header_sctp_rb, "toggled", G_CALLBACK(header_sctp_rb_toggle), header_frm);
1093 gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_sctp_rb, FALSE, FALSE, 0);
1095 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY, header_sctp_rb);
1097 header_rblbl_5_lbl = gtk_label_new(" Tag:");
1098 gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_rblbl_5_lbl, TRUE, TRUE, 0);
1099 gtk_misc_set_alignment(GTK_MISC(header_rblbl_5_lbl), 1.0f, 0.5f);
1101 tag_te = gtk_entry_new();
1102 gtk_widget_set_tooltip_text(tag_te, "The verification tag to set in the SCTP header");
1103 gtk_box_pack_end(GTK_BOX(header_rblbl_5_hb), tag_te, FALSE, FALSE, 0);
1105 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_LBL_KEY, header_rblbl_5_lbl);
1106 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY, tag_te);
1109 header_rblbl_6_hb = gtk_hbox_new(FALSE, 0);
1110 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_6_hb, FALSE, FALSE, 2);
1112 header_sctp_data_rb = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(header_eth_rb), "SCTP (DATA)");
1113 gtk_widget_set_tooltip_text(header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames");
1114 g_signal_connect(header_sctp_data_rb, "toggled", G_CALLBACK(header_sctp_data_rb_toggle), header_frm);
1115 gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_sctp_data_rb, FALSE, FALSE, 0);
1117 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY, header_sctp_data_rb);
1119 header_rblbl_6_lbl = gtk_label_new(" PPI:");
1120 gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_rblbl_6_lbl, TRUE, TRUE, 0);
1121 gtk_misc_set_alignment(GTK_MISC(header_rblbl_6_lbl), 1.0f, 0.5f);
1123 ppi_te = gtk_entry_new();
1124 gtk_widget_set_tooltip_text(ppi_te, "The payload protocol identifier to set in the SCTP DATA header");
1125 gtk_box_pack_end(GTK_BOX(header_rblbl_6_hb), ppi_te, FALSE, FALSE, 0);
1127 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_LBL_KEY, header_rblbl_6_lbl);
1128 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY, ppi_te);
1130 /* Set sensitivity */
1131 g_signal_connect(header_cb, "toggled", G_CALLBACK(header_cb_toggle), header_frm);
1132 g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", header_frm);
1134 g_signal_emit_by_name(G_OBJECT(header_eth_rb), "toggled", header_frm);
1136 gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
1137 g_signal_connect(encap_co, "changed", G_CALLBACK(encap_co_changed), header_frm);
1140 framelen_hb = gtk_hbox_new(FALSE, 3);
1141 gtk_container_set_border_width(GTK_CONTAINER(framelen_hb), 3);
1142 gtk_box_pack_start(GTK_BOX(import_vb), framelen_hb, FALSE, FALSE, 0);
1144 framelen_lbl = gtk_label_new("Max. frame length:");
1145 gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_lbl, FALSE, FALSE, 0);
1147 framelen_te = gtk_entry_new();
1148 gtk_widget_set_tooltip_text(framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)");
1149 gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_te, FALSE, FALSE, 0);
1151 g_object_set_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY, framelen_te);
1153 /* Setup the button row */
1155 bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1156 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
1158 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1159 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_IMPORT_DIALOG);
1160 gtk_widget_set_tooltip_text(help_bt, "Show topic specific help");
1162 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1163 window_set_cancel_button(main_w, close_bt, window_cancel_button_cb);
1164 gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
1166 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1167 g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_import_ok_cb), main_w);
1168 gtk_widget_grab_default(ok_bt);
1169 gtk_widget_set_tooltip_text(ok_bt, "Import the selected file into a temporary capture file");
1171 /* Setup widget handling */
1173 g_signal_connect(main_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1174 g_signal_connect(main_w, "destroy", G_CALLBACK(file_import_dlg_destroy_cb), NULL);
1176 gtk_widget_show_all(main_w);
1177 window_present(main_w);
1183 file_import_cmd_cb(GtkWidget *widget _U_)
1185 /* Do we have an encapsulation type list? */
1186 if (!encap_list_store)
1188 /* No. Create one. */
1189 create_encap_list_store();
1192 /* Has a file import dialog already been opened? */
1193 if (file_import_dlg_w)
1195 /* Yes. Just re-activate that dialog box. */
1196 reactivate_window(file_import_dlg_w);
1198 /* No. Create one */
1199 file_import_dlg_w = file_import_dlg_new();