Don't include epan/emem.h twice.
[obnox/wireshark/wip.git] / gtk / main.c
index 3cab4f65dbef1fb0d5bf1bfa0d23fc08fe95f179..343708986fe28a802db95979c80a60e6db2d984d 100644 (file)
 #endif
 
 #ifdef NEED_STRERROR_H
-#include "strerror.h"
+#include "wsutil/strerror.h"
 #endif
 
-#ifdef NEED_GETOPT_H
-#include "getopt.h"
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#include "wsutil/wsgetopt.h"
 #endif
 
 #ifdef _WIN32 /* Needed for console I/O */
@@ -78,7 +80,6 @@
 #include <epan/tap.h>
 #include <epan/stat_cmd_args.h>
 #include <epan/uat.h>
-#include <epan/emem.h>
 #include <epan/column.h>
 
 /* general (not GTK specific) */
 #include "../color_filters.h"
 #include "../print.h"
 #include "../simple_dialog.h"
+#include "../main_statusbar.h"
 #include "../register.h"
 #include "../ringbuffer.h"
 #include "../ui_util.h"
 #include "../util.h"
 #include "../clopts_common.h"
+#include "../console_io.h"
 #include "../cmdarg_err.h"
 #include "../version_info.h"
 #include "../merge.h"
 #include "../alert_box.h"
-#include "../capture_ui_utils.h"
 #include "../log.h"
+#include "../u3.h"
 #include <wsutil/file_util.h>
 
-
 #ifdef HAVE_LIBPCAP
+#include "../capture_ui_utils.h"
 #include "../capture-pcap-util.h"
+#include "../capture_ifinfo.h"
 #include "../capture.h"
 #include "../capture_sync.h"
 #endif
 #include "../capture-wpcap.h"
 #include "../capture_wpcap_packet.h"
 #include <tchar.h> /* Needed for Unicode */
+#include <wsutil/unicode-utils.h>
 #include <commctrl.h>
+#include <shellapi.h>
 #endif /* _WIN32 */
 
 /* GTK related */
 #include "gtk/color_dlg.h"
 #include "gtk/filter_dlg.h"
 #include "gtk/uat_gui.h"
-#include "gtk/u3.h"
 #include "gtk/main.h"
 #include "gtk/main_airpcap_toolbar.h"
 #include "gtk/main_filter_toolbar.h"
 #include "gtk/menus.h"
+#include "gtk/macros_dlg.h"
 #include "gtk/main_packet_list.h"
-#include "gtk/main_statusbar.h"
 #include "gtk/main_statusbar_private.h"
 #include "gtk/main_toolbar.h"
 #include "gtk/main_welcome.h"
 #include "gtk/capture_dlg.h"
 #include "gtk/capture_if_dlg.h"
 #include "gtk/tap_dfilter_dlg.h"
+#include "gtk/prefs_column.h"
+#include "gtk/prefs_dlg.h"
+#include "gtk/proto_help.h"
 
 #ifdef HAVE_LIBPCAP
 #include "../image/wsicon16.xpm"
 #include "gtk/new_packet_list.h"
 #endif
 
+#ifdef HAVE_GTKOSXAPPLICATION
+#include <igemacintegration/gtkosxapplication.h>
+#endif
+
 /*
  * Files under personal and global preferences directories in which
  * GTK settings for Wireshark are stored.
 capture_file cfile;
 
 /* "exported" main widgets */
-GtkWidget   *top_level = NULL, *pkt_scrollw, *tree_view, *byte_nb_ptr;
+GtkWidget   *top_level = NULL, *pkt_scrollw, *tree_view_gbl, *byte_nb_ptr_gbl;
 
 /* placement widgets (can be a bit confusing, because of the many layout possibilities */
 static GtkWidget   *main_vbox, *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2;
@@ -202,9 +214,10 @@ int    airpcap_dll_ret_val = -1;
 #endif
 
 GString *comp_info_str, *runtime_info_str;
-gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */
 
-guint  tap_update_timer_id;
+static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */
+
+static guint  tap_update_timer_id;
 
 #ifdef _WIN32
 static gboolean has_console;   /* TRUE if app has console */
@@ -344,7 +357,11 @@ colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr)
             } else {
                 color_filters_set_tmp(filt_nr,filter, FALSE);
             }
+#ifdef NEW_PACKET_LIST
+            new_packet_list_colorize_packets();
+#else
             cf_colorize_packets(&cfile);
+#endif
         }
     }
 }
@@ -416,7 +433,7 @@ selected_ptree_info_cb(GtkWidget *widget _U_, gpointer data _U_)
             simple_dialog_set_cb(dialog, selected_ptree_info_answered_cb, (gpointer)proto_abbrev);
         } else {
             /* appologize to the user that the wiki page cannot be opened */
-            dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+            simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                     "%sCan't open Wireshark Wiki page of protocol \"%s\"%s\n"
                     "\n"
                     "This would open the \"%s\" related Wireshark Wiki page in your Web browser.\n"
@@ -481,7 +498,7 @@ selected_ptree_ref_cb(GtkWidget *widget _U_, gpointer data _U_)
             simple_dialog_set_cb(dialog, selected_ptree_ref_answered_cb, (gpointer)proto_abbrev);
         } else {
             /* appologize to the user that the wiki page cannot be opened */
-            dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+            simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                     "%sCan't open Wireshark filter reference page of protocol \"%s\"%s\n"
                     "\n"
                     "This would open the \"%s\" related Wireshark filter reference page in your Web browser.\n"
@@ -495,15 +512,81 @@ selected_ptree_ref_cb(GtkWidget *widget _U_, gpointer data _U_)
     }
 }
 
+static gboolean
+is_address_column (gint column)
+{
+  if (((cfile.cinfo.col_fmt[column] == COL_DEF_SRC) ||
+       (cfile.cinfo.col_fmt[column] == COL_RES_SRC) ||
+       (cfile.cinfo.col_fmt[column] == COL_DEF_DST) ||
+       (cfile.cinfo.col_fmt[column] == COL_RES_DST)) &&
+      strlen(cfile.cinfo.col_expr.col_expr_val[column]))
+  {
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+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));
+#ifdef NEW_PACKET_LIST
+    gint    column = new_packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
+#else
+    gint    column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY));
+#endif
+    gint    col;
+    frame_data *fdata;
+    GList      *addr_list = NULL;
+
+#ifdef NEW_PACKET_LIST
+    fdata = (frame_data *) new_packet_list_get_row_data(row);
+#else
+    fdata = (frame_data *) packet_list_get_row_data(row);
+#endif
+
+    if (fdata != NULL) {
+        epan_dissect_t edt;
+
+        if (!cf_read_frame (&cfile, fdata))
+            return NULL; /* error reading the frame */
+
+        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_fill_in_columns(&edt, TRUE, TRUE);
+
+       /* First check selected column */
+       if (is_address_column (column)) {
+         addr_list = g_list_append (addr_list, se_strdup_printf("%s", cfile.cinfo.col_expr.col_expr_val[column]));
+        }
+
+       for (col = 0; col < cfile.cinfo.num_cols; col++) {
+         /* Then check all columns except the selected */
+         if ((col != column) && (is_address_column (col))) {
+           addr_list = g_list_append (addr_list, se_strdup_printf("%s", cfile.cinfo.col_expr.col_expr_val[col]));
+         }
+       }
+
+        epan_dissect_cleanup(&edt);
+    }
+
+    return addr_list;
+}
+
 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));
+#ifdef NEW_PACKET_LIST
+    gint    column = new_packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
+#else
     gint    column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY));
+#endif
     frame_data *fdata;
     gchar      *buf=NULL;
-    int         err;
-    gchar       *err_info;
 
 #ifdef NEW_PACKET_LIST
     fdata = (frame_data *) new_packet_list_get_row_data(row);
@@ -514,25 +597,45 @@ get_filter_from_packet_list_row_and_column(gpointer data)
     if (fdata != NULL) {
         epan_dissect_t edt;
 
-        if (!wtap_seek_read(cfile.wth, fdata->file_off, &cfile.pseudo_header,
-                   cfile.pd, fdata->cap_len, &err, &err_info)) {
-            simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-                      cf_read_error_message(err, err_info), cfile.filename);
-            return NULL;
-        }
+        if (!cf_read_frame(&cfile, fdata))
+            return NULL; /* error reading the frame */
         /* proto tree, visible. We need a proto tree if there's custom columns */
         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_fill_in_columns(&edt, TRUE);
+        epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
 
-        if (strlen(cfile.cinfo.col_expr.col_expr[column]) != 0 &&
-            strlen(cfile.cinfo.col_expr.col_expr_val[column]) != 0) {
-            /* leak a little but safer than ep_ here*/
-            buf = se_strdup_printf("%s == %s", cfile.cinfo.col_expr.col_expr[column],
-                 cfile.cinfo.col_expr.col_expr_val[column]);
+        if ((cfile.cinfo.col_custom_occurrence[column]) ||
+            (strchr (cfile.cinfo.col_expr.col_expr_val[column], ',') == NULL))
+        {
+            /* Only construct the filter when a single occurrence is displayed
+             * otherwise we might end up with a filter like "ip.proto==1,6".
+             *
+             * Or do we want to be able to filter on multiple occurrences so that
+             * the filter might be calculated as "ip.proto==1 && ip.proto==6"
+             * instead?
+             */
+            if (strlen(cfile.cinfo.col_expr.col_expr[column]) != 0 &&
+                strlen(cfile.cinfo.col_expr.col_expr_val[column]) != 0) {
+                /* 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) {
+                        /* Protocol only */
+                        buf = se_strdup(cfile.cinfo.col_expr.col_expr[column]);
+                    } else if (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]);
+                    }
+                }
+                if (buf == NULL) {
+                    buf = se_strdup_printf("%s == %s", cfile.cinfo.col_expr.col_expr[column],
+                                           cfile.cinfo.col_expr.col_expr_val[column]);
+                }
+            }
         }
 
         epan_dissect_cleanup(&edt);
@@ -603,17 +706,25 @@ copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E acti
 
 
 /* mark as reference time frame */
-static void
+void
 set_frame_reftime(gboolean set, frame_data *frame, gint row) {
   if (row == -1)
     return;
   if (set) {
     frame->flags.ref_time=1;
+       cfile.ref_time_count++;
   } else {
     frame->flags.ref_time=0;
+    cfile.ref_time_count--;
   }
   cf_reftime_packets(&cfile);
 #ifdef NEW_PACKET_LIST
+  if (!frame->flags.ref_time && !frame->flags.passed_dfilter) {
+    new_packet_list_freeze();
+    cfile.displayed_count--;
+    new_packet_list_recreate_visible_rows();
+    new_packet_list_thaw();
+  }
   new_packet_list_queue_draw();
 #endif
 }
@@ -625,7 +736,12 @@ static void reftime_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_
     case(ESD_BTN_YES):
         timestamp_set_type(TS_RELATIVE);
         recent.gui_time_format  = TS_RELATIVE;
+#ifdef NEW_PACKET_LIST
+               cf_timestamp_auto_precision(&cfile);
+               new_packet_list_queue_draw();
+#else
         cf_change_time_formats(&cfile);
+#endif
         break;
     case(ESD_BTN_NO):
         break;
@@ -662,10 +778,10 @@ reftime_frame_cb(GtkWidget *w _U_, gpointer data _U_, REFTIME_ACTION_E action)
     }
     break;
   case REFTIME_FIND_NEXT:
-    find_previous_next_frame_with_filter("frame.ref_time", FALSE);
+    cf_find_packet_time_reference(&cfile, SD_FORWARD);
     break;
   case REFTIME_FIND_PREV:
-    find_previous_next_frame_with_filter("frame.ref_time", TRUE);
+    cf_find_packet_time_reference(&cfile, SD_BACKWARD);
     break;
   }
 }
@@ -673,20 +789,19 @@ reftime_frame_cb(GtkWidget *w _U_, gpointer data _U_, REFTIME_ACTION_E action)
 void
 find_next_mark_cb(GtkWidget *w _U_, gpointer data _U_, int action _U_)
 {
-    find_previous_next_frame_with_filter("frame.marked == TRUE", FALSE);
+    cf_find_packet_marked(&cfile, SD_FORWARD);
 }
 
 void
 find_prev_mark_cb(GtkWidget *w _U_, gpointer data _U_, int action _U_)
 {
-    find_previous_next_frame_with_filter("frame.marked == TRUE", TRUE);
+    cf_find_packet_marked(&cfile, SD_BACKWARD);
 }
 
 static void
 tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
 {
     field_info   *finfo;
-    gchar        *help_str = NULL;
     gchar         len_str[2+10+1+5+1]; /* ", {N} bytes\0",
                                           N < 4294967296 */
     gboolean      has_blurb = FALSE;
@@ -704,7 +819,7 @@ tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
          * Which byte view is displaying the current protocol tree
          * row's data?
          */
-        byte_view = get_notebook_bv_ptr(byte_nb_ptr);
+        byte_view = get_notebook_bv_ptr(byte_nb_ptr_gbl);
         if (byte_view == NULL)
             return;    /* none */
 
@@ -715,14 +830,15 @@ tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
         cf_unselect_field(&cfile);
         packet_hex_print(byte_view, byte_data,
                          cfile.current_frame, NULL, byte_len);
+        proto_help_menu_modify(sel, &cfile);
         return;
     }
     gtk_tree_model_get(model, &iter, 1, &finfo, -1);
     if (!finfo) return;
 
-    set_notebook_page(byte_nb_ptr, finfo->ds_tvb);
+    set_notebook_page(byte_nb_ptr_gbl, finfo->ds_tvb);
 
-    byte_view = get_notebook_bv_ptr(byte_nb_ptr);
+    byte_view = get_notebook_bv_ptr(byte_nb_ptr_gbl);
     byte_data = get_byte_view_data_and_length(byte_view, &byte_len);
     g_assert(byte_data != NULL);
 
@@ -748,11 +864,9 @@ tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
         }
         statusbar_pop_field_msg();     /* get rid of current help msg */
         if (length) {
-            help_str = g_strdup_printf(" %s (%s)%s",
+            statusbar_push_field_msg(" %s (%s)%s",
                     (has_blurb) ? finfo->hfinfo->blurb : finfo->hfinfo->name,
                     finfo->hfinfo->abbrev, len_str);
-            statusbar_push_field_msg(help_str);
-            g_free(help_str);
         } else {
             /*
              * Don't show anything if the field name is zero-length;
@@ -773,44 +887,63 @@ tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
              * with no pseudo-field being used, but that might also
              * require special checks for -1 to be added.
              */
-            statusbar_push_field_msg("");
+            statusbar_push_field_msg("%s", "");
         }
     }
     packet_hex_print(byte_view, byte_data, cfile.current_frame, finfo,
                      byte_len);
+    proto_help_menu_modify(sel, &cfile);
 }
 
 void collapse_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
   if (cfile.edt->tree)
-    collapse_all_tree(cfile.edt->tree, tree_view);
+    collapse_all_tree(cfile.edt->tree, tree_view_gbl);
 }
 
 void expand_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
   if (cfile.edt->tree)
-    expand_all_tree(cfile.edt->tree, tree_view);
+    expand_all_tree(cfile.edt->tree, tree_view_gbl);
+}
+
+void apply_as_custom_column_cb (GtkWidget *widget _U_, gpointer data _U_)
+{
+  if (cfile.finfo_selected) {
+    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 */
+#ifdef NEW_PACKET_LIST
+    new_packet_list_recreate ();
+#else
+    packet_list_recreate ();
+#endif
+    if (!prefs.gui_use_pref_save) {
+      prefs_main_write();
+    }
+    cfile.cinfo.columns_changed = FALSE; /* Reset value */
+  }
 }
 
 void expand_tree_cb(GtkWidget *widget _U_, gpointer data _U_) {
   GtkTreePath  *path;
 
-  path = tree_find_by_field_info(GTK_TREE_VIEW(tree_view), cfile.finfo_selected);
+  path = tree_find_by_field_info(GTK_TREE_VIEW(tree_view_gbl), cfile.finfo_selected);
   if(path) {
     /* the mouse position is at an entry, expand that one */
-    gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view), path, TRUE);
+    gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view_gbl), path, TRUE);
     gtk_tree_path_free(path);
   }
 }
 
 void resolve_name_cb(GtkWidget *widget _U_, gpointer data _U_) {
   if (cfile.edt->tree) {
-    guint32 tmp = g_resolv_flags;
-    g_resolv_flags = RESOLV_ALL;
-    proto_tree_draw(cfile.edt->tree, tree_view);
-    g_resolv_flags = tmp;
+    guint32 tmp = gbl_resolv_flags;
+    gbl_resolv_flags = RESOLV_ALL;
+    proto_tree_draw(cfile.edt->tree, tree_view_gbl);
+    gbl_resolv_flags = tmp;
   }
 }
 
-void
+static void
 main_set_for_capture_file(gboolean have_capture_file_in)
 {
     have_capture_file = have_capture_file_in;
@@ -1054,7 +1187,7 @@ print_usage(gboolean print_ver) {
   fprintf(output, "  -Q                       quit Wireshark after capturing\n");
   fprintf(output, "  -S                       update packet display when new packets are captured\n");
   fprintf(output, "  -l                       turn on automatic scrolling while -S is in use\n");
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
   fprintf(output, "  -B <buffer size>         size of kernel buffer (def: 1MB)\n");
 #endif
   fprintf(output, "  -y <link type>           link layer type (def: first appropriate)\n");
@@ -1087,8 +1220,11 @@ print_usage(gboolean print_ver) {
   fprintf(output, "User interface:\n");
   fprintf(output, "  -C <config profile>      start with specified configuration profile\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) 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, "  -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");
 
@@ -1136,26 +1272,46 @@ show_version(void)
 }
 
 /*
- * Report an error in command-line arguments.
- * Creates a console on Windows.
+ * 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
-cmdarg_err(const char *fmt, ...)
+vfprintf_stderr(const char *fmt, va_list ap)
 {
-  va_list ap;
-
 #ifdef _WIN32
   create_console();
 #endif
-  va_start(ap, fmt);
-  fprintf(stderr, "wireshark: ");
   vfprintf(stderr, fmt, ap);
-  fprintf(stderr, "\n");
+}
+
+void
+fprintf_stderr(const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start(ap, fmt);
+  vfprintf_stderr(fmt, ap);
   va_end(ap);
 }
 
+/*
+ * Report an error in command-line arguments.
+ * Creates a console on Windows.
+ */
+void
+cmdarg_err(const char *fmt, ...)
+{
+  va_list ap;
+
+  fprintf_stderr("wireshark: ");
+  va_start(ap, fmt);
+  vfprintf_stderr(fmt, ap);
+  va_end(ap);
+  fprintf_stderr("\n");
+}
+
 /*
  * Report additional information for an error in command-line arguments.
  * Creates a console on Windows.
@@ -1167,23 +1323,18 @@ 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);
 }
 
-#if defined(_WIN32) || ! defined USE_THREADS
 /*
    Once every 3 seconds we get a callback here which we use to update
-   the tap extensions. Since Gtk1 is single threaded we dont have to
-   worry about any locking or critical regions.
+   the tap extensions. 
  */
 static gboolean
-update_cb(gpointer data _U_)
+tap_update_cb(gpointer data _U_)
 {
        draw_tap_listeners(FALSE);
        return TRUE;
@@ -1193,77 +1344,65 @@ update_cb(gpointer data _U_)
 void reset_tap_update_timer(void)
 {
     g_source_remove(tap_update_timer_id);
-    tap_update_timer_id = g_timeout_add(prefs.tap_update_interval, update_cb, NULL);
+    tap_update_timer_id = g_timeout_add(prefs.tap_update_interval, tap_update_cb, NULL);
 }
 
-#else
-
-/* if these three functions are copied to gtk1 Wireshark, since gtk1 does not
-   use threads all update_thread_mutex can be dropped and protect/unprotect
-   would just be empty functions.
-
-   This allows gtk2-rpcstat.c and friends to be copied unmodified to
-   gtk1-wireshark and it will just work.
- */
-static GStaticMutex update_thread_mutex = G_STATIC_MUTEX_INIT;
-gpointer
-update_thread(gpointer data _U_)
-{
-    while(1){
-        GTimeVal tv1, tv2;
-        g_get_current_time(&tv1);
-        g_static_mutex_lock(&update_thread_mutex);
-        gdk_threads_enter();
-        draw_tap_listeners(FALSE);
-        gdk_threads_leave();
-        g_static_mutex_unlock(&update_thread_mutex);
-        g_thread_yield();
-        g_get_current_time(&tv2);
-
-        /* Assuming it took less than configured time to update tap listeners... */
-        if( (tv1.tv_sec * 1000000 + tv1.tv_usec + prefs.tap_update_interval * 1000) >
-            (tv2.tv_sec * 1000000 + tv2.tv_usec) ){
-            /* Wait for remainder of configured time */
-            g_usleep((tv1.tv_sec * 1000000 + tv1.tv_usec + prefs.tap_update_interval * 1000) -
-                     (tv2.tv_sec * 1000000 + tv2.tv_usec));
-        }
-
-        return NULL;
-}
-#endif
 void
 protect_thread_critical_region(void)
 {
-#if !defined(_WIN32) && defined USE_THREADS
-    g_static_mutex_lock(&update_thread_mutex);
-#endif
+       /* 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)
 {
-#if !defined(_WIN32) && defined USE_THREADS
-    g_static_mutex_unlock(&update_thread_mutex);
-#endif
+       /* 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.
+ */
+
+static gboolean
+resolv_update_cb(gpointer data _U_)
+{
+  /* Anything new show up? */
+  if (host_name_lookup_process(NULL)) {
+    if (pkt_scrollw->window)
+       gdk_window_invalidate_rect(pkt_scrollw->window, NULL, TRUE);
+    if (tv_scrollw->window)
+       gdk_window_invalidate_rect(tv_scrollw->window, NULL, TRUE);
+  }
+
+  /* Always check. Even if we don't do async lookups we could still get
+     passive updates, e.g. from DNS packets. */
+  return TRUE;
 }
 
-/* Set the file name in the name for the main window and in the name for the main window's icon. */
+
+/* Set main_window_name and it's icon title to the capture filename */
 static void
 set_display_filename(capture_file *cf)
 {
-  gchar       *win_name;
+  gchar *window_name;
 
-  if (!cf->is_tempfile && cf->filename) {
-    /* Add this filename to the list of recent files in the "Recent Files" submenu */
-    add_menu_recent_capture_file(cf->filename);
+  if (cf->filename) {
+    window_name = g_strdup_printf("%s", cf_get_display_name(cf));
+    set_main_window_name(window_name);
+    g_free(window_name);
+  } else {
+    set_main_window_name("The Wireshark Network Analyzer");
   }
-
-  /* window title */
-  win_name = g_strdup_printf("%s - Wireshark", cf_get_display_name(cf));
-  set_main_window_name(win_name);
-  g_free(win_name);
 }
 
-GtkWidget           *close_dlg = NULL;
+static GtkWidget           *close_dlg = NULL;
 
 static void
 priv_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)
@@ -1328,7 +1467,7 @@ main_cf_cb_file_closed(capture_file *cf _U_)
 
 
 static void
-main_cf_cb_file_read_start(capture_file *cf _U_)
+main_cf_cb_file_read_started(capture_file *cf _U_)
 {
   tap_dfilter_dlg_update();
 
@@ -1339,6 +1478,17 @@ main_cf_cb_file_read_start(capture_file *cf _U_)
 static void
 main_cf_cb_file_read_finished(capture_file *cf)
 {
+    gchar *dir_path;
+
+    if (!cf->is_tempfile && cf->filename) {
+        /* Add this filename to the list of recent files in the "Recent Files" submenu */
+        add_menu_recent_capture_file(cf->filename);
+
+        /* Remember folder for next Open dialog and save it in recent */
+       dir_path = get_dirname(g_strdup(cf->filename));
+        set_last_open_dir(dir_path);
+        g_free(dir_path);
+    }
     set_display_filename(cf);
 
     /* Enable menu items that make sense if you have a capture file you've
@@ -1349,7 +1499,8 @@ main_cf_cb_file_read_finished(capture_file *cf)
     set_menus_for_captured_packets(TRUE);
 }
 
-GList *icon_list_create(
+#ifdef HAVE_LIBPCAP
+static GList *icon_list_create(
     const char **icon16_xpm,
     const char **icon32_xpm,
     const char **icon48_xpm,
@@ -1389,22 +1540,25 @@ GList *icon_list_create(
   return icon_list;
 }
 
-#ifdef HAVE_LIBPCAP
 static void
-main_capture_cb_capture_prepared(capture_options *capture_opts)
+main_capture_set_main_window_title(capture_options *capture_opts)
 {
-    gchar *title;
-    static GList *icon_list = NULL;
-
+    GString *title = g_string_new("");
 
+    g_string_append(title, "Capturing ");
     if(capture_opts->iface) {
-        title = g_strdup_printf("%s: Capturing - Wireshark",
-                               get_iface_description(capture_opts));
-    } else {
-        title = g_strdup_printf("Capturing - Wireshark");
+        g_string_append_printf(title, "from %s ", cf_get_tempfile_source(capture_opts->cf));
     }
-    set_main_window_name(title);
-    g_free(title);
+    set_main_window_name(title->str);
+    g_string_free(title, TRUE);
+}
+
+static void
+main_capture_cb_capture_prepared(capture_options *capture_opts)
+{
+    static GList *icon_list = NULL;
+
+    main_capture_set_main_window_title(capture_opts);
 
     if(icon_list == NULL) {
         icon_list = icon_list_create(wsiconcap16_xpm, wsiconcap32_xpm, wsiconcap48_xpm, NULL);
@@ -1423,18 +1577,9 @@ main_capture_cb_capture_prepared(capture_options *capture_opts)
 static void
 main_capture_cb_capture_update_started(capture_options *capture_opts)
 {
-    gchar *title;
-
     /* We've done this in "prepared" above, but it will be cleared while
        switching to the next multiple file. */
-    if(capture_opts->iface) {
-        title = g_strdup_printf("%s: Capturing - Wireshark",
-                               get_iface_description(capture_opts));
-    } else {
-        title = g_strdup_printf("Capturing - Wireshark");
-    }
-    set_main_window_name(title);
-    g_free(title);
+    main_capture_set_main_window_title(capture_opts);
 
     set_menus_for_capture_in_progress(TRUE);
     set_capture_if_dialog_for_capture_in_progress(TRUE);
@@ -1453,6 +1598,10 @@ main_capture_cb_capture_update_finished(capture_options *capture_opts)
     capture_file *cf = capture_opts->cf;
     static GList *icon_list = NULL;
 
+    if (!cf->is_tempfile && cf->filename) {
+        /* Add this filename to the list of recent files in the "Recent Files" submenu */
+        add_menu_recent_capture_file(cf->filename);
+    }
     set_display_filename(cf);
 
     /* Enable menu items that make sense if you're not currently running
@@ -1527,7 +1676,7 @@ main_cf_cb_packet_selected(gpointer data)
 {
     capture_file *cf = data;
 
-    /* Display the GUI protocol tree and hex dump.
+    /* Display the GUI protocol tree and packet bytes.
       XXX - why do we dump core if we call "proto_tree_draw()"
       before calling "add_byte_views()"? */
     add_main_byte_views(cf->edt);
@@ -1537,7 +1686,7 @@ main_cf_cb_packet_selected(gpointer data)
      * highlight the field that is found in the tree and hex displays. */
     if((cfile.string || cfile.hex) && cfile.search_pos != 0) {
         highlight_field(cf->edt->tvb, cfile.search_pos,
-                        (GtkTreeView *)tree_view, cf->edt->tree);
+                        (GtkTreeView *)tree_view_gbl, cf->edt->tree);
         cfile.search_pos = 0; /* Reset the position */
     }
 
@@ -1562,8 +1711,9 @@ main_cf_cb_field_unselected(capture_file *cf)
 }
 
 static void
-main_cf_cb_file_safe_reload_finished(gpointer data _U_)
+main_cf_cb_file_save_reload_finished(gpointer data _U_)
 {
+    set_display_filename(&cfile);
     set_menus_for_capture_file(&cfile);
 }
 
@@ -1579,9 +1729,9 @@ main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closed");
         main_cf_cb_file_closed(data);
         break;
-    case(cf_cb_file_read_start):
-        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read start");
-        main_cf_cb_file_read_start(data);
+    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);
         break;
     case(cf_cb_file_read_finished):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read finished");
@@ -1596,18 +1746,18 @@ main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
     case(cf_cb_field_unselected):
         main_cf_cb_field_unselected(data);
         break;
-    case(cf_cb_file_safe_started):
-        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: safe started");
+    case(cf_cb_file_save_started):
+        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save started");
         break;
-    case(cf_cb_file_safe_finished):
-        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: safe finished");
+    case(cf_cb_file_save_finished):
+        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save finished");
         break;
-    case(cf_cb_file_safe_reload_finished):
-        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: reload finished");
-        main_cf_cb_file_safe_reload_finished(data);
+    case(cf_cb_file_save_reload_finished):
+        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload finished");
+        main_cf_cb_file_save_reload_finished(data);
         break;
-    case(cf_cb_file_safe_failed):
-        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: safe failed");
+    case(cf_cb_file_save_failed):
+        g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save failed");
         break;
     default:
         g_warning("main_cf_callback: event %u unknown", event);
@@ -1619,6 +1769,9 @@ main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
 static void
 main_capture_callback(gint event, capture_options *capture_opts, gpointer user_data _U_)
 {
+#ifdef HAVE_GTKOSXAPPLICATION
+    GtkOSXApplication *theApp;
+#endif
     switch(event) {
     case(capture_cb_capture_prepared):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared");
@@ -1627,6 +1780,10 @@ main_capture_callback(gint event, capture_options *capture_opts, gpointer user_d
     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);
+#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));
+#endif
         break;
     case(capture_cb_capture_update_continue):
         /*g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update continue");*/
@@ -1650,6 +1807,10 @@ main_capture_callback(gint event, capture_options *capture_opts, gpointer user_d
         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! */
+#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));
+#endif
         break;
     default:
         g_warning("main_capture_callback: event %u unknown", event);
@@ -1658,10 +1819,24 @@ main_capture_callback(gint event, capture_options *capture_opts, gpointer user_d
 }
 #endif
 
+static void
+get_gtk_compiled_info(GString *str)
+{
+  g_string_append(str, "with ");
+  g_string_append_printf(str,
+#ifdef GTK_MAJOR_VERSION
+                    "GTK+ %d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION,
+                    GTK_MICRO_VERSION);
+#else
+                    "GTK+ (version unknown)");
+#endif
+  g_string_append(str, ", ");
+}
+
 static void
 get_gui_compiled_info(GString *str)
 {
-  get_epan_compiled_version_info(str);
+  epan_get_compiled_version_info(str);
 
   g_string_append(str, ", ");
 #ifdef HAVE_LIBPORTAUDIO
@@ -1681,11 +1856,16 @@ get_gui_compiled_info(GString *str)
 #else
   g_string_append(str, "without AirPcap");
 #endif
+#ifndef NEW_PACKET_LIST
+  g_string_append(str, ", with old_packet_list");
+#endif
 }
 
 static void
 get_gui_runtime_info(GString *str)
 {
+  epan_get_runtime_version_info(str);
+
 #ifdef HAVE_AIRPCAP
   g_string_append(str, ", ");
   get_runtime_airpcap_version(str);
@@ -1695,7 +1875,6 @@ get_gui_runtime_info(GString *str)
     g_string_append(str, ", ");
     u3_runtime_info(str);
   }
-
 }
 
 static e_prefs *
@@ -1708,10 +1887,10 @@ read_configuration_files(char **gdp_path, char **dp_path)
   char                *gpf_path, *pf_path;
   char                *cf_path, *df_path;
   int                  pf_open_errno, pf_read_errno;
-  e_prefs             *prefs;
+  e_prefs             *prefs_p;
 
   /* Read the preference files. */
-  prefs = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
+  prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
                      &pf_open_errno, &pf_read_errno, &pf_path);
 
   if (gpf_path != NULL) {
@@ -1743,7 +1922,7 @@ read_configuration_files(char **gdp_path, char **dp_path)
 
 #ifdef _WIN32
   /* if the user wants a console to be always there, well, we should open one for him */
-  if (prefs->gui_console_open == console_open_always) {
+  if (prefs_p->gui_console_open == console_open_always) {
     create_console();
   }
 #endif
@@ -1798,9 +1977,50 @@ read_configuration_files(char **gdp_path, char **dp_path)
     *dp_path = NULL;
   }
 
-  return prefs;
+  return prefs_p;
 }
 
+/*  Check if there's something important to tell the user during startup.
+ *  We want to do this *after* showing the main window so that any windows
+ *  we pop up will be above the main window.
+ */
+static void
+#ifdef _WIN32
+check_and_warn_user_startup(gchar *cf_name)
+#else
+check_and_warn_user_startup(gchar *cf_name _U_)
+#endif
+{
+  gchar               *cur_user, *cur_group;
+  gpointer             priv_warning_dialog;
+
+  /* Tell the user not to run as root. */
+  if (running_with_special_privs() && recent.privs_warn_if_elevated) {
+    cur_user = get_cur_username();
+    cur_group = get_cur_groupname();
+    priv_warning_dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+      "Running as user \"%s\" and group \"%s\".\n"
+      "This could be dangerous.", cur_user, cur_group);
+    g_free(cur_user);
+    g_free(cur_group);
+    simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
+    simple_dialog_set_cb(priv_warning_dialog, priv_warning_dialog_cb, NULL);
+  }
+
+#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) {
+    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.");
+    simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
+    simple_dialog_set_cb(priv_warning_dialog, npf_warning_dialog_cb, NULL);
+  }
+#endif
+
+}
+
+
 /* And now our feature presentation... [ fade to music ] */
 int
 main(int argc, char *argv[])
@@ -1808,14 +2028,15 @@ main(int argc, char *argv[])
   char                *init_progfile_dir_error;
   char                *s;
   int                  opt;
-  extern char         *optarg;
   gboolean             arg_error = FALSE;
 
-  extern int           splash_register_freq;  /* Found in about_dlg.c */
+  extern int           info_update_freq;  /* Found in about_dlg.c. */
   const gchar         *filter;
 
 #ifdef _WIN32
   WSADATA             wsaData;
+  LPWSTR              *wc_argv;
+  int                  wc_argc, i;
 #endif  /* _WIN32 */
 
   char                *rf_path;
@@ -1825,46 +2046,69 @@ main(int argc, char *argv[])
 #ifdef HAVE_LIBPCAP
   gboolean             start_capture = FALSE;
   gboolean             list_link_layer_types = FALSE;
+  GList               *if_list;
+  gchar               *err_str;
 #else
   gboolean             capture_option_specified = FALSE;
+#ifdef _WIN32
+#ifdef HAVE_AIRPCAP
+  gchar               *err_str;
+#endif
+#endif
 #endif
   gint                 pl_size = 280, tv_size = 95, bv_size = 75;
-  gchar               *rc_file, *cf_name = NULL, *rfilter = NULL;
+  gchar               *rc_file, *cf_name = NULL, *rfilter = NULL, *jfilter = NULL;
   dfilter_t           *rfcode = NULL;
   gboolean             rfilter_parse_failed = FALSE;
-  e_prefs             *prefs;
+  e_prefs             *prefs_p;
   char                 badopt;
   GtkWidget           *splash_win = NULL;
-  gpointer             priv_warning_dialog;
   GLogLevelFlags       log_flags;
   guint                go_to_packet = 0;
+  gboolean             jump_backwards = FALSE;
+  dfilter_t           *jump_to_filter = NULL;
   int                  optind_initial;
   int                  status;
-  gchar               *cur_user, *cur_group;
-
-#ifdef _WIN32
-#ifdef HAVE_AIRPCAP
-  char                 *err_str;
-#endif
+#ifdef HAVE_GTKOSXAPPLICATION
+  GtkOSXApplication   *theApp;
 #endif
 
-#define OPTSTRING_INIT "a:b:c:C:Df:g:Hhi:kK:lLm:nN:o:P:pQr:R:Ss:t:vw:X:y:z:"
+#ifdef HAVE_LIBPCAP
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
+#define OPTSTRING_B "B:"
+#else
+#define OPTSTRING_B ""
+#endif  /* _WIN32 or HAVE_PCAP_CREATE */
+#else /* HAVE_LIBPCAP */
+#define OPTSTRING_B ""
+#endif  /* HAVE_LIBPCAP */
 
-#if defined HAVE_LIBPCAP && defined _WIN32
-#define OPTSTRING_WIN32 "B:"
+#ifdef HAVE_PCAP_CREATE
+#define OPTSTRING_I "I"
 #else
-#define OPTSTRING_WIN32 ""
+#define OPTSTRING_I ""
 #endif
 
-  char optstring[sizeof(OPTSTRING_INIT) + sizeof(OPTSTRING_WIN32) - 1] =
-    OPTSTRING_INIT OPTSTRING_WIN32;
+#define OPTSTRING "a:b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:"
+
+  static const char optstring[] = OPTSTRING;
+
+#ifdef _WIN32
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_strdup(utf_16to8(wc_argv[i]));
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+#endif /* _WIN32 */
 
   /*
    * Get credential information for later use, and drop privileges
    * before doing anything else.
    * Let the user know if anything happened.
    */
-  get_credential_info();
+  init_process_policies();
   relinquish_special_privs_perm();
 
   /*
@@ -1932,20 +2176,12 @@ main(int argc, char *argv[])
   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 ");
 
-  g_string_append(comp_info_str, "with ");
-  g_string_append_printf(comp_info_str,
-#ifdef GTK_MAJOR_VERSION
-                    "GTK+ %d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION,
-                    GTK_MICRO_VERSION);
-#else
-                    "GTK+ (version unknown)");
-#endif
-  g_string_append(comp_info_str, ", ");
-
-  get_compiled_version_info(comp_info_str, get_gui_compiled_info);
+  get_compiled_version_info(comp_info_str, get_gtk_compiled_info, get_gui_compiled_info);
 
   /* Assemble the run-time version information string */
   runtime_info_str = g_string_new("Running ");
@@ -2019,7 +2255,24 @@ main(int argc, char *argv[])
 
   /* Init the "Open file" dialog directory */
   /* (do this after the path settings are processed) */
-  set_last_open_dir(get_persdatafile_dir());
+
+  /* Read the profile dependent (static part) of the recent file. */
+  /* Only the static part of it will be read, as we don't have the gui now to fill the */
+  /* recent lists which is done in the dynamic part. */
+  /* We have to do this already here, so command line parameters can overwrite these values. */
+  recent_read_profile_static(&rf_path, &rf_open_errno);
+  if (rf_path != NULL && rf_open_errno != 0) {
+    simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+                 "Could not open recent file\n\"%s\": %s.",
+                 rf_path, strerror(rf_open_errno));
+  }
+
+  if (recent.gui_fileopen_remembered_dir &&
+      test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
+    set_last_open_dir(recent.gui_fileopen_remembered_dir);
+  } else {
+    set_last_open_dir(get_persdatafile_dir());
+  }
 
   /* Set getopt index back to initial value, so it will start with the
      first command line parameter again.  Also reset opterr to 1, so that
@@ -2111,18 +2364,16 @@ 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);
-
-  global_capture_opts.snaplen             = MIN_PACKET_SIZE;
-  global_capture_opts.has_ring_num_files  = TRUE;
 #endif
 
   /* Initialize whatever we need to allocate colors for GTK+ */
   colors_init();
 
-  /* Non-blank filter means we're remote. Throttle splash screen updates. */
+  /* Non-blank filter means we're remote. Throttle splash screen and resolution updates. */
   filter = get_conn_cfilter();
-  if ( *filter != '\0' )
-    splash_register_freq = 1000;  /* Milliseconds */
+  if ( *filter != '\0' ) {
+    info_update_freq = 1000;  /* Milliseconds */
+  }
 
   /* We won't come till here, if we had a "console only" command line parameter. */
   splash_win = splash_new("Loading Wireshark ...");
@@ -2167,41 +2418,17 @@ main(int argc, char *argv[])
      We must do that before we read the preferences as well. */
   prefs_register_modules();
 
-  prefs = read_configuration_files (&gdp_path, &dp_path);
+  prefs_p = read_configuration_files (&gdp_path, &dp_path);
+  /* Removed thread code:
+   * http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027
+   */
 
-  /* multithread support currently doesn't seem to work in win32 gtk2.0.6 */
-#if !defined(_WIN32) && defined(G_THREADS_ENABLED) && defined USE_THREADS
-  {
-      GThread *ut;
-      g_thread_init(NULL);
-      gdk_threads_init();
-      ut=g_thread_create(update_thread, NULL, FALSE, NULL);
-      g_thread_set_priority(ut, G_THREAD_PRIORITY_LOW);
-  }
-#else  /* !_WIN32 && G_THREADS_ENABLED && USE_THREADS */
   /* this is to keep tap extensions updating once every 3 seconds */
-  tap_update_timer_id = g_timeout_add(prefs->tap_update_interval, update_cb, NULL);
-#endif /* !_WIN32 && G_THREADS_ENABLED && USE_THREADS */
-
-#if HAVE_GNU_ADNS || HAVE_C_ARES
-  g_timeout_add(750, host_name_lookup_process, NULL);
-#endif
+  tap_update_timer_id = g_timeout_add(prefs_p->tap_update_interval, tap_update_cb, NULL);
 
   splash_update(RA_CONFIGURATION, NULL, (gpointer)splash_win);
-
-
-  /* Read the profile dependent (static part) of the recent file. */
-  /* Only the static part of it will be read, as we don't have the gui now to fill the */
-  /* recent lists which is done in the dynamic part. */
-  /* We have to do this already here, so command line parameters can overwrite these values. */
-  recent_read_profile_static(&rf_path, &rf_open_errno);
-  if (rf_path != NULL && rf_open_errno != 0) {
-    simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
-                 "Could not open recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
-  }
-
-  init_cap_file(&cfile);
+  proto_help_init();
+  cap_file_init(&cfile);
 
   /* Fill in capture options with values from the preferences */
   prefs_to_capture_opts();
@@ -2218,14 +2445,17 @@ main(int argc, char *argv[])
       case 'H':        /* Hide capture info dialog box */
       case 'i':        /* Use interface xxx */
       case 'p':        /* Don't capture in promiscuous mode */
+#ifdef HAVE_PCAP_CREATE
+      case 'I':        /* Capture in monitor mode, if available */
+#endif
       case 'Q':        /* Quit after capture (just capture to file) */
       case 's':        /* Set the snapshot (capture) length */
       case 'S':        /* "Sync" mode: used for following file ala tail -f */
       case 'w':        /* Write to capture file xxx */
       case 'y':        /* Set the pcap data link type */
-#ifdef _WIN32
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
       case 'B':        /* Buffer size */
-#endif /* _WIN32 */
+#endif /* _WIN32 or HAVE_PCAP_CREATE */
 #ifdef HAVE_LIBPCAP
         status = capture_opts_add_opt(&global_capture_opts, opt, optarg,
                                       &start_capture);
@@ -2250,16 +2480,37 @@ main(int argc, char *argv[])
        break;
       case 'D':        /* Print a list of capture devices and exit */
 #ifdef HAVE_LIBPCAP
-        capture_opts_list_interfaces(FALSE);
+        if_list = capture_interface_list(&err, &err_str);
+        if (if_list == NULL) {
+          switch (err) {
+          case CANT_GET_INTERFACE_LIST:
+            cmdarg_err("%s", err_str);
+            g_free(err_str);
+            break;
+
+          case NO_INTERFACES_FOUND:
+            cmdarg_err("There are no interfaces on which a capture can be done");
+            break;
+          }
+          exit(2);
+        }
+        capture_opts_print_interfaces(if_list);
+        free_interface_list(if_list);
         exit(0);
 #else
         capture_option_specified = TRUE;
         arg_error = TRUE;
 #endif
         break;
-      case 'g':        /* Go to packet */
+      case 'j':        /* Search backwards for a matching packet from filter in option J */
+        jump_backwards = TRUE;
+        break;
+      case 'g':        /* Go to packet with the given packet number */
         go_to_packet = get_positive_int(optarg, "go to packet");
         break;
+      case 'J':        /* Jump to the first packet which matches the filter criteria */
+        jfilter = optarg;
+        break;
       case 'l':        /* Automatic scrolling in live capture mode */
 #ifdef HAVE_LIBPCAP
         auto_scroll_live = TRUE;
@@ -2277,16 +2528,16 @@ main(int argc, char *argv[])
 #endif
         break;
       case 'm':        /* Fixed-width font for the display */
-        g_free(prefs->gui_font_name);
-        prefs->gui_font_name = g_strdup(optarg);
+        g_free(prefs_p->gui_font_name);
+        prefs_p->gui_font_name = g_strdup(optarg);
         break;
       case 'n':        /* No name resolution */
-        g_resolv_flags = RESOLV_NONE;
+        gbl_resolv_flags = RESOLV_NONE;
         break;
       case 'N':        /* Select what types of addresses/port #s to resolve */
-        if (g_resolv_flags == RESOLV_ALL)
-          g_resolv_flags = RESOLV_NONE;
-        badopt = string_to_name_resolve(optarg, &g_resolv_flags);
+        if (gbl_resolv_flags == RESOLV_ALL)
+          gbl_resolv_flags = RESOLV_NONE;
+        badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
         if (badopt != '\0') {
           cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
                        badopt);
@@ -2337,12 +2588,7 @@ main(int argc, char *argv[])
        /* We may set "last_open_dir" to "cf_name", and if we change
           "last_open_dir" later, we free the old value, so we have to
           set "cf_name" to something that's been allocated. */
-#if defined _WIN32 && GLIB_CHECK_VERSION(2,6,0)
-        /* since GLib 2.6, we need to convert filenames to utf8 for Win32 */
-        cf_name = g_locale_to_utf8(optarg, -1, NULL, NULL, NULL);
-#else
         cf_name = g_strdup(optarg);
-#endif
         break;
       case 'R':        /* Read file filter */
         rfilter = optarg;
@@ -2367,6 +2613,17 @@ main(int argc, char *argv[])
           exit(1);
         }
         break;
+      case 'u':        /* Seconds type */
+        if (strcmp(optarg, "s") == 0)
+          timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
+        else if (strcmp(optarg, "hms") == 0)
+          timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
+        else {
+          cmdarg_err("Invalid seconds type \"%s\"", optarg);
+          cmdarg_err_cont("It must be \"s\" for seconds or \"hms\" for hours, minutes and seconds.");
+          exit(1);
+        }
+        break;
       case 'X':
           /* ext ops were already processed just ignore them this time*/
           break;
@@ -2410,19 +2667,12 @@ main(int argc, char *argv[])
        * file - yes, you could have "-r" as the last part of the command,
        * but that's a bit ugly.
        */
-#if defined _WIN32 && GLIB_CHECK_VERSION(2,6,0)
-      /* since GLib 2.6, we need to convert filenames to utf8 for Win32 */
-      cf_name = g_locale_to_utf8(argv[0], -1, NULL, NULL, NULL);
-#else
       cf_name = g_strdup(argv[0]);
-#endif
     }
     argc--;
     argv++;
   }
 
-
-
   if (argc != 0) {
     /*
      * Extra command line arguments were specified; complain.
@@ -2498,14 +2748,30 @@ 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->capture_device) ? get_if_name(prefs->capture_device) : NULL)) {
+        (prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL)) {
         exit(2);
     }
   }
 
   if (list_link_layer_types) {
-    status = capture_opts_list_link_layer_types(&global_capture_opts, FALSE);
-    exit(status);
+    /* Get the list of link-layer types for the capture device. */
+    if_capabilities_t *caps;
+
+    caps = capture_get_if_capabilities(global_capture_opts.iface,
+                                       global_capture_opts.monitor_mode,
+                                       &err_str);
+    if (caps == NULL) {
+      cmdarg_err("%s", err_str);
+      g_free(err_str);
+      exit(2);
+    }
+    if (caps->data_link_types == NULL) {
+      cmdarg_err("The capture device \"%s\" has no data link types.", global_capture_opts.iface);
+      exit(2);
+    }
+    capture_opts_print_if_capabilities(caps, global_capture_opts.monitor_mode);
+    free_if_capabilities(caps);
+    exit(0);
   }
 
   capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
@@ -2522,7 +2788,7 @@ main(int argc, char *argv[])
     set_disabled_protos_list();
   }
 
-  build_column_format_array(&cfile.cinfo, prefs->num_cols, TRUE);
+  build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE);
 
   /* read in rc file from global and personal configuration paths. */
   rc_file = get_datafile_path(RC_FILE);
@@ -2534,6 +2800,8 @@ main(int argc, char *argv[])
 
   font_init();
 
+  macros_init();
+
   stock_icons_init();
 
   /* close the splash screen, as we are going to open the main window now */
@@ -2543,7 +2811,7 @@ main(int argc, char *argv[])
   /* Everything is prepared now, preferences and command line was read in */
 
   /* Pop up the main window. */
-  create_main_window(pl_size, tv_size, bv_size, prefs);
+  create_main_window(pl_size, tv_size, bv_size, prefs_p);
 
   /* Read the dynamic part of the recent file, as we have the gui now ready for it. */
   recent_read_dynamic(&rf_path, &rf_open_errno);
@@ -2598,29 +2866,8 @@ main(int argc, char *argv[])
   /* the window can be sized only, if it's not already shown, so do it now! */
   main_load_window_geometry(top_level);
 
-  /* Tell the user not to run as root. */
-  if (running_with_special_privs() && recent.privs_warn_if_elevated) {
-    cur_user = get_cur_username();
-    cur_group = get_cur_groupname();
-    priv_warning_dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
-      "Running as user \"%s\" and group \"%s\".\n"
-      "This could be dangerous.", cur_user, cur_group);
-    g_free(cur_user);
-    g_free(cur_group);
-    simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
-    simple_dialog_set_cb(priv_warning_dialog, priv_warning_dialog_cb, NULL);
-  }
+  g_timeout_add(info_update_freq, resolv_update_cb, NULL);
 
-#ifdef _WIN32
-  /* Warn the user if npf.sys isn't loaded. */
-  if (!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.");
-    simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
-    simple_dialog_set_cb(priv_warning_dialog, npf_warning_dialog_cb, NULL);
-  }
-#endif
 
   /* 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
@@ -2630,6 +2877,7 @@ main(int argc, char *argv[])
      up on top of us. */
   if (cf_name) {
     show_main_window(TRUE);
+    check_and_warn_user_startup(cf_name);
     if (rfilter != NULL) {
       if (!dfilter_compile(rfilter, &rfcode)) {
         bad_dfilter_alert_box(rfilter);
@@ -2653,7 +2901,7 @@ main(int argc, char *argv[])
         start_requested_stats();
 
         /* Read the capture file. */
-        switch (cf_read(&cfile)) {
+        switch (cf_read(&cfile, FALSE)) {
 
         case CF_READ_OK:
         case CF_READ_ERROR:
@@ -2662,7 +2910,19 @@ main(int argc, char *argv[])
              file. */
           /* if the user told us to jump to a specific packet, do it now */
           if(go_to_packet != 0) {
+            /* Jump to the specified frame number, kept for backward
+               compatibility. */
             cf_goto_frame(&cfile, go_to_packet);
+          } else if (jfilter != NULL) {
+            /* try to compile given filter */
+            if (!dfilter_compile(jfilter, &jump_to_filter)) {
+              bad_dfilter_alert_box(jfilter);
+            } else {
+              /* Filter ok, jump to the first packet matching the filter
+                 conditions. Default search direction is forward, but if
+                 option d was given, search backwards */
+              cf_find_packet_dfilter(&cfile, jump_to_filter, jump_backwards);
+            }
           }
           break;
 
@@ -2671,6 +2931,17 @@ main(int argc, char *argv[])
           exit(0);
           break;
         }
+
+       /* If the filename is not the absolute path, prepend the current dir. This happens
+          when wireshark is invoked from a cmd shell (e.g.,'wireshark -r file.pcap'). */
+       if (!g_path_is_absolute(cf_name)) {
+         char *old_cf_name = cf_name;
+         char *pwd = g_get_current_dir();
+         cf_name = g_strdup_printf("%s%s%s", pwd, G_DIR_SEPARATOR_S, cf_name);
+         g_free(old_cf_name);
+         g_free(pwd);
+       }
+
         /* Save the name of the containing directory specified in the
            path name, if any; we can write over cf_name, which is a
            good thing, given that "get_dirname()" does write over its
@@ -2684,6 +2955,7 @@ main(int argc, char *argv[])
           dfilter_free(rfcode);
         cfile.rfcode = NULL;
         show_main_window(FALSE);
+       /* Don't call check_and_warn_user_startup(): we did it above */
         set_menus_for_capture_in_progress(FALSE);
         set_capture_if_dialog_for_capture_in_progress(FALSE);
       }
@@ -2700,6 +2972,7 @@ main(int argc, char *argv[])
       }
       /* "-k" was specified; start a capture. */
       show_main_window(TRUE);
+      check_and_warn_user_startup(cf_name);
       if (capture_start(&global_capture_opts)) {
         /* The capture started.  Open stat windows; we do so after creating
           the main window, to avoid GTK warnings, and after successfully
@@ -2712,6 +2985,7 @@ main(int argc, char *argv[])
     }
     else {
       show_main_window(FALSE);
+      check_and_warn_user_startup(cf_name);
       set_menus_for_capture_in_progress(FALSE);
       set_capture_if_dialog_for_capture_in_progress(FALSE);
     }
@@ -2723,6 +2997,7 @@ main(int argc, char *argv[])
     }
 #else /* HAVE_LIBPCAP */
     show_main_window(FALSE);
+    check_and_warn_user_startup(cf_name);
     set_menus_for_capture_in_progress(FALSE);
     set_capture_if_dialog_for_capture_in_progress(FALSE);
 #endif /* HAVE_LIBPCAP */
@@ -2731,6 +3006,14 @@ main(int argc, char *argv[])
   /* 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);
+#endif
+
   g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "Wireshark is up and ready to go");
 
   /* we'll enter the GTK loop now and hand the control over to GTK ... */
@@ -2750,6 +3033,10 @@ main(int argc, char *argv[])
   /* hide the (unresponsive) main window, while asking the user to close the console window */
   gtk_widget_hide(top_level);
 
+#ifdef HAVE_GTKOSXAPPLICATION
+  g_object_unref(theApp);
+#endif
+
   /* Shutdown windows sockets */
   WSACleanup();
 
@@ -2780,6 +3067,12 @@ WinMain (struct HINSTANCE__ *hInstance,
 {
   INITCOMMONCONTROLSEX comm_ctrl;
 
+  /*
+   * Initialize our DLL search path. MUST be called before LoadLibrary
+   * or g_module_open.
+   */
+  ws_init_dll_search_path();
+
   /* Initialize our controls. Required for native Windows file dialogs. */
   memset (&comm_ctrl, 0, sizeof(comm_ctrl));
   comm_ctrl.dwSize = sizeof(comm_ctrl);
@@ -2791,7 +3084,7 @@ WinMain (struct HINSTANCE__ *hInstance,
   InitCommonControlsEx(&comm_ctrl);
 
   /* RichEd20.DLL is needed for filter entries. */
-  LoadLibrary(_T("riched20.dll"));
+  ws_load_library("riched20.dll");
 
   has_console = FALSE;
   return main (__argc, __argv);
@@ -2963,7 +3256,7 @@ static GtkWidget *main_widget_layout(gint layout_content)
     case(layout_pane_content_pdetails):
         return tv_scrollw;
     case(layout_pane_content_pbytes):
-        return byte_nb_ptr;
+        return byte_nb_ptr_gbl;
     default:
         g_assert_not_reached();
         return NULL;
@@ -2991,7 +3284,7 @@ void main_widgets_rearrange(void) {
 #endif
     g_object_ref(G_OBJECT(pkt_scrollw));
     g_object_ref(G_OBJECT(tv_scrollw));
-    g_object_ref(G_OBJECT(byte_nb_ptr));
+    g_object_ref(G_OBJECT(byte_nb_ptr_gbl));
     g_object_ref(G_OBJECT(statusbar));
     g_object_ref(G_OBJECT(main_pane_v1));
     g_object_ref(G_OBJECT(main_pane_v2));
@@ -3161,9 +3454,9 @@ main_widgets_show_or_hide(void)
     }
 
     if (recent.byte_view_show && have_capture_file) {
-        gtk_widget_show(byte_nb_ptr);
+        gtk_widget_show(byte_nb_ptr_gbl);
     } else {
-        gtk_widget_hide(byte_nb_ptr);
+        gtk_widget_hide(byte_nb_ptr_gbl);
     }
 
     if (have_capture_file) {
@@ -3202,7 +3495,7 @@ main_widgets_show_or_hide(void)
 
 
 /* called, when the window state changes (minimized, maximized, ...) */
-static int
+static gboolean
 window_state_event_cb (GtkWidget *widget _U_,
                        GdkEvent *event,
                        gpointer  data _U_)
@@ -3222,7 +3515,7 @@ window_state_event_cb (GtkWidget *widget _U_,
 
 
 #define NO_SHIFT_MOD_MASK (GDK_MODIFIER_MASK & ~(GDK_SHIFT_MASK|GDK_MOD2_MASK|GDK_LOCK_MASK))
-static int
+static gboolean
 top_level_key_pressed_cb(GtkWidget *w _U_, GdkEventKey *event, gpointer user_data _U_)
 {
     if (event->keyval == GDK_F8) {
@@ -3259,20 +3552,13 @@ 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)
+create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
 {
-    GtkTooltips   *tooltips;
     GtkAccelGroup *accel;
-    gchar         *title;
-
-    /* use user-defined title if preference is set */
-    title = create_user_window_title("The Wireshark Network Analyzer");
 
     /* Main window */
-    top_level = window_new(GTK_WINDOW_TOPLEVEL, title);
-    g_free(title);
-
-    tooltips = gtk_tooltips_new();
+    top_level = window_new(GTK_WINDOW_TOPLEVEL, "");
+    set_main_window_name("The Wireshark Network Analyzer");
 
     gtk_widget_set_name(top_level, "main window");
     g_signal_connect(top_level, "delete_event", G_CALLBACK(main_window_delete_event_cb),
@@ -3282,24 +3568,22 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
     g_signal_connect(GTK_OBJECT(top_level), "key-press-event",
                          G_CALLBACK(top_level_key_pressed_cb), NULL );
 
-    gtk_window_set_policy(GTK_WINDOW(top_level), TRUE, TRUE, FALSE);
-
     /* Vertical container for menu bar, toolbar(s), paned windows and progress/info box */
     main_vbox = gtk_vbox_new(FALSE, 1);
-    gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 1);
+    gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
     gtk_container_add(GTK_CONTAINER(top_level), main_vbox);
     gtk_widget_show(main_vbox);
 
     /* Menu bar */
     menubar = main_menu_new(&accel);
 
-#ifdef HAVE_IGE_MAC_INTEGRATION
-    /* MacOS X native menus are created and displayed by main_menu_new() */
-    if(!prefs->gui_macosx_style) {
+#if defined(HAVE_IGE_MAC_INTEGRATION) || defined (HAVE_GTKOSXAPPLICATION)
+    /* Mac OS X native menus are created and displayed by main_menu_new() */
+    if(!prefs_p->gui_macosx_style) {
 #endif
     gtk_window_add_accel_group(GTK_WINDOW(top_level), accel);
     gtk_widget_show(menubar);
-#ifdef HAVE_IGE_MAC_INTEGRATION
+#if defined(HAVE_IGE_MAC_INTEGRATION) || defined(HAVE_GTKOSXAPPLICATION)
     }
 #endif
 
@@ -3316,29 +3600,29 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
     gtk_widget_set_size_request(pkt_scrollw, -1, pl_size);
     gtk_widget_show_all(pkt_scrollw);
 #else
-    pkt_scrollw = packet_list_new(prefs);
+    pkt_scrollw = packet_list_new(prefs_p);
     gtk_widget_set_size_request(packet_list, -1, pl_size);
     gtk_widget_show(pkt_scrollw);
 #endif
 
     /* Tree view */
-    tv_scrollw = main_tree_view_new(prefs, &tree_view);
+    tv_scrollw = main_tree_view_new(prefs_p, &tree_view_gbl);
     gtk_widget_set_size_request(tv_scrollw, -1, tv_size);
     gtk_widget_show(tv_scrollw);
 
-    g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)),
+    g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_gbl)),
                    "changed", G_CALLBACK(tree_view_selection_changed_cb), NULL);
-    g_signal_connect(tree_view, "button_press_event", G_CALLBACK(popup_menu_handler),
+    g_signal_connect(tree_view_gbl, "button_press_event", G_CALLBACK(popup_menu_handler),
                    g_object_get_data(G_OBJECT(popup_menu_object), PM_TREE_VIEW_KEY));
-    gtk_widget_show(tree_view);
+    gtk_widget_show(tree_view_gbl);
 
     /* Byte view. */
-    byte_nb_ptr = byte_view_new();
-    gtk_widget_set_size_request(byte_nb_ptr, -1, bv_size);
-    gtk_widget_show(byte_nb_ptr);
+    byte_nb_ptr_gbl = byte_view_new();
+    gtk_widget_set_size_request(byte_nb_ptr_gbl, -1, bv_size);
+    gtk_widget_show(byte_nb_ptr_gbl);
 
-    g_signal_connect(byte_nb_ptr, "button_press_event", G_CALLBACK(popup_menu_handler),
-                   g_object_get_data(G_OBJECT(popup_menu_object), PM_HEXDUMP_KEY));
+    g_signal_connect(byte_nb_ptr_gbl, "button_press_event", G_CALLBACK(popup_menu_handler),
+                   g_object_get_data(G_OBJECT(popup_menu_object), PM_BYTES_VIEW_KEY));
 
     /* Panes for the packet list, tree, and byte view */
     main_pane_v1 = gtk_vpaned_new();
@@ -3402,7 +3686,7 @@ prefs_to_capture_opts(void)
 #endif /* HAVE_LIBPCAP */
 
   /* Set the name resolution code's flags from the preferences. */
-    g_resolv_flags = prefs.name_resolve;
+    gbl_resolv_flags = prefs.name_resolve;
 }
 
 
@@ -3442,14 +3726,20 @@ void change_configuration_profile (const gchar *profile_name)
                  "Could not open common recent file\n\"%s\": %s.",
                  rf_path, strerror(rf_open_errno));
    }
+   if (recent.gui_fileopen_remembered_dir &&
+       test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
+     set_last_open_dir(recent.gui_fileopen_remembered_dir);
+   }
    timestamp_set_type (recent.gui_time_format);
+   timestamp_set_seconds_type (recent.gui_seconds_format);
    color_filters_enable(recent.packet_list_colorize);
 
    prefs_to_capture_opts();
    prefs_apply_all();
+   macros_post_update();
 
    /* Update window view and redraw the toolbar */
-   update_main_window_name();
+   update_main_window_title();
    toolbar_redraw_all();
 
    /* Enable all protocols and disable from the disabled list */
@@ -3464,11 +3754,13 @@ void change_configuration_profile (const gchar *profile_name)
    /* Reload list of interfaces on welcome page */
    welcome_if_panel_reload();
 
-#ifndef NEW_PACKET_LIST
    /* Recreate the packet list according to new preferences */
+#ifdef NEW_PACKET_LIST
+   new_packet_list_recreate ();
+#else
    packet_list_recreate ();
-   cfile.cinfo.columns_changed = FALSE; /* Reset value */
 #endif
+   cfile.cinfo.columns_changed = FALSE; /* Reset value */
    user_font_apply();
 
    /* Update menus with new recent values */