Move merge.{h,c} into wiretap: these modules use wiretap to merge files.
[metze/wireshark/wip.git] / ui / gtk / main.c
index 37e073301dd86231077648b865241095c24b2997..ab137a2d974327ee8ff6fa858105795582dff507 100644 (file)
@@ -26,9 +26,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #ifdef _WIN32 /* Needed for console I/O */
 #if _MSC_VER < 1500
 /* AttachConsole() needs this #define! */
+/* But we're not calling it from here any more; do we need this? */
 #define _WIN32_WINNT 0x0501
 #endif
+
 #include <fcntl.h>
 #include <conio.h>
+#include <ui/win32/console_win32.h>
 #endif
 
 #ifdef HAVE_LIBPORTAUDIO
 #include <portaudio.h>
 #endif /* HAVE_LIBPORTAUDIO */
 
+#include <wsutil/crash_info.h>
+#include <wsutil/u3.h>
+#include <wsutil/privileges.h>
+#include <wsutil/file_util.h>
+
+#include <wiretap/merge.h>
+
 #include <epan/epan.h>
 #include <epan/filesystem.h>
-#include <wsutil/privileges.h>
 #include <epan/epan_dissect.h>
 #include <epan/timestamp.h>
 #include <epan/plugins.h>
 #include <epan/stat_cmd_args.h>
 #include <epan/uat.h>
 #include <epan/column.h>
+#include <epan/disabled_protos.h>
+#include <epan/print.h>
 
 /* general (not GTK specific) */
 #include "../file.h"
+#include "../frame_tvbuff.h"
 #include "../summary.h"
 #include "../filters.h"
-#include "../disabled_protos.h"
 #include "../color.h"
 #include "../color_filters.h"
-#include "../print.h"
 #include "../register.h"
 #include "../ringbuffer.h"
 #include "ui/util.h"
 #include "../clopts_common.h"
-#include "../console_io.h"
 #include "../cmdarg_err.h"
 #include "../version_info.h"
-#include "../merge.h"
 #include "../log.h"
-#include "../u3.h"
 
 #include "gtk_iface_monitor.h"
 
 #include "ui/alert_box.h"
 #include "ui/main_statusbar.h"
+#include "ui/preference_utils.h"
 #include "ui/recent.h"
 #include "ui/recent_utils.h"
+#include "ui/software_update.h"
 #include "ui/simple_dialog.h"
 #include "ui/ui_util.h"
 
-#include <wsutil/file_util.h>
+#ifdef HAVE_LIBPCAP
+#include "ui/capture_globals.h"
+#include "ui/iface_lists.h"
+#endif
 
 #ifdef HAVE_LIBPCAP
-#include "../capture_ui_utils.h"
-#include "../capture-pcap-util.h"
-#include "../capture_ifinfo.h"
-#include "../capture.h"
-#include "../capture_sync.h"
+#include "capture_ui_utils.h"
+#include "capture-pcap-util.h"
+#include "capture_ifinfo.h"
+#include "capture.h"
+#include "capture_sync.h"
 #endif
 
 #ifdef _WIN32
-#include "../capture-wpcap.h"
-#include "../capture_wpcap_packet.h"
+#include "capture-wpcap.h"
+#include "capture_wpcap_packet.h"
 #include <tchar.h> /* Needed for Unicode */
 #include <wsutil/unicode-utils.h>
 #include <commctrl.h>
 #include "ui/gtk/gui_utils.h"
 #include "ui/gtk/color_dlg.h"
 #include "ui/gtk/filter_dlg.h"
+#include "ui/gtk/fileset_dlg.h"
 #include "ui/gtk/uat_gui.h"
 #include "ui/gtk/main.h"
 #include "ui/gtk/main_80211_toolbar.h"
 #include "ui/gtk/webbrowser.h"
 #include "ui/gtk/capture_dlg.h"
 #include "ui/gtk/capture_if_dlg.h"
-#include "ui/gtk/capture_globals.h"
 #include "ui/gtk/tap_param_dlg.h"
 #include "ui/gtk/prefs_column.h"
 #include "ui/gtk/prefs_dlg.h"
 #include "ui/gtk/proto_help.h"
-#include "ui/gtk/new_packet_list.h"
+#include "ui/gtk/packet_list.h"
 #include "ui/gtk/filter_expression_save_dlg.h"
 
-#ifdef HAVE_LIBPCAP
-#include "ui/gtk/iface_lists.h"
-#endif
-
 #include "ui/gtk/old-gtk-compat.h"
 
 #ifdef HAVE_LIBPCAP
-#include "../../image/wsicon16.xpm"
-#include "../../image/wsicon32.xpm"
-#include "../../image/wsicon48.xpm"
-#include "../../image/wsicon64.xpm"
-#include "../../image/wsiconcap16.xpm"
-#include "../../image/wsiconcap32.xpm"
-#include "../../image/wsiconcap48.xpm"
+#include "wsicon.h"
+#include "wsiconcap.h"
 #endif
 
 #ifdef HAVE_AIRPCAP
 
 
 #ifdef HAVE_GTKOSXAPPLICATION
-#include <igemacintegration/gtkosxapplication.h>
+#include <gtkmacintegration/gtkosxapplication.h>
 #endif
 
 /*
  */
 #define RC_FILE "gtkrc"
 
+#ifdef HAVE_LIBPCAP
+capture_options global_capture_opts;
+capture_session global_capture_session;
+#endif
+
 capture_file cfile;
 
 static gboolean capture_stopping;
@@ -234,12 +240,6 @@ static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cf
 
 static guint  tap_update_timer_id;
 
-#ifdef _WIN32
-static gboolean has_console;   /* TRUE if app has console */
-static gboolean console_wait;  /* "Press any key..." */
-static void destroy_console(void);
-static gboolean stdin_capture = FALSE; /* Don't grab stdin & stdout if TRUE */
-#endif
 static void console_log_handler(const char *log_domain,
     GLogLevelFlags log_level, const char *message, gpointer user_data);
 
@@ -250,9 +250,8 @@ static void main_save_window_geometry(GtkWidget *widget);
 
 /* Match selected byte pattern */
 static void
-match_selected_cb_do(gpointer data, int action, gchar *text)
+match_selected_cb_do(GtkWidget *filter_te, int action, gchar *text)
 {
-    GtkWidget  *filter_te;
     char       *cur_filter, *new_filter;
 
     if ((!text) || (0 == strlen(text))) {
@@ -260,8 +259,6 @@ match_selected_cb_do(gpointer data, int action, gchar *text)
         return;
     }
 
-    g_assert(data);
-    filter_te = g_object_get_data(G_OBJECT(data), E_DFILTER_TE_KEY);
     g_assert(filter_te);
 
     cur_filter = gtk_editable_get_chars(GTK_EDITABLE(filter_te), 0, -1);
@@ -333,14 +330,14 @@ match_selected_cb_do(gpointer data, int action, gchar *text)
 }
 
 void
-match_selected_ptree_cb(GtkWidget *w, gpointer data, MATCH_SELECTED_E action)
+match_selected_ptree_cb(gpointer data, MATCH_SELECTED_E action)
 {
     char *filter = NULL;
 
     if (cfile.finfo_selected) {
         filter = proto_construct_match_selected_string(cfile.finfo_selected,
                                                        cfile.edt);
-        match_selected_cb_do((data ? data : w), action, filter);
+        match_selected_cb_do((GtkWidget *)g_object_get_data(G_OBJECT(data), E_DFILTER_TE_KEY), action, filter);
     }
 }
 
@@ -367,7 +364,7 @@ colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr)
             } else {
                 color_filters_set_tmp(filt_nr,filter, FALSE);
             }
-            new_packet_list_colorize_packets();
+            packet_list_colorize_packets();
         }
     }
 }
@@ -376,7 +373,7 @@ colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr)
 static void selected_ptree_info_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
 {
     gchar *selected_proto_url;
-    gchar *proto_abbrev = data;
+    gchar *proto_abbrev = (gchar *)data;
 
 
     switch(btn) {
@@ -408,7 +405,7 @@ selected_ptree_info_cb(GtkWidget *widget _U_, gpointer data _U_)
         /* convert selected field to protocol abbreviation */
         /* XXX - could this conversion be simplified? */
         field_id = cfile.finfo_selected->hfinfo->id;
-        /* if the selected field isn't a protocol, get it's parent */
+        /* if the selected field isn't a protocol, get its parent */
         if(!proto_registrar_is_protocol(field_id)) {
             field_id = proto_registrar_get_parent(cfile.finfo_selected->hfinfo->id);
         }
@@ -456,7 +453,7 @@ selected_ptree_info_cb(GtkWidget *widget _U_, gpointer data _U_)
 static void selected_ptree_ref_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
 {
     gchar *selected_proto_url;
-    gchar *proto_abbrev = data;
+    gchar *proto_abbrev = (gchar *)data;
 
     switch(btn) {
     case(ESD_BTN_OK):
@@ -486,7 +483,7 @@ selected_ptree_ref_cb(GtkWidget *widget _U_, gpointer data _U_)
         /* convert selected field to protocol abbreviation */
         /* XXX - could this conversion be simplified? */
         field_id = cfile.finfo_selected->hfinfo->id;
-        /* if the selected field isn't a protocol, get it's parent */
+        /* if the selected field isn't a protocol, get its parent */
         if(!proto_registrar_is_protocol(field_id)) {
             field_id = proto_registrar_get_parent(cfile.finfo_selected->hfinfo->id);
         }
@@ -537,12 +534,12 @@ GList *
 get_ip_address_list_from_packet_list_row(gpointer data)
 {
     gint    row = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_ROW_KEY));
-    gint    column = new_packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
+    gint    column = packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
     gint    col;
     frame_data *fdata;
     GList      *addr_list = NULL;
 
-    fdata = (frame_data *) new_packet_list_get_row_data(row);
+    fdata = (frame_data *) packet_list_get_row_data(row);
 
     if (fdata != NULL) {
         epan_dissect_t edt;
@@ -553,7 +550,8 @@ get_ip_address_list_from_packet_list_row(gpointer data)
         epan_dissect_init(&edt, FALSE, FALSE);
         col_custom_prime_edt(&edt, &cfile.cinfo);
 
-        epan_dissect_run(&edt, &cfile.pseudo_header, cfile.pd, fdata, &cfile.cinfo);
+        epan_dissect_run(&edt, &cfile.phdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
+            fdata, &cfile.cinfo);
         epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
 
         /* First check selected column */
@@ -578,11 +576,11 @@ static gchar *
 get_filter_from_packet_list_row_and_column(gpointer data)
 {
     gint    row = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_ROW_KEY));
-    gint    column = new_packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
+    gint    column = packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
     frame_data *fdata;
     gchar      *buf=NULL;
 
-    fdata = (frame_data *) new_packet_list_get_row_data(row);
+    fdata = (frame_data *) packet_list_get_row_data(row);
 
     if (fdata != NULL) {
         epan_dissect_t edt;
@@ -593,8 +591,8 @@ get_filter_from_packet_list_row_and_column(gpointer data)
         epan_dissect_init(&edt, have_custom_cols(&cfile.cinfo), FALSE);
         col_custom_prime_edt(&edt, &cfile.cinfo);
 
-        epan_dissect_run(&edt, &cfile.pseudo_header, cfile.pd, fdata,
-                 &cfile.cinfo);
+        epan_dissect_run(&edt, &cfile.phdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
+                         fdata, &cfile.cinfo);
         epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
 
         if ((cfile.cinfo.col_custom_occurrence[column]) ||
@@ -612,10 +610,10 @@ get_filter_from_packet_list_row_and_column(gpointer data)
                 /* leak a little but safer than ep_ here */
                 if (cfile.cinfo.col_fmt[column] == COL_CUSTOM) {
                     header_field_info *hfi = proto_registrar_get_byname(cfile.cinfo.col_custom_field[column]);
-                    if (hfi->parent == -1) {
+                    if (hfi && hfi->parent == -1) {
                         /* Protocol only */
                         buf = se_strdup(cfile.cinfo.col_expr.col_expr[column]);
-                    } else if (hfi->type == FT_STRING) {
+                    } else if (hfi && hfi->type == FT_STRING) {
                         /* Custom string, add quotes */
                         buf = se_strdup_printf("%s == \"%s\"", cfile.cinfo.col_expr.col_expr[column],
                                                cfile.cinfo.col_expr.col_expr_val[column]);
@@ -635,11 +633,11 @@ get_filter_from_packet_list_row_and_column(gpointer data)
 }
 
 void
-match_selected_plist_cb(GtkWidget *w _U_, gpointer data, MATCH_SELECTED_E action)
+match_selected_plist_cb(gpointer data, MATCH_SELECTED_E action)
 {
-    match_selected_cb_do(data,
+    match_selected_cb_do((GtkWidget *)g_object_get_data(G_OBJECT(data), E_DFILTER_TE_KEY),
         action,
-        get_filter_from_packet_list_row_and_column(data));
+        get_filter_from_packet_list_row_and_column((GtkWidget *)data));
 }
 
 /* This function allows users to right click in the details window and copy the text
@@ -653,7 +651,7 @@ void
 copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E action)
 {
     GString *gtk_text_str = g_string_new("");
-    char labelstring[256];
+    char labelstring[ITEM_LABEL_LENGTH];
     char *stringpointer = labelstring;
 
     switch(action)
@@ -710,12 +708,12 @@ set_frame_reftime(gboolean set, frame_data *frame, gint row) {
     }
     cf_reftime_packets(&cfile);
     if (!frame->flags.ref_time && !frame->flags.passed_dfilter) {
-        new_packet_list_freeze();
+        packet_list_freeze();
         cfile.displayed_count--;
-        new_packet_list_recreate_visible_rows();
-        new_packet_list_thaw();
+        packet_list_recreate_visible_rows();
+        packet_list_thaw();
     }
-    new_packet_list_queue_draw();
+    packet_list_queue_draw();
 }
 
 
@@ -726,7 +724,7 @@ static void reftime_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_
         timestamp_set_type(TS_RELATIVE);
         recent.gui_time_format  = TS_RELATIVE;
         cf_timestamp_auto_precision(&cfile);
-        new_packet_list_queue_draw();
+        packet_list_queue_draw();
         break;
     case(ESD_BTN_NO):
         break;
@@ -750,7 +748,7 @@ reftime_frame_cb(GtkWidget *w _U_, gpointer data _U_, REFTIME_ACTION_E action)
     case REFTIME_TOGGLE:
         if (cfile.current_frame) {
             if(recent.gui_time_format != TS_RELATIVE && cfile.current_frame->flags.ref_time==0) {
-                reftime_dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO,
+                reftime_dialog = (GtkWidget *)simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO,
                     "%sSwitch to the appropriate Time Display Format?%s\n\n"
                     "Time References don't work well with the currently selected Time Display Format.\n\n"
                     "Do you want to switch to \"Seconds Since Beginning of Capture\" now?",
@@ -896,11 +894,11 @@ void apply_as_custom_column_cb (GtkWidget *widget _U_, gpointer data _U_)
         column_prefs_add_custom(COL_CUSTOM, cfile.finfo_selected->hfinfo->name,
                                 cfile.finfo_selected->hfinfo->abbrev,0);
         /* Recreate the packet list according to new preferences */
-        new_packet_list_recreate ();
+        packet_list_recreate ();
         if (!prefs.gui_use_pref_save) {
             prefs_main_write();
         }
-        cfile.cinfo.columns_changed = FALSE; /* Reset value */
+        cfile.columns_changed = FALSE; /* Reset value */
     }
 }
 
@@ -916,7 +914,7 @@ void expand_tree_cb(GtkWidget *widget _U_, gpointer data _U_) {
 }
 
 void resolve_name_cb(GtkWidget *widget _U_, gpointer data _U_) {
-    static const e_addr_resolve resolv_flags = {TRUE, TRUE, TRUE, TRUE};
+    static const e_addr_resolve resolv_flags = {TRUE, TRUE, TRUE, TRUE, TRUE, FALSE};
 
     if (cfile.edt->tree) {
         proto_tree_draw_resolve(cfile.edt->tree, tree_view_gbl, &resolv_flags);
@@ -990,7 +988,7 @@ main_do_quit(void)
 
 #ifdef HAVE_LIBPCAP
     /* Nuke any child capture in progress. */
-    capture_kill_child(&global_capture_opts);
+    capture_kill_child(&global_capture_session);
 #endif
 
     /* Are we in the middle of reading a capture? */
@@ -1168,7 +1166,7 @@ print_usage(gboolean print_ver) {
   fprintf(output, "  -I                       capture in monitor mode, if available\n");
 #endif
 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
-  fprintf(output, "  -B <buffer size>         size of kernel buffer (def: 1MB)\n");
+  fprintf(output, "  -B <buffer size>         size of kernel buffer (def: %dMB)\n", DEFAULT_CAPTURE_BUFFER_SIZE);
 #endif
   fprintf(output, "  -y <link type>           link layer type (def: first appropriate)\n");
   fprintf(output, "  -D                       print list of interfaces and exit\n");
@@ -1185,7 +1183,10 @@ print_usage(gboolean print_ver) {
   fprintf(output, "                           filesize:NUM - switch to next file after NUM KB\n");
   fprintf(output, "                              files:NUM - ringbuffer: replace after NUM files\n");
 #endif  /* HAVE_LIBPCAP */
-
+#ifdef HAVE_PCAP_REMOTE
+  fprintf(output, "RPCAP options:\n");
+  fprintf(output, "  -A <user>:<password>     use RPCAP password authentication\n");
+#endif
   /*fprintf(output, "\n");*/
   fprintf(output, "Input file:\n");
   fprintf(output, "  -r <infile>              set the filename to read from (no pipes or stdin!)\n");
@@ -1199,13 +1200,13 @@ print_usage(gboolean print_ver) {
   fprintf(output, "\n");
   fprintf(output, "User interface:\n");
   fprintf(output, "  -C <config profile>      start with specified configuration profile\n");
-  fprintf(output, "  -d <display filter>      start with the given display filter\n");
+  fprintf(output, "  -Y <display filter>      start with the given display filter\n");
   fprintf(output, "  -g <packet number>       go to specified packet number after \"-r\"\n");
   fprintf(output, "  -J <jump filter>         jump to the first packet matching the (display)\n");
   fprintf(output, "                           filter\n");
   fprintf(output, "  -j                       search backwards for a matching packet after \"-J\"\n");
   fprintf(output, "  -m <font>                set the font name used for most text\n");
-  fprintf(output, "  -t ad|a|r|d|dd|e         output format of time stamps (def: r: rel. to first)\n");
+  fprintf(output, "  -t a|ad|d|dd|e|r|u|ud    output format of time stamps (def: r: rel. to first)\n");
   fprintf(output, "  -u s|hms                 output format of seconds (def: s: seconds)\n");
   fprintf(output, "  -X <key>:<value>         eXtension options, see man page for details\n");
   fprintf(output, "  -z <statistics>          show various statistics, see man page for details\n");
@@ -1234,10 +1235,6 @@ print_usage(gboolean print_ver) {
 static void
 show_version(void)
 {
-#ifdef _WIN32
-  create_console();
-#endif
-
   printf(PACKAGE " " VERSION "%s\n"
          "\n"
          "%s"
@@ -1247,35 +1244,6 @@ show_version(void)
          "%s",
       wireshark_svnversion, get_copyright_info(), comp_info_str->str,
       runtime_info_str->str);
-
-#ifdef _WIN32
-  destroy_console();
-#endif
-}
-
-/*
- * Print to the standard error.  On Windows, create a console for the
- * standard error to show up on, if necessary.
- * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
- * terminal isn't the standard error?
- */
-void
-vfprintf_stderr(const char *fmt, va_list ap)
-{
-#ifdef _WIN32
-  create_console();
-#endif
-  vfprintf(stderr, fmt, ap);
-}
-
-void
-fprintf_stderr(const char *fmt, ...)
-{
-  va_list ap;
-
-  va_start(ap, fmt);
-  vfprintf_stderr(fmt, ap);
-  va_end(ap);
 }
 
 /*
@@ -1287,11 +1255,14 @@ cmdarg_err(const char *fmt, ...)
 {
   va_list ap;
 
-  fprintf_stderr("wireshark: ");
+#ifdef _WIN32
+  create_console();
+#endif
+  fprintf(stderr, "wireshark: ");
   va_start(ap, fmt);
-  vfprintf_stderr(fmt, ap);
+  vfprintf(stderr, fmt, ap);
   va_end(ap);
-  fprintf_stderr("\n");
+  fprintf(stderr, "\n");
 }
 
 /*
@@ -1305,9 +1276,12 @@ cmdarg_err_cont(const char *fmt, ...)
 {
   va_list ap;
 
+#ifdef _WIN32
+  create_console();
+#endif
   va_start(ap, fmt);
-  vfprintf_stderr(fmt, ap);
-  fprintf_stderr("\n");
+  vfprintf(stderr, fmt, ap);
+  fprintf(stderr, "\n");
   va_end(ap);
 }
 
@@ -1322,31 +1296,6 @@ tap_update_cb(gpointer data _U_)
     return TRUE;
 }
 
-/* Restart the tap update display timer with new configured interval */
-void reset_tap_update_timer(void)
-{
-    g_source_remove(tap_update_timer_id);
-    tap_update_timer_id = g_timeout_add(prefs.tap_update_interval, tap_update_cb, NULL);
-}
-
-void
-protect_thread_critical_region(void)
-{
-    /* Threading support for TAP:s removed
-     * http://www.wireshark.org/lists/wireshark-dev/200611/msg00199.html
-     * See the commit for removed code:
-     * http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027
-     */
-}
-void
-unprotect_thread_critical_region(void)
-{
-    /* Threading support for TAP:s removed
-     * http://www.wireshark.org/lists/wireshark-dev/200611/msg00199.html
-     */
-
-}
-
 /*
  * Periodically process outstanding hostname lookups. If we have new items,
  * redraw the packet list and tree view.
@@ -1356,7 +1305,7 @@ static gboolean
 resolv_update_cb(gpointer data _U_)
 {
   /* Anything new show up? */
-  if (host_name_lookup_process(NULL)) {
+  if (host_name_lookup_process()) {
     if (gtk_widget_get_window(pkt_scrollw))
       gdk_window_invalidate_rect(gtk_widget_get_window(pkt_scrollw), NULL, TRUE);
     if (gtk_widget_get_window(tv_scrollw))
@@ -1369,25 +1318,6 @@ resolv_update_cb(gpointer data _U_)
 }
 
 
-/* Set main_window_name and it's icon title to the capture filename */
-static void
-set_display_filename(capture_file *cf)
-{
-  gchar *display_name;
-  gchar *window_name;
-
-  if (cf->filename) {
-    display_name = cf_get_display_name(cf);
-    window_name = g_strdup_printf("%s%s", cf->unsaved_changes ? "*" : "",
-                                  display_name);
-    g_free(display_name);
-    main_set_window_name(window_name);
-    g_free(window_name);
-  } else {
-    main_set_window_name("The Wireshark Network Analyzer");
-  }
-}
-
 /* Update various parts of the main window for a capture file "unsaved
    changes" change - update the title to reflect whether there are
    unsaved changes or not, and update the menus and toolbar to
@@ -1395,7 +1325,7 @@ set_display_filename(capture_file *cf)
 void
 main_update_for_unsaved_changes(capture_file *cf)
 {
-  set_display_filename(cf);
+  set_titlebar_for_capture_file(cf);
   set_menus_for_capture_file(cf);
   set_toolbar_for_capture_file(cf);
 }
@@ -1424,7 +1354,7 @@ main_colorize_changed(gboolean packet_list_colorize)
   if(packet_list_colorize != recent.packet_list_colorize) {
       recent.packet_list_colorize = packet_list_colorize;
       color_filters_enable(packet_list_colorize);
-      new_packet_list_colorize_packets();
+      packet_list_colorize_packets();
   }
 }
 
@@ -1453,7 +1383,7 @@ main_cf_cb_file_closing(capture_file *cf)
      * data structures, so it wouldn't be easy to use a progress bar,
      * rather than, say, a progress spinner, here! */
     if(cf->count > 10000) {
-        close_dlg = simple_dialog(ESD_TYPE_STOP, ESD_BTN_NONE,
+        close_dlg = (GtkWidget *)simple_dialog(ESD_TYPE_STOP, ESD_BTN_NONE,
                                   "%sClosing file!%s\n\nPlease wait ...",
                                   simple_dialog_primary_start(),
                                   simple_dialog_primary_end());
@@ -1464,10 +1394,11 @@ main_cf_cb_file_closing(capture_file *cf)
        capture file we're closing. */
     destroy_packet_wins();
 
-    /* Restore the standard title bar message. */
-    main_set_window_name("The Wireshark Network Analyzer");
+    /* Update the titlebar to reflect the lack of a capture file. */
+    set_titlebar_for_capture_file(NULL);
 
-    /* Disable all menu items that make sense only if you have a capture. */
+    /* Disable all menu and toolbar items that make sense only if
+       you have a capture. */
     set_menus_for_capture_file(NULL);
     set_toolbar_for_capture_file(NULL);
     main_set_for_captured_packets(FALSE);
@@ -1544,10 +1475,10 @@ main_cf_cb_file_rescan_finished(capture_file *cf)
 
 #ifdef HAVE_LIBPCAP
 static GList *icon_list_create(
-    const char **icon16_xpm,
-    const char **icon32_xpm,
-    const char **icon48_xpm,
-    const char **icon64_xpm)
+    const guint8 *icon16_pb,
+    const guint8 *icon32_pb,
+    const guint8 *icon48_pb,
+    const guint8 *icon64_pb)
 {
   GList *icon_list = NULL;
   GdkPixbuf * pixbuf16;
@@ -1556,26 +1487,26 @@ static GList *icon_list_create(
   GdkPixbuf * pixbuf64;
 
 
-  if(icon16_xpm != NULL) {
-      pixbuf16 = gdk_pixbuf_new_from_xpm_data(icon16_xpm);
+  if(icon16_pb != NULL) {
+      pixbuf16 = gdk_pixbuf_new_from_inline(-1, icon16_pb, FALSE, NULL);
       g_assert(pixbuf16);
       icon_list = g_list_append(icon_list, pixbuf16);
   }
 
-  if(icon32_xpm != NULL) {
-      pixbuf32 = gdk_pixbuf_new_from_xpm_data(icon32_xpm);
+  if(icon32_pb != NULL) {
+      pixbuf32 = gdk_pixbuf_new_from_inline(-1, icon32_pb, FALSE, NULL);
       g_assert(pixbuf32);
       icon_list = g_list_append(icon_list, pixbuf32);
   }
 
-  if(icon48_xpm != NULL) {
-      pixbuf48 = gdk_pixbuf_new_from_xpm_data(icon48_xpm);
+  if(icon48_pb != NULL) {
+      pixbuf48 = gdk_pixbuf_new_from_inline(-1, icon48_pb, FALSE, NULL);
       g_assert(pixbuf48);
       icon_list = g_list_append(icon_list, pixbuf48);
   }
 
-  if(icon64_xpm != NULL) {
-      pixbuf64 = gdk_pixbuf_new_from_xpm_data(icon64_xpm);
+  if(icon64_pb != NULL) {
+      pixbuf64 = gdk_pixbuf_new_from_inline(-1, icon64_pb, FALSE, NULL);
       g_assert(pixbuf64);
       icon_list = g_list_append(icon_list, pixbuf64);
   }
@@ -1584,25 +1515,14 @@ static GList *icon_list_create(
 }
 
 static void
-main_capture_set_main_window_title(capture_options *capture_opts)
-{
-    GString *title = g_string_new("");
-
-    g_string_append(title, "Capturing ");
-    g_string_append_printf(title, "from %s ", cf_get_tempfile_source(capture_opts->cf));
-    main_set_window_name(title->str);
-    g_string_free(title, TRUE);
-}
-
-static void
-main_capture_cb_capture_prepared(capture_options *capture_opts)
+main_capture_cb_capture_prepared(capture_session *cap_session)
 {
     static GList *icon_list = NULL;
 
-    main_capture_set_main_window_title(capture_opts);
+    set_titlebar_for_capture_in_progress((capture_file *)cap_session->cf);
 
     if(icon_list == NULL) {
-        icon_list = icon_list_create(wsiconcap16_xpm, wsiconcap32_xpm, wsiconcap48_xpm, NULL);
+        icon_list = icon_list_create(wsiconcap_16_pb_data, wsiconcap_32_pb_data, wsiconcap_48_pb_data, wsiconcap_64_pb_data);
     }
     gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
 
@@ -1616,11 +1536,11 @@ main_capture_cb_capture_prepared(capture_options *capture_opts)
 }
 
 static void
-main_capture_cb_capture_update_started(capture_options *capture_opts)
+main_capture_cb_capture_update_started(capture_session *cap_session)
 {
     /* We've done this in "prepared" above, but it will be cleared while
        switching to the next multiple file. */
-    main_capture_set_main_window_title(capture_opts);
+    set_titlebar_for_capture_in_progress((capture_file *)cap_session->cf);
 
     main_set_for_capture_in_progress(TRUE);
     set_capture_if_dialog_for_capture_in_progress(TRUE);
@@ -1634,9 +1554,9 @@ main_capture_cb_capture_update_started(capture_options *capture_opts)
 }
 
 static void
-main_capture_cb_capture_update_finished(capture_options *capture_opts)
+main_capture_cb_capture_update_finished(capture_session *cap_session)
 {
-    capture_file *cf = capture_opts->cf;
+    capture_file *cf = (capture_file *)cap_session->cf;
     static GList *icon_list = NULL;
 
     /* The capture isn't stopping any more - it's stopped. */
@@ -1647,19 +1567,22 @@ main_capture_cb_capture_update_finished(capture_options *capture_opts)
         add_menu_recent_capture_file(cf->filename);
     }
 
-    /* Update the main window as appropriate */
-    main_update_for_unsaved_changes(cf);
-
     /* Enable menu items that make sense if you're not currently running
      a capture. */
     main_set_for_capture_in_progress(FALSE);
     set_capture_if_dialog_for_capture_in_progress(FALSE);
 
+    /* Update the main window as appropriate. This has to occur AFTER
+     * main_set_for_capture_in_progress() or else some of the menus are
+     * incorrectly disabled (see bug
+     * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8108) */
+    main_update_for_unsaved_changes(cf);
+
     /* Set up main window for a capture file. */
     main_set_for_capture_file(TRUE);
 
     if(icon_list == NULL) {
-        icon_list = icon_list_create(wsicon16_xpm, wsicon32_xpm, wsicon48_xpm, wsicon64_xpm);
+        icon_list = icon_list_create(wsicon_16_pb_data, wsicon_32_pb_data, wsicon_48_pb_data, wsicon_64_pb_data);
     }
     gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
 
@@ -1671,24 +1594,24 @@ main_capture_cb_capture_update_finished(capture_options *capture_opts)
 }
 
 static void
-main_capture_cb_capture_fixed_started(capture_options *capture_opts _U_)
+main_capture_cb_capture_fixed_started(capture_session *cap_session _U_)
 {
     /* Don't set up main window for a capture file. */
     main_set_for_capture_file(FALSE);
 }
 
 static void
-main_capture_cb_capture_fixed_finished(capture_options *capture_opts _U_)
+main_capture_cb_capture_fixed_finished(capture_session *cap_session _U_)
 {
 #if 0
-    capture_file *cf = capture_opts->cf;
+    capture_file *cf = (capture_file *)cap_session->cf;
 #endif
     static GList *icon_list = NULL;
 
     /* The capture isn't stopping any more - it's stopped. */
     capture_stopping = FALSE;
 
-    /*set_display_filename(cf);*/
+    /*set_titlebar_for_capture_file(cf);*/
 
     /* Enable menu items that make sense if you're not currently running
      a capture. */
@@ -1697,10 +1620,10 @@ main_capture_cb_capture_fixed_finished(capture_options *capture_opts _U_)
 
     /* Restore the standard title bar message */
     /* (just in case we have trouble opening the capture file). */
-    main_set_window_name("The Wireshark Network Analyzer");
+    set_titlebar_for_capture_file(NULL);
 
     if(icon_list == NULL) {
-        icon_list = icon_list_create(wsicon16_xpm, wsicon32_xpm, wsicon48_xpm, wsicon64_xpm);
+        icon_list = icon_list_create(wsicon_16_pb_data, wsicon_32_pb_data, wsicon_48_pb_data, wsicon_64_pb_data);
     }
     gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
 
@@ -1715,7 +1638,7 @@ main_capture_cb_capture_fixed_finished(capture_options *capture_opts _U_)
 }
 
 static void
-main_capture_cb_capture_stopping(capture_options *capture_opts _U_)
+main_capture_cb_capture_stopping(capture_session *cap_session _U_)
 {
     capture_stopping = TRUE;
     set_menus_for_capture_stopping();
@@ -1727,7 +1650,7 @@ main_capture_cb_capture_stopping(capture_options *capture_opts _U_)
 }
 
 static void
-main_capture_cb_capture_failed(capture_options *capture_opts _U_)
+main_capture_cb_capture_failed(capture_session *cap_session _U_)
 {
     static GList *icon_list = NULL;
 
@@ -1736,8 +1659,7 @@ main_capture_cb_capture_failed(capture_options *capture_opts _U_)
 
     /* the capture failed before the first packet was captured
        reset title, menus and icon */
-
-    main_set_window_name("The Wireshark Network Analyzer");
+    set_titlebar_for_capture_file(NULL);
 
     main_set_for_capture_in_progress(FALSE);
     set_capture_if_dialog_for_capture_in_progress(FALSE);
@@ -1745,7 +1667,7 @@ main_capture_cb_capture_failed(capture_options *capture_opts _U_)
     main_set_for_capture_file(FALSE);
 
     if(icon_list == NULL) {
-        icon_list = icon_list_create(wsicon16_xpm, wsicon32_xpm, wsicon48_xpm, wsicon64_xpm);
+        icon_list = icon_list_create(wsicon_16_pb_data, wsicon_32_pb_data, wsicon_48_pb_data, wsicon_64_pb_data);
     }
     gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
 
@@ -1761,7 +1683,7 @@ main_capture_cb_capture_failed(capture_options *capture_opts _U_)
 static void
 main_cf_cb_packet_selected(gpointer data)
 {
-    capture_file *cf = data;
+    capture_file *cf = (capture_file *)data;
 
     /* Display the GUI protocol tree and packet bytes.
       XXX - why do we dump core if we call "proto_tree_draw()"
@@ -1809,50 +1731,56 @@ main_cf_cb_field_unselected(capture_file *cf)
 static void
 main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
 {
+    capture_file *cf = (capture_file *)data;
     switch(event) {
+    case(cf_cb_file_opened):
+        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Opened");
+        fileset_file_opened(cf);
+        break;
     case(cf_cb_file_closing):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closing");
-        main_cf_cb_file_closing(data);
+        main_cf_cb_file_closing(cf);
         break;
     case(cf_cb_file_closed):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closed");
-        main_cf_cb_file_closed(data);
+        main_cf_cb_file_closed(cf);
+        fileset_file_closed();
         break;
     case(cf_cb_file_read_started):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read started");
-        main_cf_cb_file_read_started(data);
+        main_cf_cb_file_read_started(cf);
         break;
     case(cf_cb_file_read_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read finished");
-        main_cf_cb_file_read_finished(data);
+        main_cf_cb_file_read_finished(cf);
         break;
     case(cf_cb_file_reload_started):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload started");
-        main_cf_cb_file_read_started(data);
+        main_cf_cb_file_read_started(cf);
         break;
     case(cf_cb_file_reload_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload finished");
-        main_cf_cb_file_read_finished(data);
+        main_cf_cb_file_read_finished(cf);
         break;
     case(cf_cb_file_rescan_started):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Rescan started");
         break;
     case(cf_cb_file_rescan_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Rescan finished");
-        main_cf_cb_file_rescan_finished(data);
+        main_cf_cb_file_rescan_finished(cf);
         break;
     case(cf_cb_file_fast_save_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Fast save finished");
-        main_cf_cb_file_rescan_finished(data);
+        main_cf_cb_file_rescan_finished(cf);
         break;
     case(cf_cb_packet_selected):
-        main_cf_cb_packet_selected(data);
+        main_cf_cb_packet_selected(cf);
         break;
     case(cf_cb_packet_unselected):
-        main_cf_cb_packet_unselected(data);
+        main_cf_cb_packet_unselected(cf);
         break;
     case(cf_cb_field_unselected):
-        main_cf_cb_field_unselected(data);
+        main_cf_cb_field_unselected(cf);
         break;
     case(cf_cb_file_save_started):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save started");
@@ -1886,22 +1814,22 @@ main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
 
 #ifdef HAVE_LIBPCAP
 static void
-main_capture_callback(gint event, capture_options *capture_opts, gpointer user_data _U_)
+main_capture_callback(gint event, capture_session *cap_session, gpointer user_data _U_)
 {
 #ifdef HAVE_GTKOSXAPPLICATION
-    GtkOSXApplication *theApp;
+    GtkosxApplication *theApp;
 #endif
     switch(event) {
     case(capture_cb_capture_prepared):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared");
-        main_capture_cb_capture_prepared(capture_opts);
+        main_capture_cb_capture_prepared(cap_session);
         break;
     case(capture_cb_capture_update_started):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update started");
-        main_capture_cb_capture_update_started(capture_opts);
+        main_capture_cb_capture_update_started(cap_session);
 #ifdef HAVE_GTKOSXAPPLICATION
-        theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
-        gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsiconcap48_xpm));
+        theApp = (GtkosxApplication *)g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+        gtkosx_application_set_dock_icon_pixbuf(theApp, gdk_pixbuf_new_from_inline(-1, wsiconcap_48_pb_data, FALSE, NULL));
 #endif
         break;
     case(capture_cb_capture_update_continue):
@@ -1909,32 +1837,32 @@ main_capture_callback(gint event, capture_options *capture_opts, gpointer user_d
         break;
     case(capture_cb_capture_update_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update finished");
-        main_capture_cb_capture_update_finished(capture_opts);
+        main_capture_cb_capture_update_finished(cap_session);
         break;
     case(capture_cb_capture_fixed_started):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed started");
-        main_capture_cb_capture_fixed_started(capture_opts);
+        main_capture_cb_capture_fixed_started(cap_session);
         break;
     case(capture_cb_capture_fixed_continue):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed continue");
         break;
     case(capture_cb_capture_fixed_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed finished");
-        main_capture_cb_capture_fixed_finished(capture_opts);
+        main_capture_cb_capture_fixed_finished(cap_session);
         break;
     case(capture_cb_capture_stopping):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture stopping");
         /* Beware: this state won't be called, if the capture child
-         * closes the capturing on it's own! */
+         * closes the capturing on its own! */
 #ifdef HAVE_GTKOSXAPPLICATION
-        theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
-        gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsicon64_xpm));
+        theApp = (GtkosxApplication *)g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+        gtkosx_application_set_dock_icon_pixbuf(theApp, gdk_pixbuf_new_from_inline(-1, wsicon_64_pb_data, FALSE, NULL));
 #endif
-        main_capture_cb_capture_stopping(capture_opts);
+        main_capture_cb_capture_stopping(cap_session);
         break;
     case(capture_cb_capture_failed):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture failed");
-        main_capture_cb_capture_failed(capture_opts);
+        main_capture_cb_capture_failed(cap_session);
         break;
     default:
         g_warning("main_capture_callback: event %u unknown", event);
@@ -2147,7 +2075,7 @@ check_and_warn_user_startup(gchar *cf_name _U_)
 
 #ifdef _WIN32
   /* Warn the user if npf.sys isn't loaded. */
-  if (!stdin_capture && !cf_name && !npf_sys_is_running() && recent.privs_warn_if_no_npf && get_os_major_version() >= 6) {
+  if (!get_stdin_capture() && !cf_name && !npf_sys_is_running() && recent.privs_warn_if_no_npf && get_os_major_version() >= 6) {
     priv_warning_dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
       "The NPF driver isn't running.  You may have trouble\n"
       "capturing or listing interfaces.");
@@ -2201,12 +2129,12 @@ main(int argc, char *argv[])
   GtkWidget           *splash_win = NULL;
   GLogLevelFlags       log_flags;
   guint                go_to_packet = 0;
-  gboolean             jump_backwards = FALSE;
+  search_direction     jump_backwards = SD_FORWARD;
   dfilter_t           *jump_to_filter = NULL;
   int                  optind_initial;
   int                  status;
 #ifdef HAVE_GTKOSXAPPLICATION
-  GtkOSXApplication   *theApp;
+  GtkosxApplication   *theApp;
 #endif
 
 #ifdef HAVE_LIBPCAP
@@ -2218,21 +2146,27 @@ main(int argc, char *argv[])
 #else /* HAVE_LIBPCAP */
 #define OPTSTRING_B ""
 #endif  /* HAVE_LIBPCAP */
-
+#ifdef HAVE_PCAP_REMOTE
+#define OPTSTRING_A "A:"
+#else
+#define OPTSTRING_A ""
+#endif
 #ifdef HAVE_PCAP_CREATE
 #define OPTSTRING_I "I"
 #else
 #define OPTSTRING_I ""
 #endif
 
-#define OPTSTRING "a:b:" OPTSTRING_B "c:C:d:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pr:R:Ss:t:u:vw:X:y:z:"
+#define OPTSTRING "a:" OPTSTRING_A "b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pr:R:Ss:t:u:vw:X:y:Y:z:"
 
   static const char optstring[] = OPTSTRING;
 
+
   /* Set the C-language locale to the native environment. */
   setlocale(LC_ALL, "");
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
+  create_app_running_mutex();
 #endif /* _WIN32 */
 
   /*
@@ -2272,7 +2206,7 @@ main(int argc, char *argv[])
 
     if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){
       if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) {
-        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters!");
+        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters.");
         g_free(err_str);
       }
       airpcap_if_active = NULL;
@@ -2281,7 +2215,7 @@ main(int argc, char *argv[])
 
       /* select the first ad default (THIS SHOULD BE CHANGED) */
       airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
-          }
+    }
     break;
 #if 0
     /*
@@ -2301,13 +2235,8 @@ main(int argc, char *argv[])
 #endif
   }
 #endif /* HAVE_AIRPCAP */
-
-  /* Start windows sockets */
-  WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
 #endif  /* _WIN32 */
 
-  profile_store_persconffiles (TRUE);
-
   /* Assemble the compile-time version information string */
   comp_info_str = g_string_new("Compiled ");
 
@@ -2317,6 +2246,20 @@ main(int argc, char *argv[])
   runtime_info_str = g_string_new("Running ");
   get_runtime_version_info(runtime_info_str, get_gui_runtime_info);
 
+#ifdef _WIN32
+  ws_add_crash_info(PACKAGE " " VERSION "%s\n"
+         "\n"
+         "%s"
+         "\n"
+         "%s",
+      wireshark_svnversion, comp_info_str->str, runtime_info_str->str);
+
+  /* Start windows sockets */
+  WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
+#endif  /* _WIN32 */
+
+  profile_store_persconffiles (TRUE);
+
   /* Read the profile independent recent file.  We have to do this here so we can */
   /* set the profile before it can be set from the command line parameterts */
   recent_read_static(&rf_path, &rf_open_errno);
@@ -2351,7 +2294,7 @@ main(int argc, char *argv[])
        break;
       case 'D':        /* Print a list of capture devices and exit */
 #ifdef HAVE_LIBPCAP
-        if_list = capture_interface_list(&err, &err_str);
+        if_list = capture_interface_list(&err, &err_str,main_window_update);
         if (if_list == NULL) {
           switch (err) {
           case CANT_GET_INTERFACE_LIST:
@@ -2366,13 +2309,19 @@ main(int argc, char *argv[])
           }
           exit(2);
         }
+#ifdef _WIN32
+        create_console();
+#endif /* _WIN32 */
         capture_opts_print_interfaces(if_list);
         free_interface_list(if_list);
+#ifdef _WIN32
+        destroy_console();
+#endif /* _WIN32 */
         exit(0);
-#else
+#else /* HAVE_LIBPCAP */
         capture_option_specified = TRUE;
         arg_error = TRUE;
-#endif
+#endif /* HAVE_LIBPCAP */
         break;
       case 'h':        /* Print help and exit */
         print_usage(TRUE);
@@ -2381,7 +2330,7 @@ main(int argc, char *argv[])
 #ifdef _WIN32
       case 'i':
         if (strcmp(optarg, "-") == 0)
-          stdin_capture = TRUE;
+          set_stdin_capture(TRUE);
         break;
 #endif
       case 'P':        /* Path settings - change these before the Preferences and alike are processed */
@@ -2392,7 +2341,13 @@ main(int argc, char *argv[])
         }
         break;
       case 'v':        /* Show version and exit */
+#ifdef _WIN32
+        create_console();
+#endif
         show_version();
+#ifdef _WIN32
+        destroy_console();
+#endif
         exit(0);
         break;
       case 'X':
@@ -2496,14 +2451,14 @@ main(int argc, char *argv[])
 
   /* We might want to have component specific log levels later ... */
 
-  log_flags =
-            G_LOG_LEVEL_ERROR|
+  log_flags = (GLogLevelFlags)
+            (G_LOG_LEVEL_ERROR|
             G_LOG_LEVEL_CRITICAL|
             G_LOG_LEVEL_WARNING|
             G_LOG_LEVEL_MESSAGE|
             G_LOG_LEVEL_INFO|
             G_LOG_LEVEL_DEBUG|
-            G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION;
+            G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION);
 
   g_log_set_handler(NULL,
             log_flags,
@@ -2522,7 +2477,9 @@ main(int argc, char *argv[])
 
   /* Set the initial values in the capture options. This might be overwritten
      by preference settings and then again by the command line parameters. */
-  capture_opts_init(&global_capture_opts, &cfile);
+  capture_opts_init(&global_capture_opts);
+
+  capture_session_init(&global_capture_session, (void *)&cfile);
 #endif
 
   /* Initialize whatever we need to allocate colors for GTK+ */
@@ -2589,7 +2546,7 @@ main(int argc, char *argv[])
   prefs_to_capture_opts();
 
 /*#ifdef HAVE_LIBPCAP
-  fill_in_local_interfaces(&global_capture_opts);
+  fill_in_local_interfaces();
 #endif*/
   /* Now get our args */
   while ((opt = getopt(argc, argv, optstring)) != -1) {
@@ -2605,6 +2562,9 @@ main(int argc, char *argv[])
       case 'i':        /* Use interface x */
 #ifdef HAVE_PCAP_CREATE
       case 'I':        /* Capture in monitor mode, if available */
+#endif
+#ifdef HAVE_PCAP_REMOTE
+      case 'A':        /* Authentication */
 #endif
       case 's':        /* Set the snapshot (capture) length */
       case 'S':        /* "Sync" mode: used for following file ala tail -f */
@@ -2635,11 +2595,8 @@ main(int argc, char *argv[])
       case 'C':
         /* Configuration profile settings were already processed just ignore them this time*/
         break;
-      case 'd':
-        dfilter = optarg;
-        break;
       case 'j':        /* Search backwards for a matching packet from filter in option J */
-        jump_backwards = TRUE;
+        jump_backwards = SD_BACKWARD;
         break;
       case 'g':        /* Go to packet with the given packet number */
         go_to_packet = get_positive_int(optarg, "go to packet");
@@ -2664,8 +2621,8 @@ main(int argc, char *argv[])
 #endif
         break;
       case 'm':        /* Fixed-width font for the display */
-        g_free(prefs_p->gui_font_name);
-        prefs_p->gui_font_name = g_strdup(optarg);
+        g_free(prefs_p->gui_gtk2_font_name);
+        prefs_p->gui_gtk2_font_name = g_strdup(optarg);
         break;
       case 'n':        /* No name resolution */
         gbl_resolv_flags.mac_name = FALSE;
@@ -2749,8 +2706,9 @@ main(int argc, char *argv[])
           timestamp_set_type(TS_UTC_WITH_DATE);
         else {
           cmdarg_err("Invalid time stamp type \"%s\"", optarg);
-          cmdarg_err_cont("It must be \"r\" for relative, \"a\" for absolute,");
-          cmdarg_err_cont("\"ad\" for absolute with date, or \"d\" for delta.");
+          cmdarg_err_cont("It must be \"a\" for absolute, \"ad\" for absolute with date, \"d\" for delta,");
+          cmdarg_err_cont("\"dd\" for delta displayed, \"e\" for epoch, \"r\" for relative, \"u\" for UTC, ");
+          cmdarg_err_cont("or \"ud\" for UTC with date.");
           exit(1);
         }
         break;
@@ -2768,6 +2726,9 @@ main(int argc, char *argv[])
       case 'X':
           /* ext ops were already processed just ignore them this time*/
           break;
+      case 'Y':
+        dfilter = optarg;
+        break;
       case 'z':
         /* We won't call the init function for the stat this soon
            as it would disallow MATE's fields (which are registered
@@ -2809,7 +2770,14 @@ main(int argc, char *argv[])
          * file - yes, you could have "-r" as the last part of the command,
          * but that's a bit ugly.
          */
+#ifndef HAVE_GTKOSXAPPLICATION
+        /*
+         * For GTK+ Mac Integration, file name passed as free argument passed
+         * through grag-and-drop and opened twice sometimes causing crashes.
+         * Subject to report to GTK+ MAC.
+         */
         cf_name = g_strdup(argv[0]);
+#endif
       }
       argc--;
       argv++;
@@ -2832,9 +2800,9 @@ main(int argc, char *argv[])
     print_usage(FALSE);
     exit(1);
   }
-  
+
 #ifdef HAVE_LIBPCAP
-  fill_in_local_interfaces(&global_capture_opts);
+  fill_in_local_interfaces(main_window_update);
   if (start_capture && list_link_layer_types) {
     /* Specifying *both* is bogus. */
     cmdarg_err("You can't specify both -L and a live capture.");
@@ -2884,10 +2852,13 @@ main(int argc, char *argv[])
   }
 
   if (start_capture || list_link_layer_types) {
-    /* Did the user specify an interface to use? */
-    if (!capture_opts_trim_iface(&global_capture_opts,
-        (prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL)) {
-        exit(2);
+    /* We're supposed to do a live capture or get a list of link-layer
+       types for a live capture device; if the user didn't specify an
+       interface to use, pick a default. */
+    status = capture_opts_default_iface_if_necessary(&global_capture_opts,
+        ((prefs_p->capture_device) && (*prefs_p->capture_device != '\0')) ? get_if_name(prefs_p->capture_device) : NULL);
+    if (status != 0) {
+      exit(status);
     }
   }
 
@@ -2901,9 +2872,9 @@ main(int argc, char *argv[])
       device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
       if (device.selected) {
 #if defined(HAVE_PCAP_CREATE)
-        caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, &err_str);
+        caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, &err_str, main_window_update);
 #else
-        caps = capture_get_if_capabilities(device.name, FALSE, &err_str);
+        caps = capture_get_if_capabilities(device.name, FALSE, &err_str,main_window_update);
 #endif
         if (caps == NULL) {
           cmdarg_err("%s", err_str);
@@ -2914,11 +2885,17 @@ main(int argc, char *argv[])
           cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
           exit(2);
         }
+#ifdef _WIN32
+        create_console();
+#endif /* _WIN32 */
 #if defined(HAVE_PCAP_CREATE)
         capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
 #else
         capture_opts_print_if_capabilities(caps, device.name, FALSE);
 #endif
+#ifdef _WIN32
+        destroy_console();
+#endif /* _WIN32 */
         free_if_capabilities(caps);
       }
     }
@@ -2936,12 +2913,12 @@ main(int argc, char *argv[])
 
 #ifdef HAVE_LIBPCAP
   if ((global_capture_opts.num_selected == 0) &&
-      (prefs.capture_device != NULL)) {
+      ((prefs.capture_device != NULL) && (*prefs_p->capture_device != '\0'))) {
     guint i;
     interface_t device;
     for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
       device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
-      if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) {
+      if (!device.hidden && strstr(prefs.capture_device, device.name) != NULL) {
         device.selected = TRUE;
         global_capture_opts.num_selected++;
         global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
@@ -2950,6 +2927,13 @@ main(int argc, char *argv[])
       }
     }
   }
+  if (global_capture_opts.num_selected == 0 && global_capture_opts.all_ifaces->len == 1) {
+    interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, 0);
+    device.selected = TRUE;
+    global_capture_opts.num_selected++;
+    global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, 0);
+    g_array_insert_val(global_capture_opts.all_ifaces, 0, device);
+  }
 #endif
 
   /* disabled protocols as per configuration file */
@@ -2966,7 +2950,7 @@ main(int argc, char *argv[])
 #else
   gtk_rc_parse(rc_file);
   g_free(rc_file);
-  rc_file = get_persconffile_path(RC_FILE, FALSE, FALSE);
+  rc_file = get_persconffile_path(RC_FILE, FALSE);
   gtk_rc_parse(rc_file);
 #endif
   g_free(rc_file);
@@ -3041,15 +3025,6 @@ main(int argc, char *argv[])
 
   g_timeout_add(info_update_freq, resolv_update_cb, NULL);
 
-  if (dfilter) {
-    GtkWidget *filter_te;
-    filter_te = gtk_bin_get_child(GTK_BIN(g_object_get_data(G_OBJECT(top_level), E_DFILTER_CM_KEY)));
-    gtk_entry_set_text(GTK_ENTRY(filter_te), dfilter);
-
-    /* Run the display filter so it goes in effect. */
-    main_filter_packets(&cfile, dfilter, FALSE);
-  }
-
   /* If we were given the name of a capture file, read it in now;
      we defer it until now, so that, if we can't open it, and pop
      up an alert box, the alert box is more likely to come up on
@@ -3160,7 +3135,7 @@ main(int argc, char *argv[])
          to use for this capture. */
       if (global_capture_opts.ifaces->len == 0)
         collect_ifaces(&global_capture_opts);
-      if (capture_start(&global_capture_opts)) {
+      if (capture_start(&global_capture_opts, &global_capture_session,main_window_update)) {
         /* The capture started.  Open stat windows; we do so after creating
            the main window, to avoid GTK warnings, and after successfully
            opening the capture file, so we know we have something to compute
@@ -3188,15 +3163,25 @@ main(int argc, char *argv[])
 #endif /* HAVE_LIBPCAP */
   }
 
+  if (dfilter) {
+    GtkWidget *filter_te;
+    filter_te = gtk_bin_get_child(GTK_BIN(g_object_get_data(G_OBJECT(top_level), E_DFILTER_CM_KEY)));
+    gtk_entry_set_text(GTK_ENTRY(filter_te), dfilter);
+
+    /* Run the display filter so it goes in effect. */
+    main_filter_packets(&cfile, dfilter, FALSE);
+  }
+
+
   /* register our pid if we are being run from a U3 device */
   u3_register_pid();
 
   profile_store_persconffiles (FALSE);
 
 #ifdef HAVE_GTKOSXAPPLICATION
-  theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
-  gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsicon64_xpm));
-  gtk_osxapplication_ready(theApp);
+  theApp = (GtkosxApplication *)g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+  gtkosx_application_set_dock_icon_pixbuf(theApp, gdk_pixbuf_new_from_inline(-1, wsicon_64_pb_data, FALSE, NULL));
+  gtkosx_application_ready(theApp);
 #endif
 
   g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "Wireshark is up and ready to go");
@@ -3205,6 +3190,8 @@ main(int argc, char *argv[])
   gtk_iface_mon_start();
 #endif
 
+  software_update_init();
+
   /* we'll enter the GTK loop now and hand the control over to GTK ... */
   gtk_main();
   /* ... back from GTK, we're going down now! */
@@ -3228,6 +3215,8 @@ main(int argc, char *argv[])
   g_object_unref(theApp);
 #endif
 
+  software_update_cleanup();
+
   /* Shutdown windows sockets */
   WSACleanup();
 
@@ -3277,79 +3266,11 @@ WinMain (struct HINSTANCE__ *hInstance,
   /* RichEd20.DLL is needed for filter entries. */
   ws_load_library("riched20.dll");
 
-  has_console = FALSE;
-  console_wait = FALSE;
+  set_has_console(FALSE);
+  set_console_wait(FALSE);
   return main (__argc, __argv);
 }
 
-/* The code to create and desstroy console windows should not be necessary,
-   at least as I read the GLib source code, as it looks as if GLib is, on
-   Win32, *supposed* to create a console window into which to display its
-   output.
-
-   That doesn't happen, however.  I suspect there's something completely
-   broken about that code in GLib-for-Win32, and that it may be related
-   to the breakage that forces us to just call "printf()" on the message
-   rather than passing the message on to "g_log_default_handler()"
-   (which is the routine that does the aforementioned non-functional
-   console window creation).  */
-
-/*
- * If this application has no console window to which its standard output
- * would go, create one.
- */
-void
-create_console(void)
-{
-  if (stdin_capture) {
-    /* We've been handed "-i -". Don't mess with stdio. */
-    return;
-  }
-
-  if (!has_console) {
-    /* We have no console to which to print the version string, so
-       create one and make it the standard input, output, and error. */
-
-    /*
-     * See if we have an existing console (i.e. we were run from a
-     * command prompt)
-     */
-    if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
-      if (AllocConsole()) {
-        console_wait = TRUE;
-        SetConsoleTitle(_T("Wireshark Debug Console"));
-      } else {
-        return;   /* couldn't create console */
-      }
-    }
-
-    ws_freopen("CONIN$", "r", stdin);
-    ws_freopen("CONOUT$", "w", stdout);
-    ws_freopen("CONOUT$", "w", stderr);
-    fprintf(stdout, "\n");
-    fprintf(stderr, "\n");
-
-    /* Now register "destroy_console()" as a routine to be called just
-       before the application exits, so that we can destroy the console
-       after the user has typed a key (so that the console doesn't just
-       disappear out from under them, giving the user no chance to see
-       the message(s) we put in there). */
-    atexit(destroy_console);
-
-    /* Well, we have a console now. */
-    has_console = TRUE;
-  }
-}
-
-static void
-destroy_console(void)
-{
-  if (console_wait) {
-    printf("\n\nPress any key to exit\n");
-    _getch();
-  }
-  FreeConsole();
-}
 #endif /* _WIN32 */
 
 
@@ -3380,7 +3301,7 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
     /* the user wants a console or the application will terminate immediately */
     create_console();
   }
-  if (has_console) {
+  if (get_has_console()) {
     /* For some unknown reason, the above doesn't appear to actually cause
        anything to be sent to the standard output, so we'll just splat the
        message out directly, just to make sure it gets out. */
@@ -3573,7 +3494,7 @@ void main_widgets_rearrange(void) {
     if (second_pane_widget2 != NULL)
         gtk_paned_pack2(GTK_PANED(main_second_pane), second_pane_widget2, FALSE, FALSE);
 
-    gtk_container_add(GTK_CONTAINER(main_vbox), main_first_pane);
+    gtk_box_pack_start(GTK_BOX(main_vbox), main_first_pane, TRUE, TRUE, 0);
 
     /* welcome pane */
     gtk_box_pack_start(GTK_BOX(main_vbox), welcome_pane, TRUE, TRUE, 0);
@@ -3598,7 +3519,7 @@ void main_widgets_rearrange(void) {
 static void
 is_widget_visible(GtkWidget *widget, gpointer data)
 {
-    gboolean *is_visible = data;
+    gboolean *is_visible = ( gboolean *)data;
 
     if (!*is_visible) {
         if (gtk_widget_get_visible(widget))
@@ -3704,10 +3625,10 @@ static gboolean
 top_level_key_pressed_cb(GtkWidget *w _U_, GdkEventKey *event, gpointer user_data _U_)
 {
     if (event->keyval == GDK_F8) {
-        new_packet_list_next();
+        packet_list_next();
         return TRUE;
     } else if (event->keyval == GDK_F7) {
-        new_packet_list_prev();
+        packet_list_prev();
         return TRUE;
     } else if (event->state & NO_SHIFT_MOD_MASK) {
         return FALSE; /* Skip control, alt, and other modifiers */
@@ -3729,13 +3650,17 @@ top_level_key_pressed_cb(GtkWidget *w _U_, GdkEventKey *event, gpointer user_dat
 }
 
 static void
-create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
+create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p
+#if !defined(HAVE_IGE_MAC_INTEGRATION) && !defined (HAVE_GTKOSXAPPLICATION)
+                    _U_
+#endif
+                    )
 {
     GtkAccelGroup *accel;
 
     /* Main window */
     top_level = window_new(GTK_WINDOW_TOPLEVEL, "");
-    main_set_window_name("The Wireshark Network Analyzer");
+    set_titlebar_for_capture_file(NULL);
 
     gtk_widget_set_name(top_level, "main window");
     g_signal_connect(top_level, "delete_event", G_CALLBACK(main_window_delete_event_cb),
@@ -3747,7 +3672,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
 
     /* Vertical container for menu bar, toolbar(s), paned windows and progress/info box */
     main_vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);
-    gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
+
+       gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
     gtk_container_add(GTK_CONTAINER(top_level), main_vbox);
     gtk_widget_show(main_vbox);
 
@@ -3761,6 +3687,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
     gtk_window_add_accel_group(GTK_WINDOW(top_level), accel);
     gtk_widget_show(menubar);
 #if defined(HAVE_IGE_MAC_INTEGRATION) || defined(HAVE_GTKOSXAPPLICATION)
+    } else {
+    gtk_widget_hide(menubar);
     }
 #endif
 
@@ -3772,12 +3700,12 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
     filter_tb = filter_toolbar_new();
 
     /* Packet list */
-    pkt_scrollw = new_packet_list_create();
+    pkt_scrollw = packet_list_create();
     gtk_widget_set_size_request(pkt_scrollw, -1, pl_size);
     gtk_widget_show_all(pkt_scrollw);
 
     /* Tree view */
-    tv_scrollw = proto_tree_view_new(prefs_p, &tree_view_gbl);
+    tv_scrollw = proto_tree_view_new(&tree_view_gbl);
     gtk_widget_set_size_request(tv_scrollw, -1, tv_size);
     gtk_widget_show(tv_scrollw);
 
@@ -3845,21 +3773,6 @@ show_main_window(gboolean doing_work)
 #endif /* HAVE_AIRPCAP */
 }
 
-/* Fill in capture options with values from the preferences */
-void
-prefs_to_capture_opts(void)
-{
-#ifdef HAVE_LIBPCAP
-  /* Set promiscuous mode from the preferences setting. */
-  /* the same applies to other preferences settings as well. */
-    global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
-    global_capture_opts.use_pcapng                   = prefs.capture_pcap_ng;
-    global_capture_opts.show_info                    = prefs.capture_show_info;
-    global_capture_opts.real_time_mode               = prefs.capture_real_time;
-    auto_scroll_live                                 = prefs.capture_auto_scroll;
-#endif /* HAVE_LIBPCAP */
-}
-
 static void copy_global_profile (const gchar *profile_name)
 {
     char  *pf_dir_path, *pf_dir_path2, *pf_filename;
@@ -3962,8 +3875,8 @@ void change_configuration_profile (const gchar *profile_name)
     welcome_if_panel_reload();
 
     /* Recreate the packet list according to new preferences */
-    new_packet_list_recreate ();
-    cfile.cinfo.columns_changed = FALSE; /* Reset value */
+    packet_list_recreate ();
+    cfile.columns_changed = FALSE; /* Reset value */
     user_font_apply();
 
     /* Update menus with new recent values */