5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@ethereal.com>
7 * Copyright 1998 Gerald Combs
9 * Richard Sharpe, 13-Feb-1999, added support for initializing structures
10 * needed by dissect routines
11 * Jeff Foster, 2001/03/12, added support tabbed hex display windowss
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 #include <io.h> /* open/close on win32 */
46 #ifdef NEED_STRERROR_H
54 #ifdef _WIN32 /* Needed for console I/O */
59 #include <epan/epan.h>
60 #include <epan/filesystem.h>
61 #include <epan/epan_dissect.h>
62 #include <epan/timestamp.h>
63 #include <epan/packet.h>
64 #include <epan/plugins.h>
65 #include <epan/dfilter/dfilter.h>
66 #include <epan/strutil.h>
67 #include <epan/addr_resolv.h>
69 /* general (not GTK specific) */
70 #include "svnversion.h"
74 #include "disabled_protos.h"
75 #include <epan/prefs.h>
76 #include "filter_dlg.h"
77 #include "layout_prefs.h"
79 #include "color_filters.h"
81 #include "simple_dialog.h"
83 #include <epan/prefs-int.h>
84 #include "ringbuffer.h"
85 #include "../ui_util.h" /* beware: ui_util.h exists twice! */
88 #include "clopts_common.h"
89 #include "version_info.h"
94 #include "pcap-util.h"
99 #include "capture-wpcap.h"
100 #include "capture_wpcap_packet.h"
103 #if GTK_MAJOR_VERSION < 2 && GTK_MINOR_VERSION < 3
104 #include "ethclist.h"
108 #include "statusbar.h"
109 #include "alert_box.h"
110 #include "dlg_utils.h"
111 #include "gtkglobals.h"
113 #include "ui_util.h" /* beware: ui_util.h exists twice! */
114 #include "compat_macros.h"
118 #include "../main_window.h"
120 #include "file_dlg.h"
121 #include <epan/column.h>
122 #include "proto_draw.h"
124 #include "packet_win.h"
126 #include "find_dlg.h"
127 #include "packet_list.h"
129 #include "follow_dlg.h"
130 #include "font_utils.h"
131 #include "about_dlg.h"
132 #include "help_dlg.h"
133 #include "decode_as_dlg.h"
134 #include "webbrowser.h"
135 #include "capture_dlg.h"
137 #include "../image/eicon3d64.xpm"
139 #include "capture_ui_utils.h"
141 #include "../epan/emem.h"
146 * Files under personal and global preferences directories in which
147 * GTK settings for Ethereal are stored.
149 #define RC_FILE "gtkrc"
152 #define DEF_READY_MESSAGE " Ready to load or capture"
154 #define DEF_READY_MESSAGE " Ready to load file"
158 GtkWidget *main_display_filter_widget=NULL;
159 GtkWidget *top_level = NULL, *tree_view, *byte_nb_ptr, *tv_scrollw;
160 static GtkWidget *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2;
161 static GtkWidget *main_first_pane, *main_second_pane;
162 static GtkWidget *status_pane;
163 static GtkWidget *menubar, *main_vbox, *main_tb, *pkt_scrollw, *stat_hbox, *filter_tb;
164 static GtkWidget *info_bar;
165 static GtkWidget *packets_bar = NULL;
166 static GtkWidget *welcome_pane;
167 static guint main_ctx, file_ctx, help_ctx;
168 static guint packets_ctx;
169 static gchar *packets_str = NULL;
170 GString *comp_info_str, *runtime_info_str;
171 gchar *ethereal_path = NULL;
172 gboolean have_capture_file = FALSE; /* XXX - is there an aquivalent in cfile? */
175 static gboolean has_console; /* TRUE if app has console */
176 static void destroy_console(void);
178 static void console_log_handler(const char *log_domain,
179 GLogLevelFlags log_level, const char *message, gpointer user_data);
182 static gboolean list_link_layer_types;
183 capture_options global_capture_opts;
184 capture_options *capture_opts = &global_capture_opts;
188 static void create_main_window(gint, gint, gint, e_prefs*);
189 static void show_main_window(gboolean);
190 static void file_quit_answered_cb(gpointer dialog, gint btn, gpointer data);
191 static void main_save_window_geometry(GtkWidget *widget);
193 #define E_DFILTER_CM_KEY "display_filter_combo"
194 #define E_DFILTER_FL_KEY "display_filter_list"
198 /* Match selected byte pattern */
200 match_selected_cb_do(gpointer data, int action, gchar *text)
202 GtkWidget *filter_te;
203 char *cur_filter, *new_filter;
208 filter_te = OBJECT_GET_DATA(data, E_DFILTER_TE_KEY);
211 cur_filter = gtk_editable_get_chars(GTK_EDITABLE(filter_te), 0, -1);
213 switch (action&MATCH_SELECTED_MASK) {
215 case MATCH_SELECTED_REPLACE:
216 new_filter = g_strdup(text);
219 case MATCH_SELECTED_AND:
220 if ((!cur_filter) || (0 == strlen(cur_filter)))
221 new_filter = g_strdup(text);
223 new_filter = g_strconcat("(", cur_filter, ") && (", text, ")", NULL);
226 case MATCH_SELECTED_OR:
227 if ((!cur_filter) || (0 == strlen(cur_filter)))
228 new_filter = g_strdup(text);
230 new_filter = g_strconcat("(", cur_filter, ") || (", text, ")", NULL);
233 case MATCH_SELECTED_NOT:
234 new_filter = g_strconcat("!(", text, ")", NULL);
237 case MATCH_SELECTED_AND_NOT:
238 if ((!cur_filter) || (0 == strlen(cur_filter)))
239 new_filter = g_strconcat("!(", text, ")", NULL);
241 new_filter = g_strconcat("(", cur_filter, ") && !(", text, ")", NULL);
244 case MATCH_SELECTED_OR_NOT:
245 if ((!cur_filter) || (0 == strlen(cur_filter)))
246 new_filter = g_strconcat("!(", text, ")", NULL);
248 new_filter = g_strconcat("(", cur_filter, ") || !(", text, ")", NULL);
252 g_assert_not_reached();
257 /* Free up the copy we got of the old filter text. */
260 /* create a new one and set the display filter entry accordingly */
261 gtk_entry_set_text(GTK_ENTRY(filter_te), new_filter);
263 /* Run the display filter so it goes in effect. */
264 if (action&MATCH_SELECTED_APPLY_NOW)
265 main_filter_packets(&cfile, new_filter, FALSE);
267 /* Free up the new filter text. */
270 /* Free up the generated text we were handed. */
275 match_selected_ptree_cb(GtkWidget *w, gpointer data, MATCH_SELECTED_E action)
277 if (cfile.finfo_selected)
278 match_selected_cb_do((data ? data : w),
280 proto_construct_dfilter_string(cfile.finfo_selected, cfile.edt));
284 static void selected_ptree_info_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
286 gchar *selected_proto_url;
287 gchar *proto_abbrev = data;
292 if (cfile.finfo_selected) {
293 /* open wiki page using the protocol abbreviation */
294 selected_proto_url = g_strdup_printf("http://wiki.ethereal.com/Protocols/%s", proto_abbrev);
295 browser_open_url(selected_proto_url);
296 g_free(selected_proto_url);
299 case(ESD_BTN_CANCEL):
302 g_assert_not_reached();
308 selected_ptree_info_cb(GtkWidget *widget _U_, gpointer data _U_)
311 const gchar *proto_abbrev;
315 if (cfile.finfo_selected) {
316 /* convert selected field to protocol abbreviation */
317 /* XXX - could this conversion be simplified? */
318 field_id = cfile.finfo_selected->hfinfo->id;
319 /* if the selected field isn't a protocol, get it's parent */
320 if(!proto_registrar_is_protocol(field_id)) {
321 field_id = proto_registrar_get_parent(cfile.finfo_selected->hfinfo->id);
324 proto_abbrev = proto_registrar_get_abbrev(field_id);
326 /* ask the user if the wiki page really should be opened */
327 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
328 PRIMARY_TEXT_START "Open Ethereal Wiki page of protocol \"%s\"?" PRIMARY_TEXT_END "\n"
330 "This will open the \"%s\" related Ethereal Wiki page in your Web browser.\n"
332 "The Ethereal Wiki is a collaborative approach to provide information\n"
333 "about Ethereal in several ways (not limited to protocol specifics).\n"
335 "This Wiki is new, so the page of the selected protocol\n"
336 "may not exist and/or may not contain valuable information.\n"
338 "As everyone can edit the Wiki and add new content (or extend existing),\n"
339 "you are encouraged to add information if you can.\n"
341 "Hint 1: If you are new to wiki editing, try out editing the Sandbox first!\n"
343 "Hint 2: If you want to add a new protocol page, you should use the ProtocolTemplate,\n"
344 "which will save you a lot of editing and will give a consistent look over the pages.",
345 proto_abbrev, proto_abbrev);
346 simple_dialog_set_cb(dialog, selected_ptree_info_answered_cb, (gpointer) proto_abbrev);
352 selected_ptree_ref_cb(GtkWidget *widget _U_, gpointer data _U_)
355 const gchar *proto_abbrev;
356 gchar *selected_proto_url;
359 if (cfile.finfo_selected) {
360 /* convert selected field to protocol abbreviation */
361 /* XXX - could this conversion be simplified? */
362 field_id = cfile.finfo_selected->hfinfo->id;
363 /* if the selected field isn't a protocol, get it's parent */
364 if(!proto_registrar_is_protocol(field_id)) {
365 field_id = proto_registrar_get_parent(cfile.finfo_selected->hfinfo->id);
368 proto_abbrev = proto_registrar_get_abbrev(field_id);
370 /* open reference page using the protocol abbreviation */
371 selected_proto_url = g_strdup_printf("http://www.ethereal.com/docs/dfref/%c/%s", proto_abbrev[0], proto_abbrev);
372 browser_open_url(selected_proto_url);
373 g_free(selected_proto_url);
379 get_text_from_packet_list(gpointer data)
381 gint row = GPOINTER_TO_INT(OBJECT_GET_DATA(data, E_MPACKET_LIST_ROW_KEY));
382 gint column = GPOINTER_TO_INT(OBJECT_GET_DATA(data, E_MPACKET_LIST_COL_KEY));
383 frame_data *fdata = (frame_data *)packet_list_get_row_data(row);
391 if (!wtap_seek_read(cfile.wth, fdata->file_off, &cfile.pseudo_header,
392 cfile.pd, fdata->cap_len, &err, &err_info)) {
393 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
394 cf_read_error_message(err, err_info), cfile.filename);
398 edt = epan_dissect_new(FALSE, FALSE);
399 epan_dissect_run(edt, &cfile.pseudo_header, cfile.pd, fdata,
401 epan_dissect_fill_in_columns(edt);
403 if (strlen(cfile.cinfo.col_expr[column]) != 0 &&
404 strlen(cfile.cinfo.col_expr_val[column]) != 0) {
405 len = strlen(cfile.cinfo.col_expr[column]) +
406 strlen(cfile.cinfo.col_expr_val[column]) + 5;
407 buf = g_malloc0(len);
408 g_snprintf(buf, len, "%s == %s", cfile.cinfo.col_expr[column],
409 cfile.cinfo.col_expr_val[column]);
412 epan_dissect_free(edt);
419 match_selected_plist_cb(GtkWidget *w _U_, gpointer data, MATCH_SELECTED_E action)
421 match_selected_cb_do(data,
423 get_text_from_packet_list(data));
428 /* XXX: use a preference for this setting! */
429 static guint dfilter_combo_max_recent = 10;
431 /* add a display filter to the combo box */
432 /* Note: a new filter string will replace an old identical one */
434 dfilter_combo_add(GtkWidget *filter_cm, char *s) {
436 GList *dfilter_list = OBJECT_GET_DATA(filter_cm, E_DFILTER_FL_KEY);
439 /* GtkCombos don't let us get at their list contents easily, so we maintain
440 our own filter list, and feed it to gtk_combo_set_popdown_strings when
441 a new filter is added. */
442 li = g_list_first(dfilter_list);
444 /* If the filter is already in the list, remove the old one and
445 * append the new one at the latest position (at g_list_append() below) */
446 if (li->data && strcmp(s, li->data) == 0) {
447 dfilter_list = g_list_remove(dfilter_list, li->data);
453 dfilter_list = g_list_append(dfilter_list, s);
454 OBJECT_SET_DATA(filter_cm, E_DFILTER_FL_KEY, dfilter_list);
455 gtk_combo_set_popdown_strings(GTK_COMBO(filter_cm), dfilter_list);
456 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(filter_cm)->entry), g_list_last(dfilter_list)->data);
462 /* write all non empty display filters (until maximum count)
463 * of the combo box GList to the user's recent file */
465 dfilter_recent_combo_write_all(FILE *rf) {
466 GtkWidget *filter_cm = OBJECT_GET_DATA(top_level, E_DFILTER_CM_KEY);
467 GList *dfilter_list = OBJECT_GET_DATA(filter_cm, E_DFILTER_FL_KEY);
472 /* write all non empty display filter strings to the recent file (until max count) */
473 li = g_list_first(dfilter_list);
474 while ( li && (max_count++ <= dfilter_combo_max_recent) ) {
475 if (strlen(li->data)) {
476 fprintf (rf, RECENT_KEY_DISPLAY_FILTER ": %s\n", (char *)li->data);
482 /* empty the combobox entry field */
484 dfilter_combo_add_empty(void) {
485 GtkWidget *filter_cm = OBJECT_GET_DATA(top_level, E_DFILTER_CM_KEY);
487 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(filter_cm)->entry), "");
491 /* add a display filter coming from the user's recent file to the dfilter combo box */
493 dfilter_combo_add_recent(gchar *s) {
494 GtkWidget *filter_cm = OBJECT_GET_DATA(top_level, E_DFILTER_CM_KEY);
498 if (!dfilter_combo_add(filter_cm, dup)) {
507 /* call cf_filter_packets() and add this filter string to the recent filter list */
509 main_filter_packets(capture_file *cf, const gchar *dftext, gboolean force)
511 GtkCombo *filter_cm = OBJECT_GET_DATA(top_level, E_DFILTER_CM_KEY);
512 GList *dfilter_list = OBJECT_GET_DATA(filter_cm, E_DFILTER_FL_KEY);
514 gboolean add_filter = TRUE;
515 gboolean free_filter = TRUE;
517 cf_status_t cf_status;
519 /* we'll crash later on if dftext is NULL */
520 g_assert(dftext != NULL);
522 s = g_strdup(dftext);
524 /* GtkCombos don't let us get at their list contents easily, so we maintain
525 our own filter list, and feed it to gtk_combo_set_popdown_strings when
526 a new filter is added. */
527 cf_status = cf_filter_packets(cf, s, force);
528 if (cf_status == CF_OK) {
529 li = g_list_first(dfilter_list);
531 if (li->data && strcmp(s, li->data) == 0)
537 /* trim list size first */
538 while (g_list_length(dfilter_list) >= dfilter_combo_max_recent) {
539 dfilter_list = g_list_remove(dfilter_list, g_list_first(dfilter_list)->data);
543 dfilter_list = g_list_append(dfilter_list, s);
544 OBJECT_SET_DATA(filter_cm, E_DFILTER_FL_KEY, dfilter_list);
545 gtk_combo_set_popdown_strings(filter_cm, dfilter_list);
546 gtk_entry_set_text(GTK_ENTRY(filter_cm->entry), g_list_last(dfilter_list)->data);
552 return (cf_status == CF_OK);
556 /* Run the current display filter on the current packet set, and
559 filter_activate_cb(GtkWidget *w _U_, gpointer data)
563 s = gtk_entry_get_text(GTK_ENTRY(data));
565 main_filter_packets(&cfile, s, FALSE);
568 /* redisplay with no display filter */
570 filter_reset_cb(GtkWidget *w, gpointer data _U_)
572 GtkWidget *filter_te = NULL;
574 if ((filter_te = OBJECT_GET_DATA(w, E_DFILTER_TE_KEY))) {
575 gtk_entry_set_text(GTK_ENTRY(filter_te), "");
577 main_filter_packets(&cfile, "", FALSE);
580 /* mark as reference time frame */
582 set_frame_reftime(gboolean set, frame_data *frame, gint row) {
586 frame->flags.ref_time=1;
588 frame->flags.ref_time=0;
590 cf_reftime_packets(&cfile);
594 reftime_frame_cb(GtkWidget *w _U_, gpointer data _U_, REFTIME_ACTION_E action)
599 if (cfile.current_frame) {
600 /* XXX hum, should better have a "cfile->current_row" here ... */
601 set_frame_reftime(!cfile.current_frame->flags.ref_time,
603 packet_list_find_row_from_data(cfile.current_frame));
606 case REFTIME_FIND_NEXT:
607 find_previous_next_frame_with_filter("frame.ref_time", FALSE);
609 case REFTIME_FIND_PREV:
610 find_previous_next_frame_with_filter("frame.ref_time", TRUE);
615 #if GTK_MAJOR_VERSION < 2
617 tree_view_select_row_cb(GtkCTree *ctree, GList *node, gint column _U_,
618 gpointer user_data _U_)
621 tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
625 gchar *help_str = NULL;
626 gchar len_str[2+10+1+5+1]; /* ", {N} bytes\0",
628 gboolean has_blurb = FALSE;
629 guint length = 0, byte_len;
630 GtkWidget *byte_view;
631 const guint8 *byte_data;
632 #if GTK_MAJOR_VERSION >= 2
637 #if GTK_MAJOR_VERSION >= 2
638 /* if nothing is selected */
639 if (!gtk_tree_selection_get_selected(sel, &model, &iter))
642 * Which byte view is displaying the current protocol tree
645 byte_view = get_notebook_bv_ptr(byte_nb_ptr);
646 if (byte_view == NULL)
649 byte_data = get_byte_view_data_and_length(byte_view, &byte_len);
650 if (byte_data == NULL)
653 cf_unselect_field(&cfile);
654 packet_hex_print(GTK_TEXT_VIEW(byte_view), byte_data,
655 cfile.current_frame, NULL, byte_len);
658 gtk_tree_model_get(model, &iter, 1, &finfo, -1);
661 finfo = gtk_ctree_node_get_row_data( ctree, GTK_CTREE_NODE(node) );
665 set_notebook_page(byte_nb_ptr, finfo->ds_tvb);
667 byte_view = get_notebook_bv_ptr(byte_nb_ptr);
668 byte_data = get_byte_view_data_and_length(byte_view, &byte_len);
669 g_assert(byte_data != NULL);
671 cfile.finfo_selected = finfo;
672 set_menus_for_selected_tree_row(&cfile);
675 if (finfo->hfinfo->blurb != NULL &&
676 finfo->hfinfo->blurb[0] != '\0') {
678 length = strlen(finfo->hfinfo->blurb);
680 length = strlen(finfo->hfinfo->name);
682 if (finfo->length == 0) {
684 } else if (finfo->length == 1) {
685 strcpy (len_str, ", 1 byte");
687 g_snprintf (len_str, sizeof len_str, ", %d bytes", finfo->length);
689 statusbar_pop_field_msg(); /* get rid of current help msg */
691 help_str = g_strdup_printf("%s (%s)%s",
692 (has_blurb) ? finfo->hfinfo->blurb : finfo->hfinfo->name,
693 finfo->hfinfo->abbrev, len_str);
694 statusbar_push_field_msg(help_str);
698 * Don't show anything if the field name is zero-length;
699 * the pseudo-field for "proto_tree_add_text()" is such
700 * a field, and we don't want "Text (text)" showing up
701 * on the status line if you've selected such a field.
703 * XXX - there are zero-length fields for which we *do*
704 * want to show the field name.
706 * XXX - perhaps the name and abbrev field should be null
707 * pointers rather than null strings for that pseudo-field,
708 * but we'd have to add checks for null pointers in some
709 * places if we did that.
711 * Or perhaps protocol tree items added with
712 * "proto_tree_add_text()" should have -1 as the field index,
713 * with no pseudo-field being used, but that might also
714 * require special checks for -1 to be added.
716 statusbar_push_field_msg("");
720 #if GTK_MAJOR_VERSION < 2
721 packet_hex_print(GTK_TEXT(byte_view), byte_data, cfile.current_frame,
724 packet_hex_print(GTK_TEXT_VIEW(byte_view), byte_data, cfile.current_frame,
729 #if GTK_MAJOR_VERSION < 2
731 tree_view_unselect_row_cb(GtkCTree *ctree _U_, GList *node _U_, gint column _U_,
732 gpointer user_data _U_)
734 GtkWidget *byte_view;
739 * Which byte view is displaying the current protocol tree
742 byte_view = get_notebook_bv_ptr(byte_nb_ptr);
743 if (byte_view == NULL)
746 data = get_byte_view_data_and_length(byte_view, &len);
750 cf_unselect_field(&cfile);
751 packet_hex_print(GTK_TEXT(byte_view), data, cfile.current_frame,
756 void collapse_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
758 collapse_all_tree(cfile.edt->tree, tree_view);
761 void expand_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
763 expand_all_tree(cfile.edt->tree, tree_view);
766 void expand_tree_cb(GtkWidget *widget _U_, gpointer data _U_) {
767 #if GTK_MAJOR_VERSION < 2
773 #if GTK_MAJOR_VERSION < 2
774 node = gtk_ctree_find_by_row_data(GTK_CTREE(tree_view), NULL, cfile.finfo_selected);
776 /* the mouse position is at an entry, expand that one */
777 gtk_ctree_expand_recursive(GTK_CTREE(tree_view), node);
780 path = tree_find_by_field_info(GTK_TREE_VIEW(tree_view), cfile.finfo_selected);
782 /* the mouse position is at an entry, expand that one */
783 gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view), path, TRUE);
784 gtk_tree_path_free(path);
789 void resolve_name_cb(GtkWidget *widget _U_, gpointer data _U_) {
790 if (cfile.edt->tree) {
791 guint32 tmp = g_resolv_flags;
792 g_resolv_flags = RESOLV_ALL;
793 proto_tree_draw(cfile.edt->tree, tree_view);
794 g_resolv_flags = tmp;
799 * Push a message referring to file access onto the statusbar.
802 statusbar_push_file_msg(gchar *msg)
804 /*g_warning("statusbar_push: %s", msg);*/
805 gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, msg);
809 * Pop a message referring to file access off the statusbar.
812 statusbar_pop_file_msg(void)
814 /*g_warning("statusbar_pop");*/
815 gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx);
819 * XXX - do we need multiple statusbar contexts?
823 * Push a message referring to the currently-selected field onto the statusbar.
826 statusbar_push_field_msg(gchar *msg)
828 gtk_statusbar_push(GTK_STATUSBAR(info_bar), help_ctx, msg);
832 * Pop a message referring to the currently-selected field off the statusbar.
835 statusbar_pop_field_msg(void)
837 gtk_statusbar_pop(GTK_STATUSBAR(info_bar), help_ctx);
841 * update the packets statusbar to the current values
843 void packets_bar_update(void)
847 /* remove old status */
850 gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
853 /* do we have any packets? */
855 if(cfile.drops_known) {
856 packets_str = g_strdup_printf(" P: %u D: %u M: %u Drops: %u",
857 cfile.count, cfile.displayed_count, cfile.marked_count, cfile.drops);
859 packets_str = g_strdup_printf(" P: %u D: %u M: %u",
860 cfile.count, cfile.displayed_count, cfile.marked_count);
863 packets_str = g_strdup(" No Packets");
865 gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, packets_str);
870 main_set_for_capture_file(gboolean have_capture_file_in)
872 have_capture_file = have_capture_file_in;
874 main_widgets_show_or_hide();
880 /* get the current geometry, before writing it to disk */
881 main_save_window_geometry(top_level);
883 /* write user's recent file to disk
884 * It is no problem to write this file, even if we do not quit */
887 /* XXX - should we check whether the capture file is an
888 unsaved temporary file for a live capture and, if so,
889 pop up a "do you want to exit without saving the capture
890 file?" dialog, and then just return, leaving said dialog
891 box to forcibly quit if the user clicks "OK"?
893 If so, note that this should be done in a subroutine that
894 returns TRUE if we do so, and FALSE otherwise, and if it
895 returns TRUE we should return TRUE without nuking anything.
897 Note that, if we do that, we might also want to check if
898 an "Update list of packets in real time" capture is in
899 progress and, if so, ask whether they want to terminate
900 the capture and discard it, and return TRUE, before nuking
901 any child capture, if they say they don't want to do so. */
904 /* Nuke any child capture in progress. */
905 capture_kill_child(capture_opts);
908 /* Are we in the middle of reading a capture? */
909 if (cfile.state == FILE_READ_IN_PROGRESS) {
910 /* Yes, so we can't just close the file and quit, as
911 that may yank the rug out from under the read in
912 progress; instead, just set the state to
913 "FILE_READ_ABORTED" and return - the code doing the read
914 will check for that and, if it sees that, will clean
916 cfile.state = FILE_READ_ABORTED;
918 /* Say that the window should *not* be deleted;
919 that'll be done by the code that cleans up. */
922 /* Close any capture file we have open; on some OSes, you
923 can't unlink a temporary capture file if you have it
925 "cf_close()" will unlink it after closing it if
926 it's a temporary file.
928 We do this here, rather than after the main loop returns,
929 as, after the main loop returns, the main window may have
930 been destroyed (if this is called due to a "destroy"
931 even on the main window rather than due to the user
932 selecting a menu item), and there may be a crash
933 or other problem when "cf_close()" tries to
934 clean up stuff in the main window.
936 XXX - is there a better place to put this?
937 Or should we have a routine that *just* closes the
938 capture file, and doesn't do anything with the UI,
939 which we'd call here, and another routine that
940 calls that routine and also cleans up the UI, which
941 we'd call elsewhere? */
944 /* Exit by leaving the main loop, so that any quit functions
945 we registered get called. */
948 /* Say that the window should be deleted. */
954 main_window_delete_event_cb(GtkWidget *widget _U_, GdkEvent *event _U_, gpointer data _U_)
958 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
959 #if GTK_MAJOR_VERSION >= 2
960 gtk_window_present(GTK_WINDOW(top_level));
962 /* user didn't saved his current file, ask him */
963 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
964 PRIMARY_TEXT_START "Save capture file before program quit?" PRIMARY_TEXT_END "\n\n"
965 "If you quit the program without saving, your capture data will be discarded.");
966 simple_dialog_set_cb(dialog, file_quit_answered_cb, NULL);
969 /* unchanged file, just exit */
970 /* "main_do_quit()" indicates whether the main window should be deleted. */
971 return main_do_quit();
978 main_load_window_geometry(GtkWidget *widget)
980 window_geometry_t geom;
982 geom.set_pos = prefs.gui_geometry_save_position;
983 geom.x = recent.gui_geometry_main_x;
984 geom.y = recent.gui_geometry_main_y;
985 geom.set_size = prefs.gui_geometry_save_size;
986 if (recent.gui_geometry_main_width > 0 &&
987 recent.gui_geometry_main_height > 0) {
988 geom.width = recent.gui_geometry_main_width;
989 geom.height = recent.gui_geometry_main_height;
990 geom.set_maximized = prefs.gui_geometry_save_maximized;
992 /* We assume this means the width and height weren't set in
993 the "recent" file (or that there is no "recent" file),
994 and weren't set to a default value, so we don't set the
995 size. (The "recent" file code rejects non-positive width
996 and height values.) */
997 geom.set_size = FALSE;
999 geom.maximized = recent.gui_geometry_main_maximized;
1001 window_set_geometry(widget, &geom);
1003 if (recent.has_gui_geometry_main_upper_pane && recent.gui_geometry_main_upper_pane)
1004 gtk_paned_set_position(GTK_PANED(main_first_pane), recent.gui_geometry_main_upper_pane);
1005 if (recent.has_gui_geometry_main_lower_pane && recent.gui_geometry_main_lower_pane)
1006 gtk_paned_set_position(GTK_PANED(main_second_pane), recent.gui_geometry_main_lower_pane);
1007 if (recent.has_gui_geometry_main_lower_pane && recent.gui_geometry_status_pane)
1008 gtk_paned_set_position(GTK_PANED(status_pane), recent.gui_geometry_status_pane);
1013 main_save_window_geometry(GtkWidget *widget)
1015 window_geometry_t geom;
1017 window_get_geometry(widget, &geom);
1019 if (prefs.gui_geometry_save_position) {
1020 recent.gui_geometry_main_x = geom.x;
1021 recent.gui_geometry_main_y = geom.y;
1024 if (prefs.gui_geometry_save_size) {
1025 recent.gui_geometry_main_width = geom.width,
1026 recent.gui_geometry_main_height = geom.height;
1029 #if GTK_MAJOR_VERSION >= 2
1030 if(prefs.gui_geometry_save_maximized) {
1031 recent.gui_geometry_main_maximized = geom.maximized;
1034 recent.gui_geometry_main_upper_pane = gtk_paned_get_position(GTK_PANED(main_first_pane));
1035 recent.gui_geometry_main_lower_pane = gtk_paned_get_position(GTK_PANED(main_second_pane));
1036 recent.gui_geometry_status_pane = gtk_paned_get_position(GTK_PANED(status_pane));
1040 static void file_quit_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
1044 /* save file first */
1045 file_save_as_cmd(after_save_exit, NULL);
1047 case(ESD_BTN_DONT_SAVE):
1050 case(ESD_BTN_CANCEL):
1053 g_assert_not_reached();
1058 file_quit_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
1062 if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) {
1063 /* user didn't saved his current file, ask him */
1064 dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL,
1065 PRIMARY_TEXT_START "Save capture file before program quit?" PRIMARY_TEXT_END "\n\n"
1066 "If you quit the program without saving, your capture data will be discarded.");
1067 simple_dialog_set_cb(dialog, file_quit_answered_cb, NULL);
1069 /* unchanged file, just exit */
1075 print_usage(gboolean print_ver) {
1085 fprintf(output, "This is "PACKAGE " " VERSION
1089 "\n (C) 1998-2005 Gerald Combs <gerald@ethereal.com>"
1091 comp_info_str->str, runtime_info_str->str);
1096 fprintf(output, "\n%s [ -vh ] [ -klLnpQS ] [ -a <capture autostop condition> ] ...\n", PACKAGE);
1097 fprintf(output, "\t[ -b <capture ring buffer option> ] ...\n");
1098 fprintf(output, "\t[ -B capture buffer size (Win32 only) ]\n");
1099 fprintf(output, "\t[ -c <capture packet count> ] [ -f <capture filter> ]\n");
1100 fprintf(output, "\t[ -g <packet number> ]\n");
1101 fprintf(output, "\t[ -i <capture interface> ] [ -m <font> ] [ -N <name resolving flags> ]\n");
1102 fprintf(output, "\t[ -o <preference/recent setting> ] ...\n");
1103 fprintf(output, "\t[ -r <infile> ] [ -R <read (display) filter> ] [ -s <capture snaplen> ]\n");
1104 fprintf(output, "\t[ -t <time stamp format> ]\n");
1105 fprintf(output, "\t[ -w <savefile> ] [ -y <capture link type> ] [ -z <statistics> ]\n");
1106 fprintf(output, "\t[ <infile> ]\n");
1108 fprintf(output, "\n%s [ -vh ] [ -n ] [ -g <packet number> ] [ -m <font> ]\n", PACKAGE);
1109 fprintf(output, "\t[ -N <resolving flags> ] [ -o <preference/recent setting> ...\n");
1110 fprintf(output, "\t[ -r <infile> ] [ -R <read (display) filter> ]\n");
1111 fprintf(output, "\t[ -t <time stamp format> ]\n");
1112 fprintf(output, "\t[ -z <statistics ] [ <infile> ]\n");
1127 printf(PACKAGE " " VERSION
1132 comp_info_str->str, runtime_info_str->str);
1139 #if defined(_WIN32) || GTK_MAJOR_VERSION < 2 || ! defined USE_THREADS
1141 Once every 3 seconds we get a callback here which we use to update
1142 the tap extensions. Since Gtk1 is single threaded we dont have to
1143 worry about any locking or critical regions.
1146 update_cb(gpointer data _U_)
1148 draw_tap_listeners(FALSE);
1153 /* if these three functions are copied to gtk1 ethereal, since gtk1 does not
1154 use threads all updte_thread_mutex can be dropped and protect/unprotect
1155 would just be empty functions.
1157 This allows gtk2-rpcstat.c and friends to be copied unmodified to
1158 gtk1-ethereal and it will just work.
1160 static GStaticMutex update_thread_mutex = G_STATIC_MUTEX_INIT;
1162 update_thread(gpointer data _U_)
1166 g_get_current_time(&tv1);
1167 g_static_mutex_lock(&update_thread_mutex);
1168 gdk_threads_enter();
1169 draw_tap_listeners(FALSE);
1170 gdk_threads_leave();
1171 g_static_mutex_unlock(&update_thread_mutex);
1173 g_get_current_time(&tv2);
1174 if( ((tv1.tv_sec + 2) * 1000000 + tv1.tv_usec) >
1175 (tv2.tv_sec * 1000000 + tv2.tv_usec) ){
1176 g_usleep(((tv1.tv_sec + 2) * 1000000 + tv1.tv_usec) -
1177 (tv2.tv_sec * 1000000 + tv2.tv_usec));
1184 protect_thread_critical_region(void)
1186 #if !defined(_WIN32) && GTK_MAJOR_VERSION >= 2 && defined USE_THREADS
1187 g_static_mutex_lock(&update_thread_mutex);
1191 unprotect_thread_critical_region(void)
1193 #if !defined(_WIN32) && GTK_MAJOR_VERSION >= 2 && defined USE_THREADS
1194 g_static_mutex_unlock(&update_thread_mutex);
1198 /* Set the file name in the status line, in the name for the main window,
1199 and in the name for the main window's icon. */
1201 set_display_filename(capture_file *cf)
1203 const gchar *name_ptr;
1208 name_ptr = cf_get_display_name(cf);
1210 if (!cf->is_tempfile && cf->filename) {
1211 /* Add this filename to the list of recent files in the "Recent Files" submenu */
1212 add_menu_recent_capture_file(cf->filename);
1215 /* convert file size */
1216 if (cf->f_len/1024/1024 > 10) {
1217 size_str = g_strdup_printf("%ld MB", cf->f_len/1024/1024);
1218 } else if (cf->f_len/1024 > 10) {
1219 size_str = g_strdup_printf("%ld KB", cf->f_len/1024);
1221 size_str = g_strdup_printf("%ld Bytes", cf->f_len);
1225 status_msg = g_strdup_printf(" File: \"%s\" %s %02u:%02u:%02u",
1226 (cf->filename) ? cf->filename : "", size_str,
1227 cf->esec/3600, cf->esec%3600/60, cf->esec%60);
1229 statusbar_push_file_msg(status_msg);
1233 win_name = g_strdup_printf("%s - Ethereal", name_ptr);
1234 set_main_window_name(win_name);
1240 main_cf_cb_file_closed(capture_file *cf)
1242 /* Destroy all windows, which refer to the
1243 capture file we're closing. */
1244 destroy_cfile_wins();
1246 /* Clear any file-related status bar messages.
1247 XXX - should be "clear *ALL* file-related status bar messages;
1248 will there ever be more than one on the stack? */
1249 statusbar_pop_file_msg();
1251 /* go back to "No packets" */
1252 packets_bar_update();
1254 /* Restore the standard title bar message. */
1255 set_main_window_name("The Ethereal Network Analyzer");
1257 /* Disable all menu items that make sense only if you have a capture. */
1258 set_menus_for_capture_file(FALSE);
1259 set_menus_for_unsaved_capture_file(FALSE);
1260 set_menus_for_captured_packets(FALSE);
1261 set_menus_for_selected_packet(cf);
1262 set_menus_for_capture_in_progress(FALSE);
1263 set_menus_for_selected_tree_row(cf);
1265 /* Set up main window for no capture file. */
1266 main_set_for_capture_file(FALSE);
1270 main_cf_cb_file_read_start(capture_file *cf)
1272 const gchar *name_ptr;
1275 name_ptr = get_basename(cf->filename);
1277 load_msg = g_strdup_printf(" Loading: %s", name_ptr);
1278 statusbar_push_file_msg(load_msg);
1283 main_cf_cb_file_read_finished(capture_file *cf)
1285 statusbar_pop_file_msg();
1286 set_display_filename(cf);
1288 /* Enable menu items that make sense if you have a capture file you've
1289 finished reading. */
1290 set_menus_for_capture_file(TRUE);
1291 set_menus_for_unsaved_capture_file(!cf->user_saved);
1293 /* Enable menu items that make sense if you have some captured packets. */
1294 set_menus_for_captured_packets(TRUE);
1296 /* Set up main window for a capture file. */
1297 main_set_for_capture_file(TRUE);
1302 main_cf_cb_live_capture_prepared(capture_options *capture_opts)
1307 if(capture_opts->iface) {
1308 title = g_strdup_printf("%s: Capturing - Ethereal",
1309 get_interface_descriptive_name(capture_opts->iface));
1311 title = g_strdup_printf("Capturing - Ethereal");
1313 set_main_window_name(title);
1316 /* Disable menu items that make no sense if you're currently running
1318 set_menus_for_capture_in_progress(TRUE);
1320 /* update statusbar */
1321 statusbar_push_file_msg("Waiting for capture input data ...");
1323 /* Don't set up main window for a capture file. */
1324 main_set_for_capture_file(FALSE);
1328 main_cf_cb_live_capture_update_started(capture_options *capture_opts)
1333 /* Enable menu items that make sense if you have some captured
1334 packets (yes, I know, we don't have any *yet*). */
1335 set_menus_for_captured_packets(TRUE);
1337 statusbar_pop_file_msg();
1339 capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
1340 get_interface_descriptive_name(capture_opts->iface),
1341 (capture_opts->save_file) ? capture_opts->save_file : "");
1343 statusbar_push_file_msg(capture_msg);
1345 g_free(capture_msg);
1347 /* Set up main window for a capture file. */
1348 main_set_for_capture_file(TRUE);
1352 main_cf_cb_live_capture_update_continue(capture_file *cf)
1357 statusbar_pop_file_msg();
1359 if (cf->f_len/1024/1024 > 10) {
1360 capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %ld MB",
1361 get_interface_descriptive_name(capture_opts->iface),
1362 capture_opts->save_file,
1363 cf->f_len/1024/1024);
1364 } else if (cf->f_len/1024 > 10) {
1365 capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %ld KB",
1366 get_interface_descriptive_name(capture_opts->iface),
1367 capture_opts->save_file,
1370 capture_msg = g_strdup_printf(" %s: <live capture in progress> File: %s %ld Bytes",
1371 get_interface_descriptive_name(capture_opts->iface),
1372 capture_opts->save_file,
1376 statusbar_push_file_msg(capture_msg);
1380 main_cf_cb_live_capture_update_finished(capture_file *cf)
1382 /* Pop the "<live capture in progress>" message off the status bar. */
1383 statusbar_pop_file_msg();
1385 set_display_filename(cf);
1387 /* Enable menu items that make sense if you're not currently running
1389 set_menus_for_capture_in_progress(FALSE);
1391 /* Enable menu items that make sense if you have a capture file
1392 you've finished reading. */
1393 set_menus_for_capture_file(TRUE);
1394 set_menus_for_unsaved_capture_file(!cf->user_saved);
1396 /* Set up main window for a capture file. */
1397 main_set_for_capture_file(TRUE);
1401 main_cf_cb_live_capture_fixed_started(capture_options *capture_opts)
1406 /* Enable menu items that make sense if you have some captured
1407 packets (yes, I know, we don't have any *yet*). */
1408 /*set_menus_for_captured_packets(TRUE);*/
1410 statusbar_pop_file_msg();
1412 capture_msg = g_strdup_printf(" %s: <live capture in progress> to file: %s",
1413 get_interface_descriptive_name(capture_opts->iface),
1414 (capture_opts->save_file) ? capture_opts->save_file : "");
1416 statusbar_push_file_msg(capture_msg);
1417 gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, " <capturing>");
1419 g_free(capture_msg);
1421 /* Don't set up main window for a capture file. */
1422 main_set_for_capture_file(FALSE);
1426 main_cf_cb_live_capture_fixed_finished(capture_file *cf _U_)
1428 /* Pop the "<live capture in progress>" message off the status bar. */
1429 statusbar_pop_file_msg();
1431 /* Pop the "<capturing>" message off the status bar */
1432 gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx);
1434 /*set_display_filename(cf);*/
1436 /* Enable menu items that make sense if you're not currently running
1438 set_menus_for_capture_in_progress(FALSE);
1440 /* We don't have loaded the capture file, this will be done later.
1441 * For now we still have simply a blank screen. */
1446 main_cf_cb_packet_selected(gpointer data)
1448 capture_file *cf = data;
1450 /* Display the GUI protocol tree and hex dump.
1451 XXX - why do we dump core if we call "proto_tree_draw()"
1452 before calling "add_byte_views()"? */
1453 add_main_byte_views(cf->edt);
1454 main_proto_tree_draw(cf->edt->tree);
1456 /* A packet is selected. */
1457 set_menus_for_selected_packet(cf);
1461 main_cf_cb_packet_unselected(capture_file *cf)
1463 /* Clear out the display of that packet. */
1464 clear_tree_and_hex_views();
1466 /* No packet is selected. */
1467 set_menus_for_selected_packet(cf);
1471 main_cf_cb_field_unselected(capture_file *cf)
1473 statusbar_pop_field_msg();
1474 set_menus_for_selected_tree_row(cf);
1478 main_cf_cb_file_safe_started(gchar * filename)
1480 const gchar *name_ptr;
1483 name_ptr = get_basename(filename);
1485 save_msg = g_strdup_printf(" Saving: %s...", name_ptr);
1487 statusbar_push_file_msg(save_msg);
1492 main_cf_cb_file_safe_finished(gpointer data _U_)
1494 /* Pop the "Saving:" message off the status bar. */
1495 statusbar_pop_file_msg();
1499 main_cf_cb_file_safe_failed(gpointer data _U_)
1501 /* Pop the "Saving:" message off the status bar. */
1502 statusbar_pop_file_msg();
1506 main_cf_cb_file_safe_reload_finished(gpointer data _U_)
1508 set_menus_for_unsaved_capture_file(FALSE);
1511 static void main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
1514 case(cf_cb_file_closed):
1515 main_cf_cb_file_closed(data);
1517 case(cf_cb_file_read_start):
1518 main_cf_cb_file_read_start(data);
1520 case(cf_cb_file_read_finished):
1521 main_cf_cb_file_read_finished(data);
1524 case(cf_cb_live_capture_prepared):
1525 main_cf_cb_live_capture_prepared(data);
1527 case(cf_cb_live_capture_update_started):
1528 main_cf_cb_live_capture_update_started(data);
1530 case(cf_cb_live_capture_update_continue):
1531 main_cf_cb_live_capture_update_continue(data);
1533 case(cf_cb_live_capture_fixed_started):
1534 main_cf_cb_live_capture_fixed_started(data);
1536 case(cf_cb_live_capture_update_finished):
1537 main_cf_cb_live_capture_update_finished(data);
1539 case(cf_cb_live_capture_fixed_finished):
1540 main_cf_cb_live_capture_fixed_finished(data);
1543 case(cf_cb_packet_selected):
1544 main_cf_cb_packet_selected(data);
1546 case(cf_cb_packet_unselected):
1547 main_cf_cb_packet_unselected(data);
1549 case(cf_cb_field_unselected):
1550 main_cf_cb_field_unselected(data);
1552 case(cf_cb_file_safe_started):
1553 main_cf_cb_file_safe_started(data);
1555 case(cf_cb_file_safe_finished):
1556 main_cf_cb_file_safe_finished(data);
1558 case(cf_cb_file_safe_reload_finished):
1559 main_cf_cb_file_safe_reload_finished(data);
1561 case(cf_cb_file_safe_failed):
1562 main_cf_cb_file_safe_failed(data);
1565 g_warning("main_cf_callback: event %u unknown", event);
1566 g_assert_not_reached();
1570 /* And now our feature presentation... [ fade to music ] */
1572 main(int argc, char *argv[])
1575 const char *command_name;
1580 extern char *optarg;
1581 gboolean arg_error = FALSE;
1589 char *gpf_path, *pf_path;
1590 char *cf_path, *df_path;
1591 char *gdp_path, *dp_path;
1592 int gpf_open_errno, gpf_read_errno;
1593 int pf_open_errno, pf_read_errno;
1594 int cf_open_errno, df_open_errno;
1595 int gdp_open_errno, gdp_read_errno;
1596 int dp_open_errno, dp_read_errno;
1599 gboolean start_capture = FALSE;
1602 GList *lt_list, *lt_entry;
1603 data_link_info_t *data_link_info;
1604 gchar err_str[PCAP_ERRBUF_SIZE];
1605 gchar *cant_get_if_list_errstr;
1606 gboolean stats_known;
1607 struct pcap_stat stats;
1609 gboolean capture_option_specified = FALSE;
1611 gint pl_size = 280, tv_size = 95, bv_size = 75;
1612 gchar *rc_file, *cf_name = NULL, *rfilter = NULL;
1613 dfilter_t *rfcode = NULL;
1614 gboolean rfilter_parse_failed = FALSE;
1617 GtkWidget *splash_win = NULL;
1618 gboolean capture_child; /* True if this is the child for "-S" */
1619 GLogLevelFlags log_flags;
1620 guint go_to_packet = 0;
1623 #define OPTSTRING_INIT "a:b:c:f:g:Hhi:klLm:nN:o:pQr:R:Ss:t:w:vy:z:"
1627 #define OPTSTRING_CHILD "W:Z:"
1628 #define OPTSTRING_WIN32 "B:"
1630 #define OPTSTRING_CHILD "W:"
1631 #define OPTSTRING_WIN32 ""
1634 #define OPTSTRING_CHILD ""
1635 #define OPTSTRING_WIN32 ""
1636 #endif /* HAVE_LIBPCAP */
1638 char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_CHILD) + sizeof(OPTSTRING_WIN32) - 2] =
1639 OPTSTRING_INIT OPTSTRING_WIN32;
1641 /* initialize memory allocation subsystem */
1644 /*** create the compile and runtime version strings ***/
1646 /* Load wpcap if possible. Do this before collecting the run-time version information */
1649 /* ... and also load the packet.dll from wpcap */
1650 wpcap_packet_load();
1652 /* Start windows sockets */
1653 WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
1656 /* Assemble the compile-time version information string */
1657 comp_info_str = g_string_new("Compiled ");
1658 g_string_append(comp_info_str, "with ");
1659 g_string_sprintfa(comp_info_str,
1660 #ifdef GTK_MAJOR_VERSION
1661 "GTK+ %d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION,
1664 "GTK+ (version unknown)");
1667 g_string_append(comp_info_str, ", ");
1668 get_compiled_version_info(comp_info_str);
1670 /* Assemble the run-time version information string */
1671 runtime_info_str = g_string_new("Running ");
1672 get_runtime_version_info(runtime_info_str);
1675 /*** "pre-scan" the command line parameters, if we have "console only" parameters ***/
1676 /* (e.g. don't start GTK+, if we only have to show the command line help) */
1677 optind_initial = optind;
1678 while ((opt = getopt(argc, argv, optstring)) != -1) {
1680 case 'h': /* Print help and exit */
1684 case 'v': /* Show version and exit */
1688 case 'G': /* dump various field or other infos, see handle_dashG_option() */
1689 /* If invoked with the "-G" flag, we dump out information based on
1690 the argument to the "-G" flag; if no argument is specified,
1691 for backwards compatibility we dump out a glossary of display
1694 We must do this before calling "gtk_init()", because "gtk_init()"
1695 tries to open an X display, and we don't want to have to do any X
1696 stuff just to do a build.
1698 Given that we call "gtk_init()" before doing the regular argument
1699 list processing, so that it can handle X and GTK+ arguments and
1700 remove them from the list at which we look, this means we must do
1701 this before doing the regular argument list processing, as well.
1705 you must give the "-G" flag as the first flag on the command line;
1707 you must give it as "-G", nothing more, nothing less;
1709 the first argument after the "-G" flag, if present, will be used
1710 to specify the information to dump;
1712 arguments after that will not be used. */
1713 handle_dashG_option(argc, argv, "ethereal");
1714 /* will never return! */
1720 /* set getopt index back to initial value, so it will start with the first command line parameter again */
1721 /* (XXX - this seems to be portable, but time will tell) */
1722 optind = optind_initial;
1725 /* Set the current locale according to the program environment.
1726 * We haven't localized anything, but some GTK widgets are localized
1727 * (the file selection dialogue, for example).
1728 * This also sets the C-language locale to the native environment. */
1731 /* Let GTK get its args (will need an X server, so do this after command line only commands handled) */
1732 gtk_init (&argc, &argv);
1734 cf_callback_add(main_cf_callback, NULL);
1736 #if GTK_MAJOR_VERSION < 2 && GTK_MINOR_VERSION < 3
1737 /* initialize our GTK eth_clist_type */
1738 init_eth_clist_type();
1741 ethereal_path = argv[0];
1743 /* Arrange that if we have no console window, and a GLib message logging
1744 routine is called to log a message, we pop up a console window.
1746 We do that by inserting our own handler for all messages logged
1747 to the default domain; that handler pops up a console if necessary,
1748 and then calls the default handler. */
1750 /* We might want to have component specific log levels later ... */
1752 /* the default_log_handler will use stdout, which makes trouble with the */
1753 /* capture child, as it uses stdout for it's sync_pipe */
1754 /* so do the filtering in the console_log_handler and not here */
1757 G_LOG_LEVEL_CRITICAL|
1758 G_LOG_LEVEL_WARNING|
1759 G_LOG_LEVEL_MESSAGE|
1762 G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION;
1764 g_log_set_handler(NULL,
1766 console_log_handler, NULL /* user_data */);
1769 g_log_set_handler(LOG_DOMAIN_CAPTURE,
1771 console_log_handler, NULL /* user_data */);
1772 g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
1774 console_log_handler, NULL /* user_data */);
1776 /* Set the initial values in the capture_opts. This might be overwritten
1777 by preference settings and then again by the command line parameters. */
1778 capture_opts_init(capture_opts, &cfile);
1780 capture_opts->snaplen = MIN_PACKET_SIZE;
1781 capture_opts->has_ring_num_files = TRUE;
1783 command_name = get_basename(ethereal_path);
1784 /* Set "capture_child" to indicate whether this is going to be a child
1785 process for a "-S" capture. */
1786 capture_child = (strcmp(command_name, CHILD_NAME) == 0);
1787 if (capture_child) {
1788 strcat(optstring, OPTSTRING_CHILD);
1792 /* We want a splash screen only if we're not a child process.
1793 We won't come till here, if we had a "console only" command line parameter. */
1797 splash_win = splash_new("Loading Ethereal ...");
1799 splash_update(splash_win, "Registering dissectors ...");
1801 /* Register all dissectors; we must do this before checking for the
1802 "-G" flag, as the "-G" flag dumps information registered by the
1803 dissectors, and we must do it before we read the preferences, in
1804 case any dissectors register preferences. */
1805 epan_init(PLUGIN_DIR,register_all_protocols,register_all_protocol_handoffs,
1806 failure_alert_box,open_failure_alert_box,read_failure_alert_box);
1808 splash_update(splash_win, "Registering tap listeners ...");
1810 /* Register all tap listeners; we do this before we parse the arguments,
1811 as the "-z" argument can specify a registered tap. */
1813 /* we register the plugin taps before the other taps because
1814 stats_tree taps plugins will be registered as tap listeners
1815 by stats_tree_stat.c and need to registered before that */
1818 register_all_plugin_tap_listeners();
1821 register_all_tap_listeners();
1823 splash_update(splash_win, "Loading module preferences ...");
1825 /* Now register the preferences for any non-dissector modules.
1826 We must do that before we read the preferences as well. */
1827 prefs_register_modules();
1829 /* multithread support currently doesn't seem to work in win32 gtk2.0.6 */
1830 #if !defined(_WIN32) && GTK_MAJOR_VERSION >= 2 && defined(G_THREADS_ENABLED) && defined USE_THREADS
1833 g_thread_init(NULL);
1835 ut=g_thread_create(update_thread, NULL, FALSE, NULL);
1836 g_thread_set_priority(ut, G_THREAD_PRIORITY_LOW);
1838 #else /* _WIN32 || GTK1.2 || !G_THREADS_ENABLED || !USE_THREADS */
1839 /* this is to keep tap extensions updating once every 3 seconds */
1840 gtk_timeout_add(3000, (GtkFunction)update_cb,(gpointer)NULL);
1841 #endif /* !_WIN32 && GTK2 && G_THREADS_ENABLED */
1844 gtk_timeout_add(750, (GtkFunction) host_name_lookup_process, NULL);
1847 splash_update(splash_win, "Loading configuration files ...");
1849 /* Read the preference files. */
1850 prefs = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
1851 &pf_open_errno, &pf_read_errno, &pf_path);
1852 if (gpf_path != NULL) {
1853 if (gpf_open_errno != 0) {
1854 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1855 "Could not open global preferences file\n\"%s\": %s.", gpf_path,
1856 strerror(gpf_open_errno));
1858 if (gpf_read_errno != 0) {
1859 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1860 "I/O error reading global preferences file\n\"%s\": %s.", gpf_path,
1861 strerror(gpf_read_errno));
1864 if (pf_path != NULL) {
1865 if (pf_open_errno != 0) {
1866 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1867 "Could not open your preferences file\n\"%s\": %s.", pf_path,
1868 strerror(pf_open_errno));
1870 if (pf_read_errno != 0) {
1871 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1872 "I/O error reading your preferences file\n\"%s\": %s.", pf_path,
1873 strerror(pf_read_errno));
1880 /* if the user wants a console to be always there, well, we should open one for him */
1881 if (prefs->gui_console_open == console_open_always) {
1887 /* If this is a capture child process, it should pay no attention
1888 to the "prefs.capture_prom_mode" setting in the preferences file;
1889 it should do what the parent process tells it to do, and if
1890 the parent process wants it not to run in promiscuous mode, it'll
1891 tell it so with a "-p" flag.
1893 Otherwise, set promiscuous mode from the preferences setting. */
1894 /* the same applies to other preferences settings as well. */
1895 if (capture_child) {
1896 auto_scroll_live = FALSE;
1898 capture_opts->promisc_mode = prefs->capture_prom_mode;
1899 capture_opts->show_info = prefs->capture_show_info;
1900 capture_opts->real_time_mode = prefs->capture_real_time;
1901 auto_scroll_live = prefs->capture_auto_scroll;
1904 #endif /* HAVE_LIBPCAP */
1906 /* Set the name resolution code's flags from the preferences. */
1907 g_resolv_flags = prefs->name_resolve;
1909 /* Read the capture filter file. */
1910 read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
1911 if (cf_path != NULL) {
1912 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1913 "Could not open your capture filter file\n\"%s\": %s.", cf_path,
1914 strerror(cf_open_errno));
1918 /* Read the display filter file. */
1919 read_filter_list(DFILTER_LIST, &df_path, &df_open_errno);
1920 if (df_path != NULL) {
1921 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1922 "Could not open your display filter file\n\"%s\": %s.", df_path,
1923 strerror(df_open_errno));
1927 /* Read the disabled protocols file. */
1928 read_disabled_protos_list(&gdp_path, &gdp_open_errno, &gdp_read_errno,
1929 &dp_path, &dp_open_errno, &dp_read_errno);
1930 if (gdp_path != NULL) {
1931 if (gdp_open_errno != 0) {
1932 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1933 "Could not open global disabled protocols file\n\"%s\": %s.",
1934 gdp_path, strerror(gdp_open_errno));
1936 if (gdp_read_errno != 0) {
1937 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1938 "I/O error reading global disabled protocols file\n\"%s\": %s.",
1939 gdp_path, strerror(gdp_read_errno));
1943 if (dp_path != NULL) {
1944 if (dp_open_errno != 0) {
1945 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1946 "Could not open your disabled protocols file\n\"%s\": %s.", dp_path,
1947 strerror(dp_open_errno));
1949 if (dp_read_errno != 0) {
1950 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
1951 "I/O error reading your disabled protocols file\n\"%s\": %s.", dp_path,
1952 strerror(dp_read_errno));
1957 /* Read the (static part) of the recent file. Only the static part of it will be read, */
1958 /* as we don't have the gui now to fill the recent lists which is done in the dynamic part. */
1959 /* We have to do this already here, so command line parameters can overwrite these values. */
1960 recent_read_static(&rf_path, &rf_open_errno);
1962 init_cap_file(&cfile);
1964 /* Now get our args */
1965 while ((opt = getopt(argc, argv, optstring)) != -1) {
1967 /*** capture option specific ***/
1968 case 'a': /* autostop criteria */
1969 case 'b': /* Ringbuffer option */
1970 case 'c': /* Capture xxx packets */
1971 case 'f': /* capture filter */
1972 case 'k': /* Start capture immediately */
1973 case 'H': /* Hide capture info dialog box */
1974 case 'i': /* Use interface xxx */
1975 case 'p': /* Don't capture in promiscuous mode */
1976 case 'Q': /* Quit after capture (just capture to file) */
1977 case 's': /* Set the snapshot (capture) length */
1978 case 'S': /* "Sync" mode: used for following file ala tail -f */
1979 case 'w': /* Write to capture file xxx */
1980 case 'y': /* Set the pcap data link type */
1982 case 'B': /* Buffer size */
1983 /* Hidden option supporting Sync mode */
1984 case 'Z': /* Write to pipe FD XXX */
1987 capture_opts_add_opt(capture_opts, "ethereal", opt, optarg, &start_capture);
1989 capture_option_specified = TRUE;
1994 /* This is a hidden option supporting Sync mode, so we don't set
1995 * the error flags for the user in the non-libpcap case.
1997 case 'W': /* Write to capture file FD xxx */
1998 capture_opts_add_opt(capture_opts, "ethereal", opt, optarg, &start_capture);
2002 /*** all non capture option specific ***/
2003 case 'g': /* Go to packet */
2004 go_to_packet = get_positive_int("Ethereal", optarg, "go to packet");
2006 case 'l': /* Automatic scrolling in live capture mode */
2008 auto_scroll_live = TRUE;
2010 capture_option_specified = TRUE;
2014 case 'L': /* Print list of link-layer types and exit */
2016 list_link_layer_types = TRUE;
2018 capture_option_specified = TRUE;
2022 case 'm': /* Fixed-width font for the display */
2023 if (prefs->PREFS_GUI_FONT_NAME != NULL)
2024 g_free(prefs->PREFS_GUI_FONT_NAME);
2025 prefs->PREFS_GUI_FONT_NAME = g_strdup(optarg);
2027 case 'n': /* No name resolution */
2028 g_resolv_flags = RESOLV_NONE;
2030 case 'N': /* Select what types of addresses/port #s to resolve */
2031 if (g_resolv_flags == RESOLV_ALL)
2032 g_resolv_flags = RESOLV_NONE;
2033 badopt = string_to_name_resolve(optarg, &g_resolv_flags);
2034 if (badopt != '\0') {
2035 fprintf(stderr, "ethereal: -N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'\n",
2040 case 'o': /* Override preference from command line */
2041 switch (prefs_set_pref(optarg)) {
2044 case PREFS_SET_SYNTAX_ERR:
2045 fprintf(stderr, "ethereal: Invalid -o flag \"%s\"\n", optarg);
2048 case PREFS_SET_NO_SUCH_PREF:
2049 /* not a preference, might be a recent setting */
2050 switch (recent_set_arg(optarg)) {
2053 case PREFS_SET_SYNTAX_ERR:
2054 /* shouldn't happen, checked already above */
2055 fprintf(stderr, "ethereal: Invalid -o flag \"%s\"\n", optarg);
2058 case PREFS_SET_NO_SUCH_PREF:
2059 case PREFS_SET_OBSOLETE:
2060 fprintf(stderr, "ethereal: -o flag \"%s\" specifies unknown preference/recent value\n",
2065 g_assert_not_reached();
2068 case PREFS_SET_OBSOLETE:
2069 fprintf(stderr, "ethereal: -o flag \"%s\" specifies obsolete preference\n",
2074 g_assert_not_reached();
2077 case 'r': /* Read capture file xxx */
2078 /* We may set "last_open_dir" to "cf_name", and if we change
2079 "last_open_dir" later, we free the old value, so we have to
2080 set "cf_name" to something that's been allocated. */
2081 cf_name = g_strdup(optarg);
2083 case 'R': /* Read file filter */
2086 case 't': /* Time stamp type */
2087 if (strcmp(optarg, "r") == 0)
2088 set_timestamp_setting(TS_RELATIVE);
2089 else if (strcmp(optarg, "a") == 0)
2090 set_timestamp_setting(TS_ABSOLUTE);
2091 else if (strcmp(optarg, "ad") == 0)
2092 set_timestamp_setting(TS_ABSOLUTE_WITH_DATE);
2093 else if (strcmp(optarg, "d") == 0)
2094 set_timestamp_setting(TS_DELTA);
2096 fprintf(stderr, "ethereal: Invalid time stamp type \"%s\"\n",
2098 fprintf(stderr, "It must be \"r\" for relative, \"a\" for absolute,\n");
2099 fprintf(stderr, "\"ad\" for absolute with date, or \"d\" for delta.\n");
2104 /* We won't call the init function for the tap this soon
2105 as it would disallow MATE's fields (which are registered
2106 by the preferences set callback) from being used as
2107 part of a tap filter. Instead, we just add the argument
2108 to a list of tap arguments. */
2109 if (!process_tap_cmd_arg(optarg)) {
2110 fprintf(stderr,"ethereal: invalid -z argument.\n");
2111 fprintf(stderr," -z argument must be one of :\n");
2112 list_tap_cmd_args();
2117 case '?': /* Bad flag - print usage message */
2125 if (cf_name != NULL) {
2127 * Input file name specified with "-r" *and* specified as a regular
2128 * command-line argument.
2133 * Input file name not specified with "-r", and a command-line argument
2134 * was specified; treat it as the input file name.
2136 * Yes, this is different from tethereal, where non-flag command-line
2137 * arguments are a filter, but this works better on GUI desktops
2138 * where a command can be specified to be run to open a particular
2139 * file - yes, you could have "-r" as the last part of the command,
2140 * but that's a bit ugly.
2142 cf_name = g_strdup(argv[0]);
2152 * Extra command line arguments were specified; complain.
2154 fprintf(stderr, "Invalid argument: %s\n", argv[0]);
2159 #ifndef HAVE_LIBPCAP
2160 if (capture_option_specified) {
2161 fprintf(stderr, "This version of Ethereal was not built with support for capturing packets.\n");
2169 if (start_capture && list_link_layer_types) {
2170 /* Specifying *both* is bogus. */
2171 fprintf(stderr, "ethereal: You can't specify both -L and a live capture.\n");
2175 if (list_link_layer_types) {
2176 /* We're supposed to list the link-layer types for an interface;
2177 did the user also specify a capture file to be read? */
2179 /* Yes - that's bogus. */
2180 fprintf(stderr, "ethereal: You can't specify -L and a capture file to be read.\n");
2183 /* No - did they specify a ring buffer option? */
2184 if (capture_opts->multi_files_on) {
2185 fprintf(stderr, "ethereal: Ring buffer requested, but a capture isn't being done.\n");
2189 /* We're supposed to do a live capture; did the user also specify
2190 a capture file to be read? */
2191 if (start_capture && cf_name) {
2192 /* Yes - that's bogus. */
2193 fprintf(stderr, "ethereal: You can't specify both a live capture and a capture file to be read.\n");
2197 /* No - was the ring buffer option specified and, if so, does it make
2199 if (capture_opts->multi_files_on) {
2200 /* Ring buffer works only under certain conditions:
2201 a) ring buffer does not work with temporary files;
2202 b) real_time_mode and multi_files_on are mutually exclusive -
2203 real_time_mode takes precedence;
2204 c) it makes no sense to enable the ring buffer if the maximum
2205 file size is set to "infinite". */
2206 if (capture_opts->save_file == NULL) {
2207 fprintf(stderr, "ethereal: Ring buffer requested, but capture isn't being saved to a permanent file.\n");
2208 capture_opts->multi_files_on = FALSE;
2210 /* if (capture_opts->real_time_mode) {
2211 fprintf(stderr, "ethereal: Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.\n");
2212 capture_opts->multi_files_on = FALSE;
2214 if (!capture_opts->has_autostop_filesize && !capture_opts->has_file_duration) {
2215 fprintf(stderr, "ethereal: Ring buffer requested, but no maximum capture file size or duration were specified.\n");
2216 /* XXX - this must be redesigned as the conditions changed */
2217 /* capture_opts->multi_files_on = FALSE;*/
2222 if (start_capture || list_link_layer_types) {
2223 /* Did the user specify an interface to use? */
2224 if (capture_opts->iface == NULL) {
2225 /* No - is a default specified in the preferences file? */
2226 if (prefs->capture_device != NULL) {
2228 capture_opts->iface = g_strdup(prefs->capture_device);
2230 /* No - pick the first one from the list of interfaces. */
2231 if_list = get_interface_list(&err, err_str);
2232 if (if_list == NULL) {
2235 case CANT_GET_INTERFACE_LIST:
2236 cant_get_if_list_errstr = cant_get_if_list_error_message(err_str);
2237 fprintf(stderr, "%s\n", cant_get_if_list_errstr);
2238 g_free(cant_get_if_list_errstr);
2241 case NO_INTERFACES_FOUND:
2242 fprintf(stderr, "ethereal: There are no interfaces on which a capture can be done\n");
2247 if_info = if_list->data; /* first interface */
2248 capture_opts->iface = g_strdup(if_info->name);
2249 free_interface_list(if_list);
2254 if (list_link_layer_types) {
2255 /* Get the list of link-layer types for the capture device. */
2256 lt_list = get_pcap_linktype_list(capture_opts->iface, err_str);
2257 if (lt_list == NULL) {
2258 if (err_str[0] != '\0') {
2259 fprintf(stderr, "ethereal: The list of data link types for the capture device could not be obtained (%s).\n"
2260 "Please check to make sure you have sufficient permissions, and that\n"
2261 "you have the proper interface or pipe specified.\n", err_str);
2263 fprintf(stderr, "ethereal: The capture device has no data link types.\n");
2266 fprintf(stderr, "Data link types (use option -y to set):\n");
2267 for (lt_entry = lt_list; lt_entry != NULL;
2268 lt_entry = g_list_next(lt_entry)) {
2269 data_link_info = lt_entry->data;
2270 fprintf(stderr, " %s", data_link_info->name);
2271 if (data_link_info->description != NULL)
2272 fprintf(stderr, " (%s)", data_link_info->description);
2274 fprintf(stderr, " (not supported)");
2277 free_pcap_linktype_list(lt_list);
2281 if (capture_opts->has_snaplen) {
2282 if (capture_opts->snaplen < 1)
2283 capture_opts->snaplen = WTAP_MAX_PACKET_SIZE;
2284 else if (capture_opts->snaplen < MIN_PACKET_SIZE)
2285 capture_opts->snaplen = MIN_PACKET_SIZE;
2288 /* Check the value range of the ringbuffer_num_files parameter */
2289 if (capture_opts->ring_num_files > RINGBUFFER_MAX_NUM_FILES)
2290 capture_opts->ring_num_files = RINGBUFFER_MAX_NUM_FILES;
2291 #if RINGBUFFER_MIN_NUM_FILES > 0
2292 else if (capture_opts->num_files < RINGBUFFER_MIN_NUM_FILES)
2293 capture_opts->ring_num_files = RINGBUFFER_MIN_NUM_FILES;
2295 #endif /* HAVE_LIBPCAP */
2297 /* Notify all registered modules that have had any of their preferences
2298 changed either from one of the preferences file or from the command
2299 line that their preferences have changed. */
2302 /* disabled protocols as per configuration file */
2303 if (gdp_path == NULL && dp_path == NULL) {
2304 set_disabled_protos_list();
2307 /* Build the column format array */
2308 col_setup(&cfile.cinfo, prefs->num_cols);
2309 for (i = 0; i < cfile.cinfo.num_cols; i++) {
2310 cfile.cinfo.col_fmt[i] = get_column_format(i);
2311 cfile.cinfo.col_title[i] = g_strdup(get_column_title(i));
2312 cfile.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
2314 get_column_format_matches(cfile.cinfo.fmt_matx[i], cfile.cinfo.col_fmt[i]);
2315 cfile.cinfo.col_data[i] = NULL;
2316 if (cfile.cinfo.col_fmt[i] == COL_INFO)
2317 cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
2319 cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2320 cfile.cinfo.col_fence[i] = 0;
2321 cfile.cinfo.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2322 cfile.cinfo.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
2325 for (i = 0; i < cfile.cinfo.num_cols; i++) {
2328 for (j = 0; j < NUM_COL_FMTS; j++) {
2329 if (!cfile.cinfo.fmt_matx[i][j])
2332 if (cfile.cinfo.col_first[j] == -1)
2333 cfile.cinfo.col_first[j] = i;
2334 cfile.cinfo.col_last[j] = i;
2338 /* read in rc file from global and personal configuration paths. */
2339 rc_file = get_datafile_path(RC_FILE);
2340 gtk_rc_parse(rc_file);
2341 rc_file = get_persconffile_path(RC_FILE, FALSE);
2342 gtk_rc_parse(rc_file);
2345 font_init(capture_child);
2350 /* close the splash screen, as we are going to open the main window now */
2351 splash_destroy(splash_win);
2355 /* Is this a "child" ethereal, which is only supposed to pop up a
2356 capture box to let us stop the capture, and run a capture
2357 to a file that our parent will read? */
2358 if (capture_child) {
2359 /* This is the child process of a capture session,
2360 so just do the low-level work of a capture - don't create
2361 a temporary file and fork off *another* child process (so don't
2362 call "capture_start()"). */
2364 /* Pop up any queued-up alert boxes. */
2365 display_queued_messages();
2367 /* Now start the capture.
2368 After the capture is done; there's nothing more for us to do. */
2370 /* XXX - hand these stats to the parent process */
2371 if(capture_loop_start(capture_opts, &stats_known, &stats) == TRUE) {
2375 /* capture failed */
2381 /***********************************************************************/
2382 /* Everything is prepared now, preferences and command line was read in,
2383 we are NOT a child window for a synced capture. */
2385 /* Pop up the main window. */
2386 create_main_window(pl_size, tv_size, bv_size, prefs);
2388 /* Read the dynamic part of the recent file, as we have the gui now ready for it. */
2389 recent_read_dynamic(&rf_path, &rf_open_errno);
2390 color_filters_enable(recent.packet_list_colorize);
2392 /* rearrange all the widgets as we now have all recent settings ready for this */
2393 main_widgets_rearrange();
2395 /* Fill in column titles. This must be done after the top level window
2398 XXX - is that still true, with fixed-width columns? */
2399 packet_list_set_column_titles();
2401 menu_recent_read_finished();
2403 switch (user_font_apply()) {
2406 case FA_FONT_NOT_RESIZEABLE:
2407 /* "user_font_apply()" popped up an alert box. */
2408 /* turn off zooming - font can't be resized */
2409 case FA_FONT_NOT_AVAILABLE:
2410 /* XXX - did we successfully load the un-zoomed version earlier?
2411 If so, this *probably* means the font is available, but not at
2412 this particular zoom level, but perhaps some other failure
2413 occurred; I'm not sure you can determine which is the case,
2415 /* turn off zooming - zoom level is unavailable */
2417 /* in any other case than FA_SUCCESS, turn off zooming */
2418 recent.gui_zoom_level = 0;
2419 /* XXX: would it be a good idea to disable zooming (insensitive GUI)? */
2422 dnd_init(top_level);
2425 color_filters_init();
2428 /* the window can be sized only, if it's not already shown, so do it now! */
2429 main_load_window_geometry(top_level);
2431 /* If we were given the name of a capture file, read it in now;
2432 we defer it until now, so that, if we can't open it, and pop
2433 up an alert box, the alert box is more likely to come up on
2434 top of the main window - but before the preference-file-error
2435 alert box, so, if we get one of those, it's more likely to come
2438 show_main_window(TRUE);
2439 if (rfilter != NULL) {
2440 if (!dfilter_compile(rfilter, &rfcode)) {
2441 bad_dfilter_alert_box(rfilter);
2442 rfilter_parse_failed = TRUE;
2445 if (!rfilter_parse_failed) {
2446 if (cf_open(&cfile, cf_name, FALSE, &err) == CF_OK) {
2447 /* "cf_open()" succeeded, so it closed the previous
2448 capture file, and thus destroyed any previous read filter
2449 attached to "cf". */
2451 cfile.rfcode = rfcode;
2452 /* Open tap windows; we do so after creating the main window,
2453 to avoid GTK warnings, and after successfully opening the
2454 capture file, so we know we have something to tap, and
2455 after registering all dissectors, so that MATE will have
2456 registered its field array and we can have a filter with
2457 one of MATE's late-registered fields as part of the tap's
2459 start_requested_taps();
2461 /* Read the capture file. */
2462 switch (cf_read(&cfile)) {
2466 /* Just because we got an error, that doesn't mean we were unable
2467 to read any of the file; we handle what we could get from the
2469 /* if the user told us to jump to a specific packet, do it now */
2470 if(go_to_packet != 0) {
2471 cf_goto_frame(&cfile, go_to_packet);
2475 case CF_READ_ABORTED:
2480 /* Save the name of the containing directory specified in the
2481 path name, if any; we can write over cf_name, which is a
2482 good thing, given that "get_dirname()" does write over its
2484 s = get_dirname(cf_name);
2485 /* we might already set this from the recent file, don't overwrite this */
2486 if(get_last_open_dir() == NULL)
2487 set_last_open_dir(s);
2492 dfilter_free(rfcode);
2493 cfile.rfcode = NULL;
2494 set_menus_for_capture_in_progress(FALSE);
2499 if (start_capture) {
2500 if (capture_opts->save_file != NULL) {
2501 /* Save the directory name for future file dialogs. */
2502 /* (get_dirname overwrites filename) */
2503 s = get_dirname(g_strdup(capture_opts->save_file));
2504 set_last_open_dir(s);
2507 /* "-k" was specified; start a capture. */
2508 show_main_window(TRUE);
2509 if (capture_start(capture_opts)) {
2510 /* The capture started. Open tap windows; we do so after creating
2511 the main window, to avoid GTK warnings, and after successfully
2512 opening the capture file, so we know we have something to tap,
2513 and after registering all dissectors, so that MATE will have
2514 registered its field array and we can have a filter with
2515 one of MATE's late-registered fields as part of the tap's
2517 start_requested_taps();
2521 show_main_window(FALSE);
2522 set_menus_for_capture_in_progress(FALSE);
2525 /* if the user didn't supplied a capture filter, use the one to filter out remote connections like SSH */
2526 if (!start_capture && (capture_opts->cfilter == NULL || strlen(capture_opts->cfilter) == 0)) {
2527 if (capture_opts->cfilter) {
2528 g_free(capture_opts->cfilter);
2530 capture_opts->cfilter = g_strdup(get_conn_cfilter());
2532 #else /* HAVE_LIBPCAP */
2533 show_main_window(FALSE);
2534 set_menus_for_capture_in_progress(FALSE);
2535 #endif /* HAVE_LIBPCAP */
2544 /* hide the (unresponsive) main window, while asking the user to close the console window */
2545 gtk_widget_hide(top_level);
2547 /* Shutdown windows sockets */
2550 /* For some unknown reason, the "atexit()" call in "create_console()"
2551 doesn't arrange that "destroy_console()" be called when we exit,
2552 so we call it here if a console was created. */
2558 /* This isn't reached, but we need it to keep GCC from complaining
2559 that "main()" returns without returning a value - it knows that
2560 "exit()" never returns, but it doesn't know that "gtk_exit()"
2561 doesn't, as GTK+ doesn't declare it with the attribute
2563 return 0; /* not reached */
2568 /* We build this as a GUI subsystem application on Win32, so
2569 "WinMain()", not "main()", gets called.
2571 Hack shamelessly stolen from the Win32 port of the GIMP. */
2573 #define _stdcall __attribute__((stdcall))
2577 WinMain (struct HINSTANCE__ *hInstance,
2578 struct HINSTANCE__ *hPrevInstance,
2582 has_console = FALSE;
2583 return main (__argc, __argv);
2587 * If this application has no console window to which its standard output
2588 * would go, create one.
2591 create_console(void)
2594 /* We have no console to which to print the version string, so
2595 create one and make it the standard input, output, and error. */
2596 if (!AllocConsole())
2597 return; /* couldn't create console */
2598 freopen("CONIN$", "r", stdin);
2599 freopen("CONOUT$", "w", stdout);
2600 freopen("CONOUT$", "w", stderr);
2602 /* Well, we have a console now. */
2605 /* Now register "destroy_console()" as a routine to be called just
2606 before the application exits, so that we can destroy the console
2607 after the user has typed a key (so that the console doesn't just
2608 disappear out from under them, giving the user no chance to see
2609 the message(s) we put in there). */
2610 atexit(destroy_console);
2615 destroy_console(void)
2618 printf("\n\nPress any key to exit\n");
2626 /* This routine should not be necessary, at least as I read the GLib
2627 source code, as it looks as if GLib is, on Win32, *supposed* to
2628 create a console window into which to display its output.
2630 That doesn't happen, however. I suspect there's something completely
2631 broken about that code in GLib-for-Win32, and that it may be related
2632 to the breakage that forces us to just call "printf()" on the message
2633 rather than passing the message on to "g_log_default_handler()"
2634 (which is the routine that does the aforementioned non-functional
2635 console window creation). */
2637 console_log_handler(const char *log_domain, GLogLevelFlags log_level,
2638 const char *message, gpointer user_data _U_)
2645 /* change this, if you want to see more verbose log output */
2646 /* XXX - make this a pref value */
2647 if( (log_level & G_LOG_LEVEL_MASK) > G_LOG_LEVEL_WARNING) {
2651 /* create a "timestamp" */
2653 today = localtime(&curr);
2656 if (prefs.gui_console_open != console_open_never) {
2660 /* For some unknown reason, the above doesn't appear to actually cause
2661 anything to be sent to the standard output, so we'll just splat the
2662 message out directly, just to make sure it gets out. */
2664 switch(log_level & G_LOG_LEVEL_MASK) {
2665 case G_LOG_LEVEL_ERROR:
2668 case G_LOG_LEVEL_CRITICAL:
2671 case G_LOG_LEVEL_WARNING:
2674 case G_LOG_LEVEL_MESSAGE:
2677 case G_LOG_LEVEL_INFO:
2680 case G_LOG_LEVEL_DEBUG:
2684 fprintf(stderr, "unknown log_level %u\n", log_level);
2686 g_assert_not_reached();
2689 /* don't use printf (stdout), as the capture child uses stdout for it's sync_pipe */
2690 fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
2691 today->tm_hour, today->tm_min, today->tm_sec,
2692 log_domain != NULL ? log_domain : "",
2696 g_log_default_handler(log_domain, log_level, message, user_data);
2702 static GtkWidget *info_bar_new(void)
2704 /* tip: tooltips don't work on statusbars! */
2705 info_bar = gtk_statusbar_new();
2706 main_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "main");
2707 file_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "file");
2708 help_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "help");
2709 #if GTK_MAJOR_VERSION >= 2
2710 gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(info_bar), FALSE);
2712 gtk_statusbar_push(GTK_STATUSBAR(info_bar), main_ctx, DEF_READY_MESSAGE);
2717 static GtkWidget *packets_bar_new(void)
2719 /* tip: tooltips don't work on statusbars! */
2720 packets_bar = gtk_statusbar_new();
2721 packets_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(packets_bar), "packets");
2722 packets_bar_update();
2729 * Helper for main_widgets_rearrange()
2731 static void foreach_remove_a_child(GtkWidget *widget, gpointer data) {
2732 gtk_container_remove(GTK_CONTAINER(data), widget);
2735 static GtkWidget *main_widget_layout(gint layout_content)
2737 switch(layout_content) {
2738 case(layout_pane_content_none):
2741 case(layout_pane_content_plist):
2744 case(layout_pane_content_pdetails):
2747 case(layout_pane_content_pbytes):
2751 g_assert_not_reached();
2758 * Rearrange the main window widgets
2760 void main_widgets_rearrange(void) {
2761 GtkWidget *first_pane_widget1, *first_pane_widget2;
2762 GtkWidget *second_pane_widget1, *second_pane_widget2;
2763 gboolean split_top_left;
2765 /* be a bit faster */
2766 gtk_widget_hide(main_vbox);
2768 /* be sure, we don't loose a widget while rearranging */
2769 gtk_widget_ref(menubar);
2770 gtk_widget_ref(main_tb);
2771 gtk_widget_ref(filter_tb);
2772 gtk_widget_ref(pkt_scrollw);
2773 gtk_widget_ref(tv_scrollw);
2774 gtk_widget_ref(byte_nb_ptr);
2775 gtk_widget_ref(stat_hbox);
2776 gtk_widget_ref(info_bar);
2777 gtk_widget_ref(packets_bar);
2778 gtk_widget_ref(status_pane);
2779 gtk_widget_ref(main_pane_v1);
2780 gtk_widget_ref(main_pane_v2);
2781 gtk_widget_ref(main_pane_h1);
2782 gtk_widget_ref(main_pane_h2);
2783 gtk_widget_ref(welcome_pane);
2785 /* empty all containers participating */
2786 gtk_container_foreach(GTK_CONTAINER(main_vbox), foreach_remove_a_child, main_vbox);
2787 gtk_container_foreach(GTK_CONTAINER(stat_hbox), foreach_remove_a_child, stat_hbox);
2788 gtk_container_foreach(GTK_CONTAINER(status_pane), foreach_remove_a_child, status_pane);
2789 gtk_container_foreach(GTK_CONTAINER(main_pane_v1), foreach_remove_a_child, main_pane_v1);
2790 gtk_container_foreach(GTK_CONTAINER(main_pane_v2), foreach_remove_a_child, main_pane_v2);
2791 gtk_container_foreach(GTK_CONTAINER(main_pane_h1), foreach_remove_a_child, main_pane_h1);
2792 gtk_container_foreach(GTK_CONTAINER(main_pane_h2), foreach_remove_a_child, main_pane_h2);
2794 /* add the menubar always at the top */
2795 gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
2798 gtk_box_pack_start(GTK_BOX(main_vbox), main_tb, FALSE, TRUE, 0);
2800 /* filter toolbar in toolbar area */
2801 if (!prefs.filter_toolbar_show_in_statusbar) {
2802 gtk_box_pack_start(GTK_BOX(main_vbox), filter_tb, FALSE, TRUE, 1);
2805 /* fill the main layout panes */
2806 switch(prefs.gui_layout_type) {
2807 case(layout_type_5):
2808 main_first_pane = main_pane_v1;
2809 main_second_pane = main_pane_v2;
2810 split_top_left = FALSE;
2812 case(layout_type_2):
2813 main_first_pane = main_pane_v1;
2814 main_second_pane = main_pane_h1;
2815 split_top_left = FALSE;
2817 case(layout_type_1):
2818 main_first_pane = main_pane_v1;
2819 main_second_pane = main_pane_h1;
2820 split_top_left = TRUE;
2822 case(layout_type_4):
2823 main_first_pane = main_pane_h1;
2824 main_second_pane = main_pane_v1;
2825 split_top_left = FALSE;
2827 case(layout_type_3):
2828 main_first_pane = main_pane_h1;
2829 main_second_pane = main_pane_v1;
2830 split_top_left = TRUE;
2832 case(layout_type_6):
2833 main_first_pane = main_pane_h1;
2834 main_second_pane = main_pane_h2;
2835 split_top_left = FALSE;
2838 main_first_pane = NULL;
2839 main_second_pane = NULL;
2840 split_top_left = FALSE;
2841 g_assert_not_reached();
2843 if (split_top_left) {
2844 first_pane_widget1 = main_second_pane;
2845 second_pane_widget1 = main_widget_layout(prefs.gui_layout_content_1);
2846 second_pane_widget2 = main_widget_layout(prefs.gui_layout_content_2);
2847 first_pane_widget2 = main_widget_layout(prefs.gui_layout_content_3);
2849 first_pane_widget1 = main_widget_layout(prefs.gui_layout_content_1);
2850 first_pane_widget2 = main_second_pane;
2851 second_pane_widget1 = main_widget_layout(prefs.gui_layout_content_2);
2852 second_pane_widget2 = main_widget_layout(prefs.gui_layout_content_3);
2854 if (first_pane_widget1 != NULL)
2855 gtk_paned_add1(GTK_PANED(main_first_pane), first_pane_widget1);
2856 if (first_pane_widget2 != NULL)
2857 gtk_paned_add2(GTK_PANED(main_first_pane), first_pane_widget2);
2858 if (second_pane_widget1 != NULL)
2859 gtk_paned_pack1(GTK_PANED(main_second_pane), second_pane_widget1, TRUE, TRUE);
2860 if (second_pane_widget2 != NULL)
2861 gtk_paned_pack2(GTK_PANED(main_second_pane), second_pane_widget2, FALSE, FALSE);
2863 gtk_container_add(GTK_CONTAINER(main_vbox), main_first_pane);
2866 gtk_box_pack_start(GTK_BOX(main_vbox), welcome_pane, TRUE, TRUE, 0);
2868 /* statusbar hbox */
2869 gtk_box_pack_start(GTK_BOX(main_vbox), stat_hbox, FALSE, TRUE, 0);
2871 /* filter toolbar in statusbar hbox */
2872 if (prefs.filter_toolbar_show_in_statusbar) {
2873 gtk_box_pack_start(GTK_BOX(stat_hbox), filter_tb, FALSE, TRUE, 1);
2877 gtk_box_pack_start(GTK_BOX(stat_hbox), status_pane, TRUE, TRUE, 0);
2878 gtk_paned_pack1(GTK_PANED(status_pane), info_bar, FALSE, FALSE);
2879 gtk_paned_pack2(GTK_PANED(status_pane), packets_bar, FALSE, FALSE);
2881 /* hide widgets on users recent settings */
2882 main_widgets_show_or_hide();
2884 gtk_widget_show(main_vbox);
2888 is_widget_visible(GtkWidget *widget, gpointer data)
2890 gboolean *is_visible = data;
2893 if (GTK_WIDGET_VISIBLE(widget))
2900 /* XXX - There seems to be some disagreement about if and how this feature should be implemented.
2901 As I currently don't have the time to continue this, it's temporarily disabled. - ULFL */
2903 welcome_item(gchar *stock_item, gchar * label, gchar * message, GtkSignalFunc callback, void *callback_data)
2905 GtkWidget *w, *item_hb;
2906 #if GTK_MAJOR_VERSION >= 2
2907 gchar *formatted_message;
2911 item_hb = gtk_hbox_new(FALSE, 1);
2913 w = BUTTON_NEW_FROM_STOCK(stock_item);
2914 WIDGET_SET_SIZE(w, 60, 60);
2915 #if GTK_MAJOR_VERSION >= 2
2916 gtk_button_set_label(GTK_BUTTON(w), label);
2918 gtk_box_pack_start(GTK_BOX(item_hb), w, FALSE, FALSE, 0);
2919 SIGNAL_CONNECT(w, "clicked", callback, callback_data);
2921 w = gtk_label_new(message);
2922 gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.5);
2923 #if GTK_MAJOR_VERSION >= 2
2924 formatted_message = g_strdup_printf("<span weight=\"bold\" size=\"x-large\">%s</span>", message);
2925 gtk_label_set_markup(GTK_LABEL(w), formatted_message);
2926 g_free(formatted_message);
2929 gtk_box_pack_start(GTK_BOX(item_hb), w, FALSE, FALSE, 10);
2935 /* XXX - the layout has to be improved */
2939 GtkWidget *welcome_scrollw, *welcome_hb, *welcome_vb, *item_hb;
2940 GtkWidget *w, *icon;
2944 welcome_scrollw = scrolled_window_new(NULL, NULL);
2946 welcome_hb = gtk_hbox_new(FALSE, 1);
2947 /*gtk_container_border_width(GTK_CONTAINER(welcome_hb), 20);*/
2949 welcome_vb = gtk_vbox_new(FALSE, 1);
2951 item_hb = gtk_hbox_new(FALSE, 1);
2953 icon = xpm_to_widget_from_parent(top_level, eicon3d64_xpm);
2954 gtk_box_pack_start(GTK_BOX(item_hb), icon, FALSE, FALSE, 5);
2956 #if GTK_MAJOR_VERSION < 2
2957 message = "Welcome to Ethereal!";
2959 message = "<span weight=\"bold\" size=\"25000\">" "Welcome to Ethereal!" "</span>";
2961 w = gtk_label_new(message);
2962 #if GTK_MAJOR_VERSION >= 2
2963 gtk_label_set_markup(GTK_LABEL(w), message);
2965 gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.5);
2966 gtk_box_pack_start(GTK_BOX(item_hb), w, TRUE, TRUE, 5);
2968 gtk_box_pack_start(GTK_BOX(welcome_vb), item_hb, TRUE, FALSE, 5);
2970 w = gtk_label_new("What would you like to do?");
2971 gtk_box_pack_start(GTK_BOX(welcome_vb), w, FALSE, FALSE, 10);
2972 gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.0);
2975 item_hb = welcome_item(ETHEREAL_STOCK_CAPTURE_START,
2977 "Capture live data from your network",
2978 GTK_SIGNAL_FUNC(capture_prep_cb), NULL);
2979 gtk_box_pack_start(GTK_BOX(welcome_vb), item_hb, TRUE, FALSE, 5);
2982 item_hb = welcome_item(GTK_STOCK_OPEN,
2984 "Open a previously captured file",
2985 GTK_SIGNAL_FUNC(file_open_cmd_cb), NULL);
2986 gtk_box_pack_start(GTK_BOX(welcome_vb), item_hb, TRUE, FALSE, 5);
2988 #if (GLIB_MAJOR_VERSION >= 2)
2989 item_hb = welcome_item(GTK_STOCK_HOME,
2991 "Visit the Ethereal homepage",
2992 GTK_SIGNAL_FUNC(topic_cb), GINT_TO_POINTER(ONLINEPAGE_HOME));
2993 gtk_box_pack_start(GTK_BOX(welcome_vb), item_hb, TRUE, FALSE, 5);
2997 w = gtk_label_new("");
2998 gtk_box_pack_start(GTK_BOX(welcome_vb), w, TRUE, TRUE, 0);
3000 w = gtk_label_new("");
3001 gtk_box_pack_start(GTK_BOX(welcome_hb), w, TRUE, TRUE, 0);
3003 gtk_box_pack_start(GTK_BOX(welcome_hb), welcome_vb, TRUE, TRUE, 0);
3005 w = gtk_label_new("");
3006 gtk_box_pack_start(GTK_BOX(welcome_hb), w, TRUE, TRUE, 0);
3008 gtk_widget_show_all(welcome_hb);
3010 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(welcome_scrollw),
3012 gtk_widget_show_all(welcome_scrollw);
3014 return welcome_scrollw;
3021 /* this is just a dummy to fill up window space, simply showing nothing */
3022 return scrolled_window_new(NULL, NULL);
3028 * XXX - this doesn't appear to work with the paned widgets in
3029 * GTK+ 1.2[.x]; if you hide one of the panes, the splitter remains
3030 * and the other pane doesn't grow to take up the rest of the pane.
3031 * It does appear to work with GTK+ 2.x.
3034 main_widgets_show_or_hide(void)
3036 gboolean main_second_pane_show;
3038 if (recent.main_toolbar_show) {
3039 gtk_widget_show(main_tb);
3041 gtk_widget_hide(main_tb);
3045 * Show the status hbox if either:
3047 * 1) we're showing the filter toolbar and we want it in the status
3052 * 2) we're showing the status bar.
3054 if ((recent.filter_toolbar_show && prefs.filter_toolbar_show_in_statusbar) ||
3055 recent.statusbar_show) {
3056 gtk_widget_show(stat_hbox);
3058 gtk_widget_hide(stat_hbox);
3061 if (recent.statusbar_show) {
3062 gtk_widget_show(status_pane);
3064 gtk_widget_hide(status_pane);
3067 if (recent.filter_toolbar_show) {
3068 gtk_widget_show(filter_tb);
3070 gtk_widget_hide(filter_tb);
3073 if (recent.packet_list_show && have_capture_file) {
3074 gtk_widget_show(pkt_scrollw);
3076 gtk_widget_hide(pkt_scrollw);
3079 if (recent.tree_view_show && have_capture_file) {
3080 gtk_widget_show(tv_scrollw);
3082 gtk_widget_hide(tv_scrollw);
3085 if (recent.byte_view_show && have_capture_file) {
3086 gtk_widget_show(byte_nb_ptr);
3088 gtk_widget_hide(byte_nb_ptr);
3091 if (have_capture_file) {
3092 gtk_widget_show(main_first_pane);
3094 gtk_widget_hide(main_first_pane);
3098 * Is anything in "main_second_pane" visible?
3099 * If so, show it, otherwise hide it.
3101 main_second_pane_show = FALSE;
3102 gtk_container_foreach(GTK_CONTAINER(main_second_pane), is_widget_visible,
3103 &main_second_pane_show);
3104 if (main_second_pane_show) {
3105 gtk_widget_show(main_second_pane);
3107 gtk_widget_hide(main_second_pane);
3110 if (!have_capture_file) {
3112 gtk_widget_show(welcome_pane);
3115 gtk_widget_hide(welcome_pane);
3120 #if GTK_MAJOR_VERSION >= 2
3121 /* called, when the window state changes (minimized, maximized, ...) */
3123 window_state_event_cb (GtkWidget *widget _U_,
3127 GdkWindowState new_window_state = ((GdkEventWindowState*)event)->new_window_state;
3129 if( (event->type) == (GDK_WINDOW_STATE)) {
3130 if(!(new_window_state & GDK_WINDOW_STATE_ICONIFIED)) {
3131 /* we might have dialogs popped up while we where iconified,
3133 display_queued_messages();
3142 create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
3145 *filter_bt, *filter_cm, *filter_te,
3146 *filter_add_expr_bt,
3149 GList *dfilter_list = NULL;
3150 GtkTooltips *tooltips;
3151 GtkAccelGroup *accel;
3153 /* Display filter construct dialog has an Apply button, and "OK" not
3154 only sets our text widget, it activates it (i.e., it causes us to
3155 filter the capture). */
3156 static construct_args_t args = {
3157 "Ethereal: Display Filter",
3162 /* use user-defined title if preference is set */
3163 title = create_user_window_title("The Ethereal Network Analyzer");
3166 top_level = window_new(GTK_WINDOW_TOPLEVEL, title);
3169 tooltips = gtk_tooltips_new();
3172 #if GTK_MAJOR_VERSION < 2
3173 /* has to be done, after top_level window is created */
3174 app_font_gtk1_init(top_level);
3178 gtk_widget_set_name(top_level, "main window");
3179 SIGNAL_CONNECT(top_level, "delete_event", main_window_delete_event_cb,
3181 #if GTK_MAJOR_VERSION >= 2
3182 SIGNAL_CONNECT(GTK_OBJECT(top_level), "window_state_event",
3183 G_CALLBACK (window_state_event_cb), NULL);
3186 gtk_window_set_policy(GTK_WINDOW(top_level), TRUE, TRUE, FALSE);
3188 /* Container for menu bar, toolbar(s), paned windows and progress/info box */
3189 main_vbox = gtk_vbox_new(FALSE, 1);
3190 gtk_container_border_width(GTK_CONTAINER(main_vbox), 1);
3191 gtk_container_add(GTK_CONTAINER(top_level), main_vbox);
3192 gtk_widget_show(main_vbox);
3195 menubar = main_menu_new(&accel);
3196 gtk_window_add_accel_group(GTK_WINDOW(top_level), accel);
3197 gtk_widget_show(menubar);
3200 main_tb = toolbar_new();
3201 gtk_widget_show (main_tb);
3204 pkt_scrollw = packet_list_new(prefs);
3205 WIDGET_SET_SIZE(packet_list, -1, pl_size);
3206 gtk_widget_show(pkt_scrollw);
3209 tv_scrollw = main_tree_view_new(prefs, &tree_view);
3210 WIDGET_SET_SIZE(tv_scrollw, -1, tv_size);
3211 gtk_widget_show(tv_scrollw);
3213 #if GTK_MAJOR_VERSION < 2
3214 SIGNAL_CONNECT(tree_view, "tree-select-row", tree_view_select_row_cb, NULL);
3215 SIGNAL_CONNECT(tree_view, "tree-unselect-row", tree_view_unselect_row_cb,
3218 SIGNAL_CONNECT(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)),
3219 "changed", tree_view_selection_changed_cb, NULL);
3221 SIGNAL_CONNECT(tree_view, "button_press_event", popup_menu_handler,
3222 OBJECT_GET_DATA(popup_menu_object, PM_TREE_VIEW_KEY));
3223 gtk_widget_show(tree_view);
3226 byte_nb_ptr = byte_view_new();
3227 WIDGET_SET_SIZE(byte_nb_ptr, -1, bv_size);
3228 gtk_widget_show(byte_nb_ptr);
3230 SIGNAL_CONNECT(byte_nb_ptr, "button_press_event", popup_menu_handler,
3231 OBJECT_GET_DATA(popup_menu_object, PM_HEXDUMP_KEY));
3234 /* Panes for the packet list, tree, and byte view */
3235 main_pane_v1 = gtk_vpaned_new();
3236 gtk_widget_show(main_pane_v1);
3237 main_pane_v2 = gtk_vpaned_new();
3238 gtk_widget_show(main_pane_v2);
3239 main_pane_h1 = gtk_hpaned_new();
3240 gtk_widget_show(main_pane_h1);
3241 main_pane_h2 = gtk_hpaned_new();
3242 gtk_widget_show(main_pane_h2);
3244 /* filter toolbar */
3245 #if GTK_MAJOR_VERSION < 2
3246 filter_tb = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
3249 filter_tb = gtk_toolbar_new();
3250 gtk_toolbar_set_orientation(GTK_TOOLBAR(filter_tb),
3251 GTK_ORIENTATION_HORIZONTAL);
3252 #endif /* GTK_MAJOR_VERSION */
3253 gtk_widget_show(filter_tb);
3255 /* Create the "Filter:" button */
3256 filter_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_DISPLAY_FILTER_ENTRY);
3257 SIGNAL_CONNECT(filter_bt, "clicked", display_filter_construct_cb, &args);
3258 gtk_widget_show(filter_bt);
3259 OBJECT_SET_DATA(top_level, E_FILT_BT_PTR_KEY, filter_bt);
3261 gtk_toolbar_append_widget(GTK_TOOLBAR(filter_tb), filter_bt,
3262 "Open the \"Display Filter\" dialog, to edit/apply filters", "Private");
3264 /* Create the filter combobox */
3265 filter_cm = gtk_combo_new();
3266 dfilter_list = NULL;
3267 gtk_combo_disable_activate(GTK_COMBO(filter_cm));
3268 gtk_combo_set_case_sensitive(GTK_COMBO(filter_cm), TRUE);
3269 OBJECT_SET_DATA(filter_cm, E_DFILTER_FL_KEY, dfilter_list);
3270 filter_te = GTK_COMBO(filter_cm)->entry;
3271 main_display_filter_widget=filter_te;
3272 OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_te);
3273 OBJECT_SET_DATA(filter_te, E_DFILTER_CM_KEY, filter_cm);
3274 OBJECT_SET_DATA(top_level, E_DFILTER_CM_KEY, filter_cm);
3275 SIGNAL_CONNECT(filter_te, "activate", filter_activate_cb, filter_te);
3276 SIGNAL_CONNECT(filter_te, "changed", filter_te_syntax_check_cb, NULL);
3277 WIDGET_SET_SIZE(filter_cm, 400, -1);
3278 gtk_widget_show(filter_cm);
3279 gtk_toolbar_append_widget(GTK_TOOLBAR(filter_tb), filter_cm,
3281 /* setting a tooltip for a combobox will do nothing, so add it to the corresponding text entry */
3282 gtk_tooltips_set_tip(tooltips, filter_te,
3283 "Enter a display filter, or choose one of your recently used filters. "
3284 "The background color of this field is changed by a continuous syntax check (green is valid, red is invalid).",
3287 /* Create the "Add Expression..." button, to pop up a dialog
3288 for constructing filter comparison expressions. */
3289 filter_add_expr_bt = BUTTON_NEW_FROM_STOCK(ETHEREAL_STOCK_ADD_EXPRESSION);
3290 OBJECT_SET_DATA(filter_tb, E_FILT_FILTER_TE_KEY, filter_te);
3291 SIGNAL_CONNECT(filter_add_expr_bt, "clicked", filter_add_expr_bt_cb, filter_tb);
3292 gtk_widget_show(filter_add_expr_bt);
3293 gtk_toolbar_append_widget(GTK_TOOLBAR(filter_tb), filter_add_expr_bt,
3294 "Add an expression to this filter string", "Private");
3296 /* Create the "Clear" button */
3297 filter_reset = BUTTON_NEW_FROM_STOCK(GTK_STOCK_CLEAR);
3298 OBJECT_SET_DATA(filter_reset, E_DFILTER_TE_KEY, filter_te);
3299 SIGNAL_CONNECT(filter_reset, "clicked", filter_reset_cb, NULL);
3300 gtk_widget_show(filter_reset);
3301 gtk_toolbar_append_widget(GTK_TOOLBAR(filter_tb), filter_reset,
3302 "Clear this filter string and update the display", "Private");
3304 /* Create the "Apply" button */
3305 filter_apply = BUTTON_NEW_FROM_STOCK(GTK_STOCK_APPLY);
3306 OBJECT_SET_DATA(filter_apply, E_DFILTER_CM_KEY, filter_cm);
3307 SIGNAL_CONNECT(filter_apply, "clicked", filter_activate_cb, filter_te);
3308 gtk_widget_show(filter_apply);
3309 gtk_toolbar_append_widget(GTK_TOOLBAR(filter_tb), filter_apply,
3310 "Apply this filter string to the display", "Private");
3312 /* Sets the text entry widget pointer as the E_DILTER_TE_KEY data
3313 * of any widget that ends up calling a callback which needs
3314 * that text entry pointer */
3315 set_menu_object_data("/File/Open...", E_DFILTER_TE_KEY, filter_te);
3316 set_menu_object_data("/Analyze/Display Filters...", E_FILT_TE_PTR_KEY,
3318 set_menu_object_data("/Analyze/Follow TCP Stream", E_DFILTER_TE_KEY,
3320 set_menu_object_data("/Analyze/Apply as Filter/Selected", E_DFILTER_TE_KEY,
3322 set_menu_object_data("/Analyze/Apply as Filter/Not Selected", E_DFILTER_TE_KEY,
3324 set_menu_object_data("/Analyze/Apply as Filter/... and Selected", E_DFILTER_TE_KEY,
3326 set_menu_object_data("/Analyze/Apply as Filter/... or Selected", E_DFILTER_TE_KEY,
3328 set_menu_object_data("/Analyze/Apply as Filter/... and not Selected", E_DFILTER_TE_KEY,
3330 set_menu_object_data("/Analyze/Apply as Filter/... or not Selected", E_DFILTER_TE_KEY,
3332 set_menu_object_data("/Analyze/Prepare a Filter/Selected", E_DFILTER_TE_KEY,
3334 set_menu_object_data("/Analyze/Prepare a Filter/Not Selected", E_DFILTER_TE_KEY,
3336 set_menu_object_data("/Analyze/Prepare a Filter/... and Selected", E_DFILTER_TE_KEY,
3338 set_menu_object_data("/Analyze/Prepare a Filter/... or Selected", E_DFILTER_TE_KEY,
3340 set_menu_object_data("/Analyze/Prepare a Filter/... and not Selected", E_DFILTER_TE_KEY,
3342 set_menu_object_data("/Analyze/Prepare a Filter/... or not Selected", E_DFILTER_TE_KEY,
3344 set_toolbar_object_data(E_DFILTER_TE_KEY, filter_te);
3345 OBJECT_SET_DATA(popup_menu_object, E_DFILTER_TE_KEY, filter_te);
3346 OBJECT_SET_DATA(popup_menu_object, E_MPACKET_LIST_KEY, packet_list);
3348 /* info (main) statusbar */
3349 info_bar = info_bar_new();
3350 gtk_widget_show(info_bar);
3352 /* packets statusbar */
3353 packets_bar = packets_bar_new();
3354 gtk_widget_show(packets_bar);
3356 /* Filter/status hbox */
3357 stat_hbox = gtk_hbox_new(FALSE, 1);
3358 gtk_container_border_width(GTK_CONTAINER(stat_hbox), 0);
3359 gtk_widget_show(stat_hbox);
3361 /* Pane for the statusbar */
3362 status_pane = gtk_hpaned_new();
3363 gtk_widget_show(status_pane);
3365 /* Pane for the welcome screen */
3366 welcome_pane = welcome_new();
3367 gtk_widget_show(welcome_pane);
3371 show_main_window(gboolean doing_work)
3373 main_set_for_capture_file(doing_work);
3375 /*** we have finished all init things, show the main window ***/
3376 gtk_widget_show(top_level);
3378 /* the window can be maximized only, if it's visible, so do it after show! */
3379 main_load_window_geometry(top_level);
3381 /* process all pending GUI events before continue */
3382 while (gtk_events_pending()) gtk_main_iteration();
3384 /* Pop up any queued-up alert boxes. */
3385 display_queued_messages();