Make sure that the Capture/Start menue item will always use the
[obnox/wireshark/wip.git] / gtk / main.c
index 45e36a8512e23df7b2e64e13be3780b754af0f4c..11f4a4673ed54bfe6d84c8927f11483e547a17ee 100644 (file)
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
+#if GTK_CHECK_VERSION(3,0,0)
+# include <gdk/gdkkeysyms-compat.h>
+#endif
 
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include <locale.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#ifdef NEED_STRERROR_H
-#include "strerror.h"
-#endif
-
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #else
-#include "wsgetopt.h"
+#include "wsutil/wsgetopt.h"
 #endif
 
 #ifdef _WIN32 /* Needed for console I/O */
@@ -80,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) */
@@ -92,6 +91,7 @@
 #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 "../merge.h"
 #include "../alert_box.h"
 #include "../log.h"
+#include "../u3.h"
 #include <wsutil/file_util.h>
 
 #ifdef HAVE_LIBPCAP
 #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/main_packet_list.h"
-#include "gtk/main_statusbar.h"
+#include "gtk/macros_dlg.h"
 #include "gtk/main_statusbar_private.h"
 #include "gtk/main_toolbar.h"
 #include "gtk/main_welcome.h"
 #include "gtk/webbrowser.h"
 #include "gtk/capture_dlg.h"
 #include "gtk/capture_if_dlg.h"
-#include "gtk/tap_dfilter_dlg.h"
+#include "gtk/tap_param_dlg.h"
 #include "gtk/prefs_column.h"
 #include "gtk/prefs_dlg.h"
 #include "gtk/proto_help.h"
+#include "gtk/new_packet_list.h"
 
 #ifdef HAVE_LIBPCAP
 #include "../image/wsicon16.xpm"
 #include "airpcap_gui_utils.h"
 #endif
 
-#ifdef HAVE_AIRPDCAP
 #include <epan/crypt/airpdcap_ws.h>
-#endif
 
-#ifdef NEW_PACKET_LIST
-#include "gtk/new_packet_list.h"
-#endif
 
 #ifdef HAVE_GTKOSXAPPLICATION
 #include <igemacintegration/gtkosxapplication.h>
@@ -212,12 +209,14 @@ 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 */
+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
@@ -354,7 +353,7 @@ colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr)
             } else {
                 color_filters_set_tmp(filt_nr,filter, FALSE);
             }
-            cf_colorize_packets(&cfile);
+            new_packet_list_colorize_packets();
         }
     }
 }
@@ -524,28 +523,18 @@ 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 = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_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    col;
     frame_data *fdata;
     GList      *addr_list = NULL;
-    int         err;
-    gchar       *err_info;
 
-#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, &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 */
 
         epan_dissect_init(&edt, FALSE, FALSE);
         col_custom_prime_edt(&edt, &cfile.cinfo);
@@ -575,26 +564,17 @@ 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 = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY));
+    gint    column = new_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;
-    int         err;
-    gchar       *err_info;
 
-#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, &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);
@@ -603,24 +583,35 @@ get_filter_from_packet_list_row_and_column(gpointer data)
                  &cfile.cinfo);
         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 */
-            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],
+        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]);
                 }
             }
-           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);
@@ -654,7 +645,8 @@ copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E acti
     switch(action)
     {
     case COPY_SELECTED_DESCRIPTION:
-        if (cfile.finfo_selected->rep->representation != 0) {
+        if (cfile.finfo_selected->rep &&
+            strlen (cfile.finfo_selected->rep->representation) > 0) {
             g_string_append(gtk_text_str, cfile.finfo_selected->rep->representation);
         }
         break;
@@ -691,19 +683,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
 }
 
 
@@ -713,12 +711,8 @@ 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;
@@ -755,10 +749,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;
   }
 }
@@ -766,20 +760,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;
@@ -842,11 +835,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;
@@ -867,7 +858,7 @@ 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,
@@ -889,13 +880,9 @@ 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);
+                            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();
     }
@@ -916,10 +903,10 @@ void expand_tree_cb(GtkWidget *widget _U_, gpointer data _U_) {
 
 void resolve_name_cb(GtkWidget *widget _U_, gpointer data _U_) {
   if (cfile.edt->tree) {
-    guint32 tmp = g_resolv_flags;
-    g_resolv_flags = RESOLV_ALL;
+    guint32 tmp = gbl_resolv_flags;
+    gbl_resolv_flags = RESOLV_ALL;
     proto_tree_draw(cfile.edt->tree, tree_view_gbl);
-    g_resolv_flags = tmp;
+    gbl_resolv_flags = tmp;
   }
 }
 
@@ -1200,7 +1187,8 @@ 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 <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");
@@ -1309,11 +1297,9 @@ cmdarg_err_cont(const char *fmt, ...)
   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
 tap_update_cb(gpointer data _U_)
@@ -1329,54 +1315,22 @@ void reset_tap_update_timer(void)
     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
+        */
+
 }
 
 /*
@@ -1389,10 +1343,17 @@ resolv_update_cb(gpointer data _U_)
 {
   /* Anything new show up? */
   if (host_name_lookup_process(NULL)) {
+#if GTK_CHECK_VERSION(2,14,0)
+    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))
+       gdk_window_invalidate_rect(gtk_widget_get_window(tv_scrollw), NULL, TRUE);
+#else
     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);
+#endif
   }
 
   /* Always check. Even if we don't do async lookups we could still get
@@ -1401,24 +1362,22 @@ resolv_update_cb(gpointer data _U_)
 }
 
 
-/* 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_)
@@ -1485,7 +1444,7 @@ main_cf_cb_file_closed(capture_file *cf _U_)
 static void
 main_cf_cb_file_read_started(capture_file *cf _U_)
 {
-  tap_dfilter_dlg_update();
+  tap_param_dlg_update();
 
   /* Set up main window for a capture file. */
   main_set_for_capture_file(TRUE);
@@ -1494,6 +1453,17 @@ main_cf_cb_file_read_started(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
@@ -1551,11 +1521,7 @@ main_capture_set_main_window_title(capture_options *capture_opts)
     GString *title = g_string_new("");
 
     g_string_append(title, "Capturing ");
-    if(capture_opts->iface) {
-        g_string_append_printf(title, "from %s ", cf_get_tempfile_source(capture_opts->cf));
-    }
-    g_string_append(title, "- Wireshark");
-
+    g_string_append_printf(title, "from %s ", cf_get_tempfile_source(capture_opts->cf));
     set_main_window_name(title->str);
     g_string_free(title, TRUE);
 }
@@ -1605,6 +1571,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
@@ -1685,12 +1655,12 @@ main_cf_cb_packet_selected(gpointer data)
     add_main_byte_views(cf->edt);
     main_proto_tree_draw(cf->edt->tree);
 
-    /* The user is searching for a string in the data or a hex value,
-     * 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,
+    /* Note: Both string and hex value searches in the packet data produce a non-zero
+       search_pos if successful */
+    if(cf->search_in_progress &&
+      (cf->search_pos != 0 || (cf->string && cf->decode_data))) {
+        highlight_field(cf->edt->tvb, cf->search_pos,
                         (GtkTreeView *)tree_view_gbl, cf->edt->tree);
-        cfile.search_pos = 0; /* Reset the position */
     }
 
     /* A packet is selected. */
@@ -1774,7 +1744,7 @@ main_capture_callback(gint event, capture_options *capture_opts, gpointer user_d
 {
 #ifdef HAVE_GTKOSXAPPLICATION
     GtkOSXApplication *theApp;
-#endif 
+#endif
     switch(event) {
     case(capture_cb_capture_prepared):
         g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared");
@@ -1822,10 +1792,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
@@ -1845,14 +1829,13 @@ get_gui_compiled_info(GString *str)
 #else
   g_string_append(str, "without AirPcap");
 #endif
-#ifdef NEW_PACKET_LIST
-  g_string_append(str, ", with new_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);
@@ -1862,7 +1845,6 @@ get_gui_runtime_info(GString *str)
     g_string_append(str, ", ");
     u3_runtime_info(str);
   }
-
 }
 
 static e_prefs *
@@ -1885,24 +1867,24 @@ read_configuration_files(char **gdp_path, char **dp_path)
     if (gpf_open_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open global preferences file\n\"%s\": %s.", gpf_path,
-        strerror(gpf_open_errno));
+        g_strerror(gpf_open_errno));
     }
     if (gpf_read_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "I/O error reading global preferences file\n\"%s\": %s.", gpf_path,
-        strerror(gpf_read_errno));
+        g_strerror(gpf_read_errno));
     }
   }
   if (pf_path != NULL) {
     if (pf_open_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open your preferences file\n\"%s\": %s.", pf_path,
-        strerror(pf_open_errno));
+        g_strerror(pf_open_errno));
     }
     if (pf_read_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "I/O error reading your preferences file\n\"%s\": %s.", pf_path,
-        strerror(pf_read_errno));
+        g_strerror(pf_read_errno));
     }
     g_free(pf_path);
     pf_path = NULL;
@@ -1920,7 +1902,7 @@ read_configuration_files(char **gdp_path, char **dp_path)
   if (cf_path != NULL) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open your capture filter file\n\"%s\": %s.", cf_path,
-        strerror(cf_open_errno));
+        g_strerror(cf_open_errno));
       g_free(cf_path);
   }
 
@@ -1929,7 +1911,7 @@ read_configuration_files(char **gdp_path, char **dp_path)
   if (df_path != NULL) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open your display filter file\n\"%s\": %s.", df_path,
-        strerror(df_open_errno));
+        g_strerror(df_open_errno));
       g_free(df_path);
   }
 
@@ -1940,12 +1922,12 @@ read_configuration_files(char **gdp_path, char **dp_path)
     if (gdp_open_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open global disabled protocols file\n\"%s\": %s.",
-       *gdp_path, strerror(gdp_open_errno));
+       *gdp_path, g_strerror(gdp_open_errno));
     }
     if (gdp_read_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "I/O error reading global disabled protocols file\n\"%s\": %s.",
-       *gdp_path, strerror(gdp_read_errno));
+       *gdp_path, g_strerror(gdp_read_errno));
     }
     g_free(*gdp_path);
     *gdp_path = NULL;
@@ -1954,12 +1936,12 @@ read_configuration_files(char **gdp_path, char **dp_path)
     if (dp_open_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "Could not open your disabled protocols file\n\"%s\": %s.", *dp_path,
-        strerror(dp_open_errno));
+        g_strerror(dp_open_errno));
     }
     if (dp_read_errno != 0) {
       simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
         "I/O error reading your disabled protocols file\n\"%s\": %s.", *dp_path,
-        strerror(dp_read_errno));
+        g_strerror(dp_read_errno));
     }
     g_free(*dp_path);
     *dp_path = NULL;
@@ -1988,7 +1970,10 @@ check_and_warn_user_startup(gchar *cf_name _U_)
     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);
+      "This could be dangerous.\n\n"
+      "If you're running Wireshark this way in order to perform live capture, "
+      "you may want to be aware that there is a better way documented at\n"
+      "http://wiki.wireshark.org/CaptureSetup/CapturePrivileges", 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.");
@@ -2051,14 +2036,14 @@ main(int argc, char *argv[])
   GtkWidget           *splash_win = NULL;
   GLogLevelFlags       log_flags;
   guint                go_to_packet = 0;
-  gboolean             jump_backwards = FALSE, saved_bw = FALSE;
+  gboolean             jump_backwards = FALSE;
   dfilter_t           *jump_to_filter = NULL;
   int                  optind_initial;
   int                  status;
 #ifdef HAVE_GTKOSXAPPLICATION
   GtkOSXApplication   *theApp;
 #endif
-       
+
 #ifdef HAVE_LIBPCAP
 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
 #define OPTSTRING_B "B:"
@@ -2079,12 +2064,18 @@ main(int argc, char *argv[])
 
   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);
+#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();
 
   /*
@@ -2095,9 +2086,7 @@ main(int argc, char *argv[])
   /* initialize the funnel mini-api */
   initialize_funnel_ops();
 
-#ifdef HAVE_AIRPDCAP
   AirPDcapInitContext(&airpdcap_ctx);
-#endif
 
 #ifdef _WIN32
   /* Load wpcap if possible. Do this before collecting the run-time version information */
@@ -2157,17 +2146,7 @@ main(int argc, char *argv[])
   /* 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 ");
@@ -2179,7 +2158,7 @@ main(int argc, char *argv[])
   if (rf_path != NULL && rf_open_errno != 0) {
     simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                  "Could not open common recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
+                 rf_path, g_strerror(rf_open_errno));
   }
 
   /* "pre-scan" the command line parameters, if we have "console only"
@@ -2198,13 +2177,37 @@ main(int argc, char *argv[])
   while ((opt = getopt(argc, argv, optstring)) != -1) {
     switch (opt) {
       case 'C':        /* Configuration Profile */
-       if (profile_exists (optarg)) {
+       if (profile_exists (optarg, FALSE)) {
          set_profile_name (optarg);
        } else {
          cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
          exit(1);
        }
        break;
+      case 'D':        /* Print a list of capture devices and exit */
+#ifdef HAVE_LIBPCAP
+        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 'h':        /* Print help and exit */
         print_usage(TRUE);
         exit(0);
@@ -2241,7 +2244,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, g_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
@@ -2279,6 +2299,10 @@ main(int argc, char *argv[])
   optind = optind_initial;
   opterr = 1;
 
+#ifdef USE_THREADS
+  g_thread_init(NULL);
+#endif
+
   /* Set the current locale according to the program environment.
    * We haven't localized anything, but some GTK widgets are localized
    * (the file selection dialogue, for example).
@@ -2333,9 +2357,6 @@ 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+ */
@@ -2391,37 +2412,15 @@ main(int argc, char *argv[])
   prefs_register_modules();
 
   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_p->tap_update_interval, tap_update_cb, NULL);
-#endif /* !_WIN32 && G_THREADS_ENABLED && USE_THREADS */
 
   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));
-  }
-
   proto_help_init();
-
   cap_file_init(&cfile);
 
   /* Fill in capture options with values from the preferences */
@@ -2472,30 +2471,6 @@ main(int argc, char *argv[])
       case 'C':
         /* Configuration profile settings were already processed just ignore them this time*/
        break;
-      case 'D':        /* Print a list of capture devices and exit */
-#ifdef HAVE_LIBPCAP
-        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 'j':        /* Search backwards for a matching packet from filter in option J */
         jump_backwards = TRUE;
         break;
@@ -2526,12 +2501,12 @@ main(int argc, char *argv[])
         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);
@@ -2582,12 +2557,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;
@@ -2605,6 +2575,10 @@ main(int argc, char *argv[])
           timestamp_set_type(TS_DELTA_DIS);
         else if (strcmp(optarg, "e") == 0)
           timestamp_set_type(TS_EPOCH);
+        else if (strcmp(optarg, "u") == 0)
+          timestamp_set_type(TS_UTC);
+        else if (strcmp(optarg, "ud") == 0)
+          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,");
@@ -2645,48 +2619,42 @@ main(int argc, char *argv[])
         break;
     }
   }
-  argc -= optind;
-  argv += optind;
-  if (argc >= 1) {
-    if (cf_name != NULL) {
+  if (!arg_error) {
+    argc -= optind;
+    argv += optind;
+    if (argc >= 1) {
+      if (cf_name != NULL) {
+        /*
+         * Input file name specified with "-r" *and* specified as a regular
+         * command-line argument.
+         */
+        cmdarg_err("File name specified both with -r and regular argument");
+        arg_error = TRUE;
+      } else {
+        /*
+         * Input file name not specified with "-r", and a command-line argument
+         * was specified; treat it as the input file name.
+         *
+         * Yes, this is different from tshark, where non-flag command-line
+         * arguments are a filter, but this works better on GUI desktops
+         * where a command can be specified to be run to open a particular
+         * file - yes, you could have "-r" as the last part of the command,
+         * but that's a bit ugly.
+         */
+        cf_name = g_strdup(argv[0]);
+      }
+      argc--;
+      argv++;
+    }
+
+    if (argc != 0) {
       /*
-       * Input file name specified with "-r" *and* specified as a regular
-       * command-line argument.
+       * Extra command line arguments were specified; complain.
        */
-      cmdarg_err("File name specified both with -r and regular argument");
+      cmdarg_err("Invalid argument: %s", argv[0]);
       arg_error = TRUE;
-    } else {
-      /*
-       * Input file name not specified with "-r", and a command-line argument
-       * was specified; treat it as the input file name.
-       *
-       * Yes, this is different from tshark, where non-flag command-line
-       * arguments are a filter, but this works better on GUI desktops
-       * where a command can be specified to be run to open a particular
-       * 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.
-     */
-    cmdarg_err("Invalid argument: %s", argv[0]);
-    arg_error = TRUE;
   }
-
   if (arg_error) {
 #ifndef HAVE_LIBPCAP
     if (capture_option_specified) {
@@ -2760,23 +2728,27 @@ main(int argc, char *argv[])
   }
 
   if (list_link_layer_types) {
-    /* Get the list of link-layer types for the capture device. */
+    /* Get the list of link-layer types for the capture devices. */
     if_capabilities_t *caps;
+    guint i;
+    interface_options interface_opts;
 
-    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);
+    for (i = 0; i < global_capture_opts.ifaces->len; i++) {
+
+      interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
+      caps = capture_get_if_capabilities(interface_opts.name, interface_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.", interface_opts.name);
+        exit(2);
+      }
+      capture_opts_print_if_capabilities(caps, interface_opts.name, interface_opts.monitor_mode);
+      free_if_capabilities(caps);
     }
-    capture_opts_print_if_capabilities(caps, global_capture_opts.monitor_mode);
-    free_if_capabilities(caps);
     exit(0);
   }
 
@@ -2789,6 +2761,47 @@ main(int argc, char *argv[])
      line that their preferences have changed. */
   prefs_apply_all();
 
+#ifdef HAVE_LIBPCAP
+#ifndef USE_THREADS
+  if ((global_capture_opts.ifaces->len > 1) && start_capture) {
+    cmdarg_err("You specified multiple interfaces for capturing which this version of Wireshark doesn't support.");
+    exit(2);
+  }
+#endif
+  if ((global_capture_opts.ifaces->len == 0) &&
+      (prefs.capture_device != NULL)) {
+    interface_options interface_opts;
+
+    interface_opts.name = g_strdup(get_if_name(prefs.capture_device));
+    interface_opts.descr = get_interface_descriptive_name(interface_opts.name);
+    interface_opts.monitor_mode = prefs_capture_device_monitor_mode(interface_opts.name);
+    interface_opts.linktype = capture_dev_user_linktype_find(interface_opts.name);
+    interface_opts.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
+    interface_opts.snaplen = global_capture_opts.default_options.snaplen;
+    interface_opts.has_snaplen = global_capture_opts.default_options.has_snaplen;
+    interface_opts.promisc_mode = global_capture_opts.default_options.promisc_mode;
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
+    interface_opts.buffer_size =  global_capture_opts.default_options.buffer_size;
+#endif
+#ifdef HAVE_PCAP_REMOTE
+    interface_opts.src_type = global_capture_opts.default_options.src_type;
+    interface_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
+    interface_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
+    interface_opts.auth_type = global_capture_opts.default_options.auth_type;
+    interface_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
+    interface_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
+    interface_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
+    interface_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
+    interface_opts.nocap_local = global_capture_opts.default_options.nocap_local;
+ #endif
+ #ifdef HAVE_PCAP_SETSAMPLING
+    interface_opts.sampling_method = global_capture_opts.default_options.sampling_method;
+    interface_opts.sampling_param  = global_capture_opts.default_options.sampling_param;
+ #endif
+    g_array_insert_val(global_capture_opts.ifaces, 0, interface_opts);
+  }
+#endif
+
   /* disabled protocols as per configuration file */
   if (gdp_path == NULL && dp_path == NULL) {
     set_disabled_protos_list();
@@ -2806,6 +2819,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 */
@@ -2822,7 +2837,7 @@ main(int argc, char *argv[])
   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));
+                 rf_path, g_strerror(rf_open_errno));
   }
 
   color_filters_enable(recent.packet_list_colorize);
@@ -2834,9 +2849,6 @@ main(int argc, char *argv[])
      is displayed.
 
      XXX - is that still true, with fixed-width columns? */
-#ifndef NEW_PACKET_LIST
-  packet_list_set_column_titles();
-#endif
 
   menu_recent_read_finished();
 #ifdef HAVE_LIBPCAP
@@ -2921,15 +2933,11 @@ main(int argc, char *argv[])
             /* try to compile given filter */
             if (!dfilter_compile(jfilter, &jump_to_filter)) {
               bad_dfilter_alert_box(jfilter);
-            } else
-            {
+            } 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 */
-              saved_bw = cfile.sbackward;
-              cfile.sbackward = jump_backwards;
-              cf_find_packet_dfilter(&cfile, jump_to_filter);
-              cfile.sbackward = saved_bw;
+              cf_find_packet_dfilter(&cfile, jump_to_filter, jump_backwards);
             }
           }
           break;
@@ -2939,6 +2947,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
@@ -2979,18 +2998,16 @@ main(int argc, char *argv[])
            one of MATE's late-registered fields as part of the filter. */
         start_requested_stats();
       }
-    }
-    else {
+    } 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);
     }
 
-    /* if the user didn't supplied a capture filter, use the one to filter out remote connections like SSH */
-    if (!start_capture && strlen(global_capture_opts.cfilter) == 0) {
-      g_free(global_capture_opts.cfilter);
-      global_capture_opts.cfilter = g_strdup(get_conn_cfilter());
+    /* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
+    if (!start_capture && !global_capture_opts.default_options.cfilter) {
+      global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
     }
 #else /* HAVE_LIBPCAP */
     show_main_window(FALSE);
@@ -3010,7 +3027,7 @@ main(int argc, char *argv[])
   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 ... */
@@ -3022,9 +3039,7 @@ main(int argc, char *argv[])
 
   epan_cleanup();
 
-#ifdef HAVE_AIRPDCAP
-       AirPDcapDestroyContext(&airpdcap_ctx);
-#endif
+  AirPDcapDestroyContext(&airpdcap_ctx);
 
 #ifdef _WIN32
   /* hide the (unresponsive) main window, while asking the user to close the console window */
@@ -3033,7 +3048,7 @@ main(int argc, char *argv[])
 #ifdef HAVE_GTKOSXAPPLICATION
   g_object_unref(theApp);
 #endif
-       
+
   /* Shutdown windows sockets */
   WSACleanup();
 
@@ -3064,6 +3079,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);
@@ -3075,9 +3096,10 @@ 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;
+  console_wait = FALSE;
   return main (__argc, __argv);
 }
 
@@ -3108,15 +3130,25 @@ create_console(void)
   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. */
-    if (!AllocConsole())
-      return;   /* couldn't create console */
+
+    /*
+     * 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);
-
-    /* Well, we have a console now. */
-    has_console = TRUE;
+    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
@@ -3125,18 +3157,19 @@ create_console(void)
        the message(s) we put in there). */
     atexit(destroy_console);
 
-    SetConsoleTitle(_T("Wireshark Debug Console"));
+    /* Well, we have a console now. */
+    has_console = TRUE;
   }
 }
 
 static void
 destroy_console(void)
 {
-  if (has_console) {
+  if (console_wait) {
     printf("\n\nPress any key to exit\n");
     _getch();
-    FreeConsole();
   }
+  FreeConsole();
 }
 #endif /* _WIN32 */
 
@@ -3379,11 +3412,6 @@ void main_widgets_rearrange(void) {
         gtk_box_pack_start(GTK_BOX(statusbar), filter_tb, FALSE, TRUE, 1);
     }
 
-#ifdef HAVE_AIRPCAP
-    /* airpcap toolbar */
-    gtk_box_pack_start(GTK_BOX(main_vbox), airpcap_tb, FALSE, TRUE, 1);
-#endif
-
     /* statusbar widgets */
     statusbar_widgets_pack(statusbar);
 
@@ -3399,7 +3427,11 @@ is_widget_visible(GtkWidget *widget, gpointer data)
     gboolean *is_visible = data;
 
     if (!*is_visible) {
+#if GTK_CHECK_VERSION(2,18,0)
+        if (gtk_widget_get_visible(widget))
+#else
         if (GTK_WIDGET_VISIBLE(widget))
+#endif
             *is_visible = TRUE;
     }
 }
@@ -3472,21 +3504,16 @@ main_widgets_show_or_hide(void)
     if (!have_capture_file) {
         if(welcome_pane) {
             gtk_widget_show(welcome_pane);
+            select_ifaces();
         }
     } else {
         gtk_widget_hide(welcome_pane);
     }
-
-    /* workaround for bug in GtkCList to ensure packet list scrollbar is updated */
-#ifndef NEW_PACKET_LIST
-    packet_list_freeze ();
-    packet_list_thaw ();
-#endif
 }
 
 
 /* called, when the window state changes (minimized, maximized, ...) */
-static int
+static gboolean
 window_state_event_cb (GtkWidget *widget _U_,
                        GdkEvent *event,
                        gpointer  data _U_)
@@ -3506,22 +3533,14 @@ 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) {
-#ifdef NEW_PACKET_LIST
        new_packet_list_next();
-#else
-       packet_list_next();
-#endif
        return TRUE;
     } else if (event->keyval == GDK_F7) {
-#ifdef NEW_PACKET_LIST
        new_packet_list_prev();
-#else
-       packet_list_prev();
-#endif
        return TRUE;
     } else if (event->state & NO_SHIFT_MOD_MASK) {
         return FALSE; /* Skip control, alt, and other modifiers */
@@ -3546,14 +3565,10 @@ static void
 create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
 {
     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);
+    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),
@@ -3565,7 +3580,7 @@ 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 = 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);
 
@@ -3590,15 +3605,9 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
     filter_tb = filter_toolbar_new();
 
     /* Packet list */
-#ifdef NEW_PACKET_LIST
     pkt_scrollw = new_packet_list_create();
     gtk_widget_set_size_request(pkt_scrollw, -1, pl_size);
     gtk_widget_show_all(pkt_scrollw);
-#else
-    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_p, &tree_view_gbl);
@@ -3659,7 +3668,11 @@ show_main_window(gboolean doing_work)
   display_queued_messages();
 
   /* Move the main window to the front, in case it isn't already there */
+#if GTK_CHECK_VERSION(2,14,0)
+  gdk_window_raise(gtk_widget_get_window(top_level));
+#else
   gdk_window_raise(top_level->window);
+#endif
 
 #ifdef HAVE_AIRPCAP
   airpcap_toolbar_show(airpcap_tb);
@@ -3673,17 +3686,40 @@ 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.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;
+    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 */
 
   /* Set the name resolution code's flags from the preferences. */
-    g_resolv_flags = prefs.name_resolve;
+    gbl_resolv_flags = prefs.name_resolve;
 }
 
+static void copy_global_profile (const gchar *profile_name)
+{
+   char  *pf_dir_path, *pf_dir_path2, *pf_filename;
+
+   if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) {
+     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+                  "Can't create directory\n\"%s\":\n%s.",
+                  pf_dir_path, g_strerror(errno));
+
+     g_free(pf_dir_path);
+   }
+
+   if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename,
+                                &pf_dir_path, &pf_dir_path2) == -1) {
+     simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
+                  "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.",
+                  pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno));
+
+     g_free(pf_filename);
+     g_free(pf_dir_path);
+     g_free(pf_dir_path2);
+   }
+}
 
 /* Change configuration profile */
 void change_configuration_profile (const gchar *profile_name)
@@ -3693,14 +3729,25 @@ void change_configuration_profile (const gchar *profile_name)
    int    rf_open_errno;
 
    /* First check if profile exists */
-   if (!profile_exists(profile_name)) {
+   if (!profile_exists(profile_name, FALSE)) {
+     if (profile_exists(profile_name, TRUE)) {
+       /* Copy from global profile */
+       copy_global_profile (profile_name);
+     } else {
+       /* No personal and no global profile exists */
+       return;
+     }
+   }
+
+   /* Then check if changing to another profile */
+   if (profile_name && strcmp (profile_name, get_profile_name()) == 0) {
      return;
    }
 
    /* Get the current geometry, before writing it to disk */
    main_save_window_geometry(top_level);
 
-   if (profile_exists(get_profile_name())) {
+   if (profile_exists(get_profile_name(), FALSE)) {
      /* Write recent file for profile we are leaving, if it still exists */
      write_profile_recent();
    }
@@ -3719,7 +3766,11 @@ void change_configuration_profile (const gchar *profile_name)
    if (rf_path != NULL && rf_open_errno != 0) {
      simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
                  "Could not open common recent file\n\"%s\": %s.",
-                 rf_path, strerror(rf_open_errno));
+                 rf_path, g_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);
@@ -3727,9 +3778,10 @@ void change_configuration_profile (const gchar *profile_name)
 
    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 */
@@ -3745,11 +3797,7 @@ void change_configuration_profile (const gchar *profile_name)
    welcome_if_panel_reload();
 
    /* Recreate the packet list according to new preferences */
-#ifdef NEW_PACKET_LIST
    new_packet_list_recreate ();
-#else
-   packet_list_recreate ();
-#endif
    cfile.cinfo.columns_changed = FALSE; /* Reset value */
    user_font_apply();