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"
59 #include "gtk/text_import_scanner.h"
62 #include "wsutil/file_util.h"
65 #define INPUT_FRM_KEY "input_frame"
67 #define INPUT_FILENAME_TE_KEY "input_filename_text"
69 #define INPUT_OFFSET_HEX_RB_KEY "input_offset_hex_radio"
70 #define INPUT_OFFSET_OCT_RB_KEY "input_offset_oct_radio"
71 #define INPUT_OFFSET_DEC_RB_KEY "input_offset_dec_radio"
73 #define INPUT_DATETIME_CB_KEY "input_datetime_checkbox"
74 #define INPUT_TIMEFMT_LBL_KEY "input_timeformat_label"
75 #define INPUT_TIMEFMT_TE_KEY "input_timeformat_entry"
77 #define IMPORT_FRM_KEY "import_frame"
78 #define IMPORT_ENCAP_CO_KEY "import_encap_combo"
80 #define IMPORT_HEADER_FRM_KEY "import_header_frame"
81 #define IMPORT_HEADER_CB_KEY "import_header_checkbox"
82 #define IMPORT_HEADER_ETH_RB_KEY "import_header_ethernet_radio"
83 #define IMPORT_HEADER_ETYPE_LBL_KEY "import_header_etype_label"
84 #define IMPORT_HEADER_ETYPE_TE_KEY "import_header_etype_text"
85 #define IMPORT_HEADER_IPV4_RB_KEY "import_header_ipv4_radio"
86 #define IMPORT_HEADER_PROT_LBL_KEY "import_header_prot_label"
87 #define IMPORT_HEADER_PROT_TE_KEY "import_header_prot_text"
88 #define IMPORT_HEADER_UDP_RB_KEY "import_header_udp_radio"
89 #define IMPORT_HEADER_SRC_PORT_LBL_KEY "import_header_src_port_label"
90 #define IMPORT_HEADER_SRC_PORT_TE_KEY "import_header_src_port_text"
91 #define IMPORT_HEADER_TCP_RB_KEY "import_header_tcp_radio"
92 #define IMPORT_HEADER_DST_PORT_LBL_KEY "import_header_dst_port_label"
93 #define IMPORT_HEADER_DST_PORT_TE_KEY "import_header_dst_port_text"
94 #define IMPORT_HEADER_SCTP_RB_KEY "import_header_sctp_radio"
95 #define IMPORT_HEADER_TAG_LBL_KEY "import_header_tag_label"
96 #define IMPORT_HEADER_TAG_TE_KEY "import_header_tag_text"
97 #define IMPORT_HEADER_SCTP_D_RB_KEY "import_header_sctp_data_radio"
98 #define IMPORT_HEADER_PPI_LBL_KEY "import_header_ppi_label"
99 #define IMPORT_HEADER_PPI_TE_KEY "import_header_ppi_text"
101 #define IMPORT_FRAME_LENGTH_TE_KEY "import_frame_length_text"
103 static GtkWidget *file_import_dlg_w = NULL;
104 static GtkListStore *encap_list_store = NULL;
106 /*****************************************************************************/
109 file_import_dlg_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
111 file_import_dlg_w = NULL;
114 /*****************************************************************************/
117 browse_file_cb(GtkWidget *browse_bt, GtkWidget *filename_te)
119 file_selection_browse(browse_bt, filename_te, "Wireshark: Import from Text",
120 FILE_SELECTION_READ_BROWSE);
124 timefmt_cb_toggle(GtkWidget *widget, gpointer data _U_)
126 GtkWidget *timefmt_lbl, *timefmt_te;
129 timefmt_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_LBL_KEY));
130 timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(widget), INPUT_TIMEFMT_TE_KEY));
132 apply_fmt = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
133 gtk_widget_set_sensitive(timefmt_lbl, apply_fmt);
134 gtk_widget_set_sensitive(timefmt_te, apply_fmt);
137 /*****************************************************************************/
139 create_encap_list_store(void)
145 encap_list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
147 /* Scan all Wiretap encapsulation types */
148 for (encap = 1; encap < wtap_get_num_encap_types(); encap++)
150 /* Check if we can write it to a PCAP file */
151 if ((wtap_wtap_encap_to_pcap_encap(encap) > 0) &&
153 * Exclude wtap encapsulations that require a pseudo header,
154 * because we won't setup one from the text we import and
155 * wiretap doesn't allow us to write 'raw' frames
157 !((encap == WTAP_ENCAP_ATM_PDUS) ||
158 (encap == WTAP_ENCAP_IRDA) ||
159 (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
160 (encap == WTAP_ENCAP_LINUX_LAPD) ||
161 (encap == WTAP_ENCAP_SITA) ||
162 (encap == WTAP_ENCAP_ERF) ||
163 (encap == WTAP_ENCAP_I2C) ||
164 (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
165 (encap == WTAP_ENCAP_PPP_WITH_PHDR)
168 /* If it has got a name */
169 if ((name = wtap_encap_string(encap)))
171 gtk_list_store_append(encap_list_store, &iter);
172 gtk_list_store_set(encap_list_store, &iter, 0, name, 1, encap, -1);
180 fill_encap_combo(void)
182 GtkWidget *encap_co = NULL;
183 GtkCellRenderer *cell;
185 encap_co = gtk_combo_box_new_with_model(GTK_TREE_MODEL(encap_list_store));
186 cell = gtk_cell_renderer_text_new();
187 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encap_co), cell, TRUE);
188 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(encap_co), cell, "text", 0, NULL);
193 static void header_frm_child_set(GtkWidget *widget, gpointer data);
196 encap_co_changed(GtkComboBox *widget, gpointer data)
200 GtkWidget *header_cb;
202 result = gtk_combo_box_get_active_iter(widget, &iter);
207 GtkTreeModel *model = gtk_combo_box_get_model(widget);
208 gtk_tree_model_get(model, &iter, 1, &encap, -1);
210 if (encap != WTAP_ENCAP_ETHERNET)
216 header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_CB_KEY));
217 g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", data);
219 gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set, GUINT_TO_POINTER(result));
223 /*****************************************************************************/
226 header_frm_child_set(GtkWidget *widget, gpointer data)
228 gtk_widget_set_sensitive(widget, GPOINTER_TO_UINT(data));
232 header_cb_toggle(GtkWidget *widget, gpointer data)
234 gtk_container_foreach(GTK_CONTAINER(data), header_frm_child_set,
235 GUINT_TO_POINTER(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))));
236 /* The frame's checkbox must stay sensitive, of course... */
237 gtk_widget_set_sensitive(widget, TRUE);
241 * Header radio button toggle handlers
244 header_eth_rb_toggle(GtkWidget *widget, gpointer data)
246 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
247 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
248 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
249 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
250 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
251 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
252 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
253 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
254 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
255 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
256 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
257 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
259 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
261 gtk_widget_set_sensitive(etype_lbl, TRUE);
262 gtk_widget_set_sensitive(etype_te, TRUE);
263 gtk_widget_set_sensitive(prot_lbl, FALSE);
264 gtk_widget_set_sensitive(prot_te, FALSE);
265 gtk_widget_set_sensitive(src_port_lbl, FALSE);
266 gtk_widget_set_sensitive(src_port_te, FALSE);
267 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
268 gtk_widget_set_sensitive(dst_port_te, FALSE);
269 gtk_widget_set_sensitive(tag_lbl, FALSE);
270 gtk_widget_set_sensitive(tag_te, FALSE);
271 gtk_widget_set_sensitive(ppi_lbl, FALSE);
272 gtk_widget_set_sensitive(ppi_te, FALSE);
276 gtk_widget_set_sensitive(etype_lbl, FALSE);
277 gtk_widget_set_sensitive(etype_te, FALSE);
282 header_ipv4_rb_toggle(GtkWidget *widget, gpointer data)
284 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
285 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
286 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
287 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
288 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
289 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
290 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
291 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
292 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
293 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
294 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
295 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
297 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
299 gtk_widget_set_sensitive(etype_lbl, FALSE);
300 gtk_widget_set_sensitive(etype_te, FALSE);
301 gtk_widget_set_sensitive(prot_lbl, TRUE);
302 gtk_widget_set_sensitive(prot_te, TRUE);
303 gtk_widget_set_sensitive(src_port_lbl, FALSE);
304 gtk_widget_set_sensitive(src_port_te, FALSE);
305 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
306 gtk_widget_set_sensitive(dst_port_te, FALSE);
307 gtk_widget_set_sensitive(tag_lbl, FALSE);
308 gtk_widget_set_sensitive(tag_te, FALSE);
309 gtk_widget_set_sensitive(ppi_lbl, FALSE);
310 gtk_widget_set_sensitive(ppi_te, FALSE);
314 gtk_widget_set_sensitive(prot_lbl, FALSE);
315 gtk_widget_set_sensitive(prot_te, FALSE);
320 header_udp_rb_toggle(GtkWidget *widget, gpointer data)
322 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
323 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
324 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
325 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
326 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
327 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
328 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
329 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
330 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
331 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
332 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
333 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
335 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
337 gtk_widget_set_sensitive(etype_lbl, FALSE);
338 gtk_widget_set_sensitive(etype_te, FALSE);
339 gtk_widget_set_sensitive(prot_lbl, FALSE);
340 gtk_widget_set_sensitive(prot_te, FALSE);
341 gtk_widget_set_sensitive(src_port_lbl, TRUE);
342 gtk_widget_set_sensitive(src_port_te, TRUE);
343 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
344 gtk_widget_set_sensitive(dst_port_te, TRUE);
345 gtk_widget_set_sensitive(tag_lbl, FALSE);
346 gtk_widget_set_sensitive(tag_te, FALSE);
347 gtk_widget_set_sensitive(ppi_lbl, FALSE);
348 gtk_widget_set_sensitive(ppi_te, FALSE);
352 gtk_widget_set_sensitive(src_port_lbl, FALSE);
353 gtk_widget_set_sensitive(src_port_te, FALSE);
354 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
355 gtk_widget_set_sensitive(dst_port_te, FALSE);
360 header_tcp_rb_toggle(GtkWidget *widget, gpointer data)
362 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
363 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
364 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
365 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
366 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
367 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
368 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
369 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
370 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
371 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
372 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
373 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
375 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
377 gtk_widget_set_sensitive(etype_lbl, FALSE);
378 gtk_widget_set_sensitive(etype_te, FALSE);
379 gtk_widget_set_sensitive(prot_lbl, FALSE);
380 gtk_widget_set_sensitive(prot_te, FALSE);
381 gtk_widget_set_sensitive(src_port_lbl, TRUE);
382 gtk_widget_set_sensitive(src_port_te, TRUE);
383 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
384 gtk_widget_set_sensitive(dst_port_te, TRUE);
385 gtk_widget_set_sensitive(tag_lbl, FALSE);
386 gtk_widget_set_sensitive(tag_te, FALSE);
387 gtk_widget_set_sensitive(ppi_lbl, FALSE);
388 gtk_widget_set_sensitive(ppi_te, FALSE);
392 gtk_widget_set_sensitive(src_port_lbl, FALSE);
393 gtk_widget_set_sensitive(src_port_te, FALSE);
394 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
395 gtk_widget_set_sensitive(dst_port_te, FALSE);
400 header_sctp_rb_toggle(GtkWidget *widget, gpointer data)
402 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
403 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
404 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
405 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
406 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
407 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
408 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
409 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
410 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
411 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
412 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
413 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
415 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
417 gtk_widget_set_sensitive(etype_lbl, FALSE);
418 gtk_widget_set_sensitive(etype_te, FALSE);
419 gtk_widget_set_sensitive(prot_lbl, FALSE);
420 gtk_widget_set_sensitive(prot_te, FALSE);
421 gtk_widget_set_sensitive(src_port_lbl, TRUE);
422 gtk_widget_set_sensitive(src_port_te, TRUE);
423 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
424 gtk_widget_set_sensitive(dst_port_te, TRUE);
425 gtk_widget_set_sensitive(tag_lbl, TRUE);
426 gtk_widget_set_sensitive(tag_te, TRUE);
427 gtk_widget_set_sensitive(ppi_lbl, FALSE);
428 gtk_widget_set_sensitive(ppi_te, FALSE);
432 gtk_widget_set_sensitive(src_port_lbl, FALSE);
433 gtk_widget_set_sensitive(src_port_te, FALSE);
434 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
435 gtk_widget_set_sensitive(dst_port_te, FALSE);
436 gtk_widget_set_sensitive(tag_lbl, FALSE);
437 gtk_widget_set_sensitive(tag_te, FALSE);
442 header_sctp_data_rb_toggle(GtkWidget *widget, gpointer data)
444 GtkWidget *etype_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_LBL_KEY));
445 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_ETYPE_TE_KEY));
446 GtkWidget *prot_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_LBL_KEY));
447 GtkWidget *prot_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PROT_TE_KEY));
448 GtkWidget *src_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_LBL_KEY));
449 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_SRC_PORT_TE_KEY));
450 GtkWidget *dst_port_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_LBL_KEY));
451 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_DST_PORT_TE_KEY));
452 GtkWidget *tag_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_LBL_KEY));
453 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_TAG_TE_KEY));
454 GtkWidget *ppi_lbl = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_LBL_KEY));
455 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(data), IMPORT_HEADER_PPI_TE_KEY));
457 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
459 gtk_widget_set_sensitive(etype_lbl, FALSE);
460 gtk_widget_set_sensitive(etype_te, FALSE);
461 gtk_widget_set_sensitive(prot_lbl, FALSE);
462 gtk_widget_set_sensitive(prot_te, FALSE);
463 gtk_widget_set_sensitive(src_port_lbl, TRUE);
464 gtk_widget_set_sensitive(src_port_te, TRUE);
465 gtk_widget_set_sensitive(dst_port_lbl, TRUE);
466 gtk_widget_set_sensitive(dst_port_te, TRUE);
467 gtk_widget_set_sensitive(tag_lbl, FALSE);
468 gtk_widget_set_sensitive(tag_te, FALSE);
469 gtk_widget_set_sensitive(ppi_lbl, TRUE);
470 gtk_widget_set_sensitive(ppi_te, TRUE);
474 gtk_widget_set_sensitive(src_port_lbl, FALSE);
475 gtk_widget_set_sensitive(src_port_te, FALSE);
476 gtk_widget_set_sensitive(dst_port_lbl, FALSE);
477 gtk_widget_set_sensitive(dst_port_te, FALSE);
478 gtk_widget_set_sensitive(ppi_lbl, FALSE);
479 gtk_widget_set_sensitive(ppi_te, FALSE);
483 /*****************************************************************************/
486 file_import_open(text_import_info_t *info)
489 char *tmpname, *capfile_name = NULL;
492 /* Choose a random name for the temporary import buffer */
493 import_file_fd = create_tempfile(&tmpname, "import");
494 capfile_name = g_strdup(tmpname);
496 info->wdh = wtap_dump_fdopen(import_file_fd, WTAP_FILE_PCAP, info->encapsulation, info->max_frame_length, FALSE, &err);
497 if (info->wdh == NULL) {
498 open_failure_alert_box(capfile_name, err, TRUE);
499 fclose(info->import_text_file);
503 text_import_setup(info);
505 text_importin = info->import_text_file;
509 text_import_cleanup();
511 if (fclose(info->import_text_file))
513 read_failure_alert_box(info->import_text_filename, errno);
516 if (!wtap_dump_close(info->wdh, &err))
518 write_failure_alert_box(capfile_name, err);
521 if (cf_open(&cfile, capfile_name, TRUE /* temporary file */, &err) != CF_OK)
523 open_failure_alert_box(capfile_name, err, FALSE);
527 switch (cf_read(&cfile, FALSE)) {
530 /* Just because we got an error, that doesn't mean we were unable
531 to read any of the file; we handle what we could get from the
535 case CF_READ_ABORTED:
536 /* The user bailed out of re-reading the capture file; the
537 capture file has been closed - just free the capture file name
538 string and return (without changing the last containing
544 g_free(info->import_text_filename);
545 g_free(info->date_timestamp_format);
547 g_free(capfile_name);
548 window_destroy(file_import_dlg_w);
551 static text_import_info_t *
552 setup_file_import(GtkWidget *main_w)
554 GtkWidget *input_frm, *import_frm;
556 text_import_info_t *text_import_info = g_malloc0(sizeof(text_import_info_t));
558 /* Retrieve the input and import settings from the dialog */
560 /* First the main components */
561 input_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), INPUT_FRM_KEY));
562 import_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(main_w), IMPORT_FRM_KEY));
564 /* Then the input frame controls of interest */
566 GtkWidget *filename_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY));
567 GtkWidget *offset_hex_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY));
568 GtkWidget *offset_oct_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY));
569 GtkWidget *offset_dec_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY));
570 GtkWidget *timefmt_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY));
571 GtkWidget *timefmt_te = GTK_WIDGET(g_object_get_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY));
573 text_import_info->import_text_filename = g_strdup(gtk_entry_get_text(GTK_ENTRY(filename_te)));
575 /* Try to open the input file */
576 text_import_info->import_text_file = ws_fopen(text_import_info->import_text_filename, "rb");
577 if (!text_import_info->import_text_file) {
578 open_failure_alert_box(text_import_info->import_text_filename, errno, FALSE);
579 g_free(text_import_info->import_text_filename);
580 g_free(text_import_info->date_timestamp_format);
581 g_free(text_import_info);
585 text_import_info->offset_type =
586 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_hex_rb)) ? OFFSET_HEX :
587 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_oct_rb)) ? OFFSET_OCT :
588 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(offset_dec_rb)) ? OFFSET_DEC :
590 text_import_info->date_timestamp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(timefmt_cb));
591 text_import_info->date_timestamp_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(timefmt_te)));
594 /* Then the import frame controls of interest */
596 GtkWidget *encap_co = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY));
597 GtkWidget *header_frm = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY));
598 GtkWidget *framelen_te = GTK_WIDGET(g_object_get_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY));
600 /* Then the header frame controls of interest */
601 GtkWidget *header_cb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY));
603 GtkWidget *header_eth_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY));
604 GtkWidget *header_ipv4_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY));
605 GtkWidget *header_udp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY));
606 GtkWidget *header_tcp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY));
607 GtkWidget *header_sctp_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY));
608 GtkWidget *header_sctp_data_rb = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY));
610 GtkWidget *etype_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY));
611 GtkWidget *protocol_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY));
612 GtkWidget *src_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY));
613 GtkWidget *dst_port_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY));
614 GtkWidget *tag_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY));
615 GtkWidget *ppi_te = GTK_WIDGET(g_object_get_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY));
619 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encap_co), &iter))
621 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(encap_co));
622 gtk_tree_model_get(model, &iter, 1, &text_import_info->encapsulation, -1);
625 if ((text_import_info->encapsulation == WTAP_ENCAP_ETHERNET) &&
626 (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_cb))))
628 text_import_info->dummy_header_type =
629 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_eth_rb)) ? HEADER_ETH :
630 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_ipv4_rb)) ? HEADER_IPV4 :
631 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_udp_rb)) ? HEADER_UDP :
632 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_tcp_rb)) ? HEADER_TCP :
633 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_rb)) ? HEADER_SCTP :
634 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(header_sctp_data_rb)) ? HEADER_SCTP_DATA :
637 switch (text_import_info->dummy_header_type)
640 text_import_info->pid = strtol(gtk_entry_get_text(GTK_ENTRY(etype_te)), NULL, 16);
641 if (text_import_info->pid > 0xffff)
643 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The Ethertype (%x) is too large.",
644 text_import_info->pid);
645 g_free(text_import_info->import_text_filename);
646 fclose(text_import_info->import_text_file);
647 g_free(text_import_info->date_timestamp_format);
648 g_free(text_import_info);
654 text_import_info->protocol = strtol(gtk_entry_get_text(GTK_ENTRY(protocol_te)), NULL, 10);
655 if (text_import_info->protocol > 0xff)
657 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The IPv4 protocol (%u) is too large.",
658 text_import_info->protocol);
659 g_free(text_import_info->import_text_filename);
660 fclose(text_import_info->import_text_file);
661 g_free(text_import_info->date_timestamp_format);
662 g_free(text_import_info);
669 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
670 if (text_import_info->src_port > 0xffff)
672 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
673 text_import_info->src_port);
674 g_free(text_import_info->import_text_filename);
675 fclose(text_import_info->import_text_file);
676 g_free(text_import_info->date_timestamp_format);
677 g_free(text_import_info);
680 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
681 if (text_import_info->dst_port > 0xffff)
683 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
684 text_import_info->dst_port);
685 g_free(text_import_info->import_text_filename);
686 fclose(text_import_info->import_text_file);
687 g_free(text_import_info->date_timestamp_format);
688 g_free(text_import_info);
694 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
695 if (text_import_info->src_port > 0xffff)
697 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
698 text_import_info->src_port);
699 g_free(text_import_info->import_text_filename);
700 fclose(text_import_info->import_text_file);
701 g_free(text_import_info->date_timestamp_format);
702 g_free(text_import_info);
705 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
706 if (text_import_info->dst_port > 0xffff)
708 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
709 text_import_info->dst_port);
710 g_free(text_import_info->import_text_filename);
711 fclose(text_import_info->import_text_file);
712 g_free(text_import_info->date_timestamp_format);
713 g_free(text_import_info);
716 text_import_info->tag = strtol(gtk_entry_get_text(GTK_ENTRY(tag_te)), NULL, 10);
719 case HEADER_SCTP_DATA:
720 text_import_info->src_port = strtol(gtk_entry_get_text(GTK_ENTRY(src_port_te)), NULL, 10);
721 if (text_import_info->src_port > 0xffff)
723 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The source port (%u) is too large.",
724 text_import_info->src_port);
725 g_free(text_import_info->import_text_filename);
726 fclose(text_import_info->import_text_file);
727 g_free(text_import_info->date_timestamp_format);
728 g_free(text_import_info);
731 text_import_info->dst_port = strtol(gtk_entry_get_text(GTK_ENTRY(dst_port_te)), NULL, 10);
732 if (text_import_info->dst_port > 0xffff)
734 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The destination port (%u) is too large.",
735 text_import_info->dst_port);
736 g_free(text_import_info->import_text_filename);
737 fclose(text_import_info->import_text_file);
738 g_free(text_import_info->date_timestamp_format);
739 g_free(text_import_info);
742 text_import_info->ppi = strtol(gtk_entry_get_text(GTK_ENTRY(ppi_te)), NULL, 10);
749 text_import_info->dummy_header_type = HEADER_NONE;
752 text_import_info->max_frame_length = strtol(gtk_entry_get_text(GTK_ENTRY(framelen_te)), NULL, 10);
753 if (text_import_info->max_frame_length == 0) {
754 text_import_info->max_frame_length = IMPORT_MAX_PACKET;
756 else if (text_import_info->max_frame_length > IMPORT_MAX_PACKET)
758 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The maximum frame length (%u) is too long.",
759 text_import_info->max_frame_length);
760 g_free(text_import_info->import_text_filename);
761 fclose(text_import_info->import_text_file);
762 g_free(text_import_info->date_timestamp_format);
763 g_free(text_import_info);
768 return text_import_info;
771 /*****************************************************************************/
774 file_import_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
776 text_import_info_t *text_import_info;
780 /* save file first */
781 file_save_as_cmd(after_save_no_action, NULL);
783 case ESD_BTN_DONT_SAVE:
789 g_assert_not_reached();
792 text_import_info = setup_file_import(data);
793 if (text_import_info)
794 file_import_open(text_import_info);
798 file_import_ok_cb(GtkWidget *widget _U_, gpointer data)
800 text_import_info_t *text_import_info;
802 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
804 /* user didn't save his current file, ask him */
805 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
806 "%sSave capture file before opening a new one?%s\n\n"
807 "If you open a new capture file without saving, your capture data will be discarded.",
808 simple_dialog_primary_start(), simple_dialog_primary_end());
809 simple_dialog_set_cb(dialog, file_import_answered_cb, data);
811 /* unchanged file, just open a new one */
812 text_import_info = setup_file_import(data);
813 if (text_import_info)
814 file_import_open(text_import_info);
819 /*****************************************************************************/
825 file_import_dlg_new()
827 GtkWidget *main_w, *main_vb,
828 *input_frm, *input_tb, *input_vb,
829 *filename_hb, *filename_lbl, *filename_te, *browse_bt,
830 *offset_hb, *offset_lbl_vb, *offset_lbl, *offset_rb_vb,
831 *offset_hex_rb, *offset_oct_rb, *offset_dec_rb,
832 *timefmt_hb, *timefmt_cb, *timefmt_lbl, *timefmt_te,
833 *import_frm, *import_vb,
834 *encap_hb, *encap_lbl, *encap_co,
835 *header_cb, *header_frm, *header_hb,
836 *header_eth_rb, *header_ipv4_rb, *header_udp_rb,
837 *header_tcp_rb, *header_sctp_rb, *header_sctp_data_rb,
839 *header_rblbl_1_hb, *header_rblbl_1_lbl,
840 *header_rblbl_2_hb, *header_rblbl_2_lbl,
841 *header_rblbl_3_hb, *header_rblbl_3_lbl,
842 *header_rblbl_4_hb, *header_rblbl_4_lbl,
843 *header_rblbl_5_hb, *header_rblbl_5_lbl,
844 *header_rblbl_6_hb, *header_rblbl_6_lbl,
845 *etype_te, *protocol_te, *src_port_te,
846 *dst_port_te, *tag_te, *ppi_te,
847 *framelen_hb, *framelen_lbl, *framelen_te,
848 *bbox, *help_bt, *close_bt, *ok_bt;
850 GSList *offset_grp, /* Offset radio button group */
851 *header_grp; /* Dummy header radio button group */
853 #if GTK_CHECK_VERSION(2,12,0)
855 GtkTooltips *tooltips = gtk_tooltips_new();
858 /* Setup the dialog */
860 main_w = dlg_window_new("Wireshark: Import from Text");
861 gtk_window_set_default_size(GTK_WINDOW(main_w), 400, 300);
863 main_vb = gtk_vbox_new(FALSE, 0);
864 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 3);
865 gtk_container_add(GTK_CONTAINER(main_w), main_vb);
867 /* Setup the input frame */
869 input_frm = gtk_frame_new("Input");
870 gtk_box_pack_start(GTK_BOX(main_vb), input_frm, FALSE, FALSE, 0);
872 g_object_set_data(G_OBJECT(main_w), INPUT_FRM_KEY, input_frm);
874 input_vb = gtk_vbox_new(FALSE, 0);
875 gtk_container_add(GTK_CONTAINER(input_frm), input_vb);
877 input_tb = gtk_table_new(2, 3, FALSE);
878 gtk_container_set_border_width(GTK_CONTAINER(input_tb), 5);
879 gtk_box_pack_start(GTK_BOX(input_vb), input_tb, FALSE, FALSE, 0);
880 gtk_table_set_row_spacings(GTK_TABLE(input_tb), 5);
881 gtk_table_set_col_spacings(GTK_TABLE(input_tb), 5);
884 filename_hb = gtk_hbox_new(FALSE, 3);
885 gtk_container_set_border_width(GTK_CONTAINER(filename_hb), 3);
887 filename_lbl = gtk_label_new("Filename:");
888 gtk_table_attach(GTK_TABLE(input_tb), filename_lbl, 0, 1, 0, 1, 0, 0, 0, 0);
890 filename_te = gtk_entry_new();
891 #if GTK_CHECK_VERSION(2,12,0)
892 gtk_widget_set_tooltip_text(filename_te, "Set name of text file to import");
894 gtk_tooltips_set_tip(tooltips, filename_te, "Set name of text file to import", NULL);
896 gtk_table_attach_defaults(GTK_TABLE(input_tb), filename_te, 1, 2, 0, 1);
898 g_object_set_data(G_OBJECT(input_frm), INPUT_FILENAME_TE_KEY, filename_te);
900 browse_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_BROWSE);
901 #if GTK_CHECK_VERSION(2,12,0)
902 gtk_widget_set_tooltip_text(browse_bt, "Browse for text file to import");
904 gtk_tooltips_set_tip(tooltips, browse_bt, "Browse for text file to import", NULL);
906 gtk_table_attach(GTK_TABLE(input_tb), browse_bt, 2, 3, 0, 1, 0, 0, 0, 0);
908 g_signal_connect(browse_bt, "clicked", G_CALLBACK(browse_file_cb), filename_te);
911 offset_hb = gtk_hbox_new(FALSE, 3);
912 gtk_container_set_border_width(GTK_CONTAINER(offset_hb), 3);
913 gtk_box_pack_start(GTK_BOX(input_vb), offset_hb, FALSE, FALSE, 0);
915 offset_lbl_vb = gtk_vbox_new(FALSE, 0);
916 gtk_box_pack_start(GTK_BOX(offset_hb), offset_lbl_vb, FALSE, FALSE, 0);
918 offset_lbl = gtk_label_new("Offsets:");
919 gtk_misc_set_alignment(GTK_MISC(offset_lbl), 1.0f, 0.0f);
920 gtk_table_attach(GTK_TABLE(input_tb), offset_lbl, 0, 1, 1, 2, 0, 0, 0, 0);
922 offset_rb_vb = gtk_vbox_new(FALSE, 0);
923 gtk_table_attach_defaults(GTK_TABLE(input_tb), offset_rb_vb, 1, 2, 1, 2);
925 offset_hex_rb = gtk_radio_button_new_with_label(NULL, "Hexadecimal");
926 #if GTK_CHECK_VERSION(2,12,0)
927 gtk_widget_set_tooltip_text(offset_hex_rb, "Offsets in the text file are in hexadecimal notation");
929 gtk_tooltips_set_tip(tooltips, offset_hex_rb, "Offsets in the text file are in hexadecimal notation", NULL);
931 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_hex_rb, FALSE, FALSE, 0);
933 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_HEX_RB_KEY, offset_hex_rb);
935 offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_hex_rb));
936 offset_oct_rb = gtk_radio_button_new_with_label(offset_grp, "Octal");
937 #if GTK_CHECK_VERSION(2,12,0)
938 gtk_widget_set_tooltip_text(offset_oct_rb, "Offsets in the text file are in octal notation");
940 gtk_tooltips_set_tip(tooltips, offset_oct_rb, "Offsets in the text file are in octal notation", NULL);
942 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_oct_rb, FALSE, FALSE, 0);
944 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_OCT_RB_KEY, offset_oct_rb);
946 offset_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(offset_oct_rb));
947 offset_dec_rb = gtk_radio_button_new_with_label(offset_grp, "Decimal");
948 #if GTK_CHECK_VERSION(2,12,0)
949 gtk_widget_set_tooltip_text(offset_dec_rb, "Offsets in the text file are in decimal notation");
951 gtk_tooltips_set_tip(tooltips, offset_dec_rb, "Offsets in the text file are in decimal notation", NULL);
953 gtk_box_pack_start(GTK_BOX(offset_rb_vb), offset_dec_rb, FALSE, FALSE, 0);
955 g_object_set_data(G_OBJECT(input_frm), INPUT_OFFSET_DEC_RB_KEY, offset_dec_rb);
958 timefmt_hb = gtk_hbox_new(FALSE, 3);
959 gtk_container_set_border_width(GTK_CONTAINER(timefmt_hb), 3);
960 gtk_box_pack_start(GTK_BOX(input_vb), timefmt_hb, FALSE, FALSE, 0);
962 timefmt_cb = gtk_check_button_new_with_label("Date/Time");
963 #if GTK_CHECK_VERSION(2,12,0)
964 gtk_widget_set_tooltip_text(timefmt_cb, "Whether or not the text file contains timestamp information");
966 gtk_tooltips_set_tip(tooltips, timefmt_cb, "Whether or not the text file contains timestamp information", NULL);
968 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_cb, FALSE, FALSE, 0);
970 g_object_set_data(G_OBJECT(input_frm), INPUT_DATETIME_CB_KEY, timefmt_cb);
972 timefmt_lbl = gtk_label_new(" Format:");
973 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_lbl, FALSE, FALSE, 0);
975 g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_LBL_KEY, timefmt_lbl);
977 timefmt_te = gtk_entry_new();
978 #if GTK_CHECK_VERSION(2,12,0)
979 gtk_widget_set_tooltip_text(timefmt_te, "The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)");
981 gtk_tooltips_set_tip(tooltips, timefmt_te, "The format in which to parse timestamps in the text file (eg. %H:%M:%S.). Format specifiers are based on strptime(3)", NULL);
983 gtk_box_pack_start(GTK_BOX(timefmt_hb), timefmt_te, FALSE, FALSE, 0);
985 g_object_set_data(G_OBJECT(timefmt_cb), INPUT_TIMEFMT_TE_KEY, timefmt_te);
986 g_object_set_data(G_OBJECT(input_frm), INPUT_TIMEFMT_TE_KEY, timefmt_te);
988 g_signal_connect(timefmt_cb, "toggled", G_CALLBACK(timefmt_cb_toggle), NULL);
989 g_signal_emit_by_name(G_OBJECT(timefmt_cb), "toggled", NULL);
991 /* Setup the import frame */
993 import_frm = gtk_frame_new("Import");
994 gtk_box_pack_start(GTK_BOX(main_vb), import_frm, TRUE, TRUE, 3);
996 g_object_set_data(G_OBJECT(main_w), IMPORT_FRM_KEY, import_frm);
998 import_vb = gtk_vbox_new(FALSE, 0);
999 gtk_container_add(GTK_CONTAINER(import_frm), import_vb);
1002 encap_hb = gtk_hbox_new(FALSE, 3);
1003 gtk_container_set_border_width(GTK_CONTAINER(encap_hb), 3);
1004 gtk_box_pack_start(GTK_BOX(import_vb), encap_hb, FALSE, FALSE, 0);
1006 encap_lbl = gtk_label_new("Encapsulation type:");
1007 gtk_box_pack_start(GTK_BOX(encap_hb), encap_lbl, FALSE, FALSE, 0);
1009 encap_co = fill_encap_combo();
1010 #if GTK_CHECK_VERSION(2,12,0)
1011 gtk_widget_set_tooltip_text(encap_co, "Encapsulation type for the frames in the import capture file");
1013 gtk_tooltips_set_tip(tooltips, encap_co, "Encapsulation type for the frames in the import capture file", NULL);
1015 gtk_box_pack_start(GTK_BOX(encap_hb), encap_co, FALSE, FALSE, 0);
1017 g_object_set_data(G_OBJECT(import_frm), IMPORT_ENCAP_CO_KEY, encap_co);
1020 header_frm = gtk_frame_new(NULL);
1021 header_cb = gtk_check_button_new_with_label("Dummy header");
1022 #if GTK_CHECK_VERSION(2,12,0)
1023 gtk_widget_set_tooltip_text(header_cb, "Whether or not to prefix a dummy header to the frames");
1025 gtk_tooltips_set_tip(tooltips, header_cb, "Whether or not to prefix a dummy header to the frames", NULL);
1027 gtk_frame_set_label_widget(GTK_FRAME(header_frm), header_cb);
1028 gtk_container_set_border_width(GTK_CONTAINER(header_frm), 3);
1029 gtk_box_pack_start(GTK_BOX(import_vb), header_frm, FALSE, FALSE, 0);
1031 g_object_set_data(G_OBJECT(import_frm), IMPORT_HEADER_FRM_KEY, header_frm);
1032 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_CB_KEY, header_cb);
1034 header_hb = gtk_hbox_new(FALSE, 3);
1035 gtk_container_set_border_width(GTK_CONTAINER(header_hb), 3);
1036 gtk_container_add(GTK_CONTAINER(header_frm), header_hb);
1038 header_rblbl_vb = gtk_vbox_new(FALSE, 0);
1039 gtk_box_pack_start(GTK_BOX(header_hb), header_rblbl_vb, TRUE, TRUE, 0);
1042 header_rblbl_1_hb = gtk_hbox_new(FALSE, 0);
1043 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_1_hb, FALSE, FALSE, 2);
1045 header_eth_rb = gtk_radio_button_new_with_label(NULL, "Ethernet");
1046 #if GTK_CHECK_VERSION(2,12,0)
1047 gtk_widget_set_tooltip_text(header_eth_rb, "Prefix an Ethernet header to the frames");
1049 gtk_tooltips_set_tip(tooltips, header_eth_rb, "Prefix an Ethernet header to the frames", NULL);
1051 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_eth_rb));
1052 g_signal_connect(header_eth_rb, "toggled", G_CALLBACK(header_eth_rb_toggle), header_frm);
1053 gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_eth_rb, FALSE, FALSE, 0);
1055 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETH_RB_KEY, header_eth_rb);
1057 header_rblbl_1_lbl = gtk_label_new(" Ethertype (hex):");
1058 gtk_box_pack_start(GTK_BOX(header_rblbl_1_hb), header_rblbl_1_lbl, TRUE, TRUE, 0);
1059 gtk_misc_set_alignment(GTK_MISC(header_rblbl_1_lbl), 1.0f, 0.5f);
1061 etype_te = gtk_entry_new();
1062 #if GTK_CHECK_VERSION(2,12,0)
1063 gtk_widget_set_tooltip_text(etype_te, "The type to set in the Ethernet header");
1065 gtk_tooltips_set_tip(tooltips, etype_te, "The type to set in the Ethernet header", NULL);
1067 gtk_box_pack_end(GTK_BOX(header_rblbl_1_hb), etype_te, FALSE, FALSE, 0);
1069 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_LBL_KEY, header_rblbl_1_lbl);
1070 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_ETYPE_TE_KEY, etype_te);
1073 header_rblbl_2_hb = gtk_hbox_new(FALSE, 0);
1074 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_2_hb, FALSE, FALSE, 2);
1076 header_ipv4_rb = gtk_radio_button_new_with_label(header_grp, "IPv4");
1077 #if GTK_CHECK_VERSION(2,12,0)
1078 gtk_widget_set_tooltip_text(header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames");
1080 gtk_tooltips_set_tip(tooltips, header_ipv4_rb, "Prefix an Ethernet and IPv4 header to the frames", NULL);
1082 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_ipv4_rb));
1083 g_signal_connect(header_ipv4_rb, "toggled", G_CALLBACK(header_ipv4_rb_toggle), header_frm);
1084 gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_ipv4_rb, FALSE, FALSE, 0);
1086 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_IPV4_RB_KEY, header_ipv4_rb);
1088 header_rblbl_2_lbl = gtk_label_new(" Protocol (dec):");
1089 gtk_box_pack_start(GTK_BOX(header_rblbl_2_hb), header_rblbl_2_lbl, TRUE, TRUE, 0);
1090 gtk_misc_set_alignment(GTK_MISC(header_rblbl_2_lbl), 1.0f, 0.5f);
1092 protocol_te = gtk_entry_new();
1093 #if GTK_CHECK_VERSION(2,12,0)
1094 gtk_widget_set_tooltip_text(protocol_te, "The protocol id to set in the IPv4 header");
1096 gtk_tooltips_set_tip(tooltips, protocol_te, "The protocol id to set in the IPv4 header", NULL);
1098 gtk_box_pack_end(GTK_BOX(header_rblbl_2_hb), protocol_te, FALSE, FALSE, 0);
1100 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_LBL_KEY, header_rblbl_2_lbl);
1101 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PROT_TE_KEY, protocol_te);
1104 header_rblbl_3_hb = gtk_hbox_new(FALSE, 0);
1105 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_3_hb, FALSE, FALSE, 2);
1107 header_udp_rb = gtk_radio_button_new_with_label(header_grp, "UDP");
1108 #if GTK_CHECK_VERSION(2,12,0)
1109 gtk_widget_set_tooltip_text(header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames");
1111 gtk_tooltips_set_tip(tooltips, header_udp_rb, "Prefix an Ethernet, IPv4 and UDP header to the frames", NULL);
1113 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_udp_rb));
1114 g_signal_connect(header_udp_rb, "toggled", G_CALLBACK(header_udp_rb_toggle), header_frm);
1115 gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_udp_rb, FALSE, FALSE, 0);
1117 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_UDP_RB_KEY, header_udp_rb);
1119 header_rblbl_3_lbl = gtk_label_new(" Source port:");
1120 gtk_box_pack_start(GTK_BOX(header_rblbl_3_hb), header_rblbl_3_lbl, TRUE, TRUE, 0);
1121 gtk_misc_set_alignment(GTK_MISC(header_rblbl_3_lbl), 1.0f, 0.5f);
1123 src_port_te = gtk_entry_new();
1124 #if GTK_CHECK_VERSION(2,12,0)
1125 gtk_widget_set_tooltip_text(src_port_te, "The source port to set in the UDP, TCP or SCTP header");
1127 gtk_tooltips_set_tip(tooltips, src_port_te, "The source port to set in the UDP, TCP or SCTP header", NULL);
1129 gtk_box_pack_end(GTK_BOX(header_rblbl_3_hb), src_port_te, FALSE, FALSE, 0);
1131 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_LBL_KEY, header_rblbl_3_lbl);
1132 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SRC_PORT_TE_KEY, src_port_te);
1135 header_rblbl_4_hb = gtk_hbox_new(FALSE, 0);
1136 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_4_hb, FALSE, FALSE, 2);
1138 header_tcp_rb = gtk_radio_button_new_with_label(header_grp, "TCP");
1139 #if GTK_CHECK_VERSION(2,12,0)
1140 gtk_widget_set_tooltip_text(header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames");
1142 gtk_tooltips_set_tip(tooltips, header_tcp_rb, "Prefix an Ethernet, IPv4 and TCP header to the frames", NULL);
1144 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_tcp_rb));
1145 g_signal_connect(header_tcp_rb, "toggled", G_CALLBACK(header_tcp_rb_toggle), header_frm);
1146 gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_tcp_rb, FALSE, FALSE, 0);
1148 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TCP_RB_KEY, header_tcp_rb);
1150 header_rblbl_4_lbl = gtk_label_new(" Destination port:");
1151 gtk_box_pack_start(GTK_BOX(header_rblbl_4_hb), header_rblbl_4_lbl, TRUE, TRUE, 0);
1152 gtk_misc_set_alignment(GTK_MISC(header_rblbl_4_lbl), 1.0f, 0.5f);
1154 dst_port_te = gtk_entry_new();
1155 #if GTK_CHECK_VERSION(2,12,0)
1156 gtk_widget_set_tooltip_text(dst_port_te, "The destination port to set in the UDP, TCP or SCTP header");
1158 gtk_tooltips_set_tip(tooltips, dst_port_te, "The destination port to set in the UDP, TCP or SCTP header", NULL);
1160 gtk_box_pack_end(GTK_BOX(header_rblbl_4_hb), dst_port_te, FALSE, FALSE, 0);
1162 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_LBL_KEY, header_rblbl_4_lbl);
1163 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_DST_PORT_TE_KEY, dst_port_te);
1166 header_rblbl_5_hb = gtk_hbox_new(FALSE, 0);
1167 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_5_hb, FALSE, FALSE, 2);
1169 header_sctp_rb = gtk_radio_button_new_with_label(header_grp, "SCTP");
1170 #if GTK_CHECK_VERSION(2,12,0)
1171 gtk_widget_set_tooltip_text(header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames");
1173 gtk_tooltips_set_tip(tooltips, header_sctp_rb, "Prefix an Ethernet, IPv4 and SCTP header to the frames", NULL);
1175 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_rb));
1176 g_signal_connect(header_sctp_rb, "toggled", G_CALLBACK(header_sctp_rb_toggle), header_frm);
1177 gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_sctp_rb, FALSE, FALSE, 0);
1179 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_RB_KEY, header_sctp_rb);
1181 header_rblbl_5_lbl = gtk_label_new(" Tag:");
1182 gtk_box_pack_start(GTK_BOX(header_rblbl_5_hb), header_rblbl_5_lbl, TRUE, TRUE, 0);
1183 gtk_misc_set_alignment(GTK_MISC(header_rblbl_5_lbl), 1.0f, 0.5f);
1185 tag_te = gtk_entry_new();
1186 #if GTK_CHECK_VERSION(2,12,0)
1187 gtk_widget_set_tooltip_text(tag_te, "The verification tag to set in the SCTP header");
1189 gtk_tooltips_set_tip(tooltips, tag_te, "The verification tag to set in the SCTP header", NULL);
1191 gtk_box_pack_end(GTK_BOX(header_rblbl_5_hb), tag_te, FALSE, FALSE, 0);
1193 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_LBL_KEY, header_rblbl_5_lbl);
1194 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_TAG_TE_KEY, tag_te);
1197 header_rblbl_6_hb = gtk_hbox_new(FALSE, 0);
1198 gtk_box_pack_start(GTK_BOX(header_rblbl_vb), header_rblbl_6_hb, FALSE, FALSE, 2);
1200 header_sctp_data_rb = gtk_radio_button_new_with_label(header_grp, "SCTP (DATA)");
1201 #if GTK_CHECK_VERSION(2,12,0)
1202 gtk_widget_set_tooltip_text(header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames");
1204 gtk_tooltips_set_tip(tooltips, header_sctp_data_rb, "Prefix an Ethernet, IPv4 and SCTP DATA header to the frames", NULL);
1206 header_grp = gtk_radio_button_get_group(GTK_RADIO_BUTTON(header_sctp_data_rb));
1207 g_signal_connect(header_sctp_data_rb, "toggled", G_CALLBACK(header_sctp_data_rb_toggle), header_frm);
1208 gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_sctp_data_rb, FALSE, FALSE, 0);
1210 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_SCTP_D_RB_KEY, header_sctp_data_rb);
1212 header_rblbl_6_lbl = gtk_label_new(" PPI:");
1213 gtk_box_pack_start(GTK_BOX(header_rblbl_6_hb), header_rblbl_6_lbl, TRUE, TRUE, 0);
1214 gtk_misc_set_alignment(GTK_MISC(header_rblbl_6_lbl), 1.0f, 0.5f);
1216 ppi_te = gtk_entry_new();
1217 #if GTK_CHECK_VERSION(2,12,0)
1218 gtk_widget_set_tooltip_text(ppi_te, "The payload protocol identifier to set in the SCTP DATA header");
1220 gtk_tooltips_set_tip(tooltips, ppi_te, "The payload protocol identifier to set in the SCTP DATA header", NULL);
1222 gtk_box_pack_end(GTK_BOX(header_rblbl_6_hb), ppi_te, FALSE, FALSE, 0);
1224 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_LBL_KEY, header_rblbl_6_lbl);
1225 g_object_set_data(G_OBJECT(header_frm), IMPORT_HEADER_PPI_TE_KEY, ppi_te);
1227 /* Set sensitivity */
1228 g_signal_connect(header_cb, "toggled", G_CALLBACK(header_cb_toggle), header_frm);
1229 g_signal_emit_by_name(G_OBJECT(header_cb), "toggled", header_frm);
1231 g_signal_emit_by_name(G_OBJECT(header_eth_rb), "toggled", header_frm);
1233 g_signal_connect(encap_co, "changed", G_CALLBACK(encap_co_changed), header_frm);
1234 gtk_combo_box_set_active(GTK_COMBO_BOX(encap_co), 0);
1237 framelen_hb = gtk_hbox_new(FALSE, 3);
1238 gtk_container_set_border_width(GTK_CONTAINER(framelen_hb), 3);
1239 gtk_box_pack_start(GTK_BOX(import_vb), framelen_hb, FALSE, FALSE, 0);
1241 framelen_lbl = gtk_label_new("Max. frame length:");
1242 gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_lbl, FALSE, FALSE, 0);
1244 framelen_te = gtk_entry_new();
1245 #if GTK_CHECK_VERSION(2,12,0)
1246 gtk_widget_set_tooltip_text(framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)");
1248 gtk_tooltips_set_tip(tooltips, framelen_te, "The maximum size of the frames to write to the import capture file (max 64000)", NULL);
1250 gtk_box_pack_start(GTK_BOX(framelen_hb), framelen_te, FALSE, FALSE, 0);
1252 g_object_set_data(G_OBJECT(import_frm), IMPORT_FRAME_LENGTH_TE_KEY, framelen_te);
1254 /* Setup the button row */
1256 bbox = dlg_button_row_new(GTK_STOCK_HELP, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
1257 gtk_box_pack_end(GTK_BOX(main_vb), bbox, FALSE, FALSE, 3);
1259 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1260 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_IMPORT_DIALOG);
1261 #if GTK_CHECK_VERSION(2,12,0)
1262 gtk_widget_set_tooltip_text(help_bt, "Show topic specific help");
1264 gtk_tooltips_set_tip(tooltips, help_bt, "Show topic specific help", NULL);
1267 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
1268 window_set_cancel_button(main_w, close_bt, window_cancel_button_cb);
1269 #if GTK_CHECK_VERSION(2,12,0)
1270 gtk_widget_set_tooltip_text(close_bt, "Close this dialog");
1272 gtk_tooltips_set_tip(tooltips, close_bt, "Close this dialog", NULL);
1275 ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
1276 g_signal_connect(ok_bt, "clicked", G_CALLBACK(file_import_ok_cb), main_w);
1277 gtk_widget_grab_default(ok_bt);
1278 #if GTK_CHECK_VERSION(2,12,0)
1279 gtk_widget_set_tooltip_text(ok_bt, "Import the selected file into a temporary capture file");
1281 gtk_tooltips_set_tip(tooltips, ok_bt, "Import the selected file into a temporary capture file", NULL);
1284 /* Setup widget handling */
1286 g_signal_connect(main_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1287 g_signal_connect(main_w, "destroy", G_CALLBACK(file_import_dlg_destroy_cb), NULL);
1289 gtk_widget_show_all(main_w);
1290 window_present(main_w);
1296 file_import_cmd_cb(GtkWidget *widget _U_)
1298 /* Do we have an encapsulation type list? */
1299 if (!encap_list_store)
1301 /* No. Create one. */
1302 create_encap_list_store();
1305 /* Has a file import dialog already been opened? */
1306 if (file_import_dlg_w)
1308 /* Yes. Just re-activate that dialog box. */
1309 reactivate_window(file_import_dlg_w);
1311 /* No. Create one */
1312 file_import_dlg_w = file_import_dlg_new();