Use "get_basename()" rather than finding the last component of "argv[0]"
[obnox/wireshark/wip.git] / gtk / main.c
index ea487221bd59a0771413602e70dfe4966b2c127f..f7f5c7c67ae4ed42ffbfc7b868c6e182367c9b6d 100644 (file)
@@ -1,6 +1,6 @@
 /* main.c
  *
- * $Id: main.c,v 1.90 2000/01/15 12:54:24 gram Exp $
+ * $Id: main.c,v 1.96 2000/01/25 04:44:33 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -989,17 +989,18 @@ print_usage(void) {
   fprintf(stderr, "This is GNU " PACKAGE " " VERSION ", compiled with %s\n",
          comp_info_str);
 #ifdef HAVE_LIBPCAP
-  fprintf(stderr, "%s [-vh] [-kQS] [-b <bold font>] [-B <byte view height>] [-c count]\n",
+  fprintf(stderr, "%s [ -vh ] [ -kQS ] [ -b <bold font> ] [ -B <byte view height> ]\n",
          PACKAGE);
-  fprintf(stderr, "         [-f <capture filter>] [-i interface] [-m <medium font>] [-n]\n");
-  fprintf(stderr, "         [-P <packet list height>] [-r infile] [-R <read filter>]\n");
-  fprintf(stderr, "         [-s snaplen] [-t <time stamp format>] [-T <tree view height>]\n");
-  fprintf(stderr, "         [-w savefile]\n");
+  fprintf(stderr, "\t[ -c count ] [ -D ] [ -f <capture filter> ] [ -i interface ]\n");
+  fprintf(stderr, "\t[ -m <medium font> ] [ -n ] [ -P <packet list height> ] [ -r infile ]\n");
+  fprintf(stderr, "\t[ -R <read filter> ] [ -s snaplen ] [ -t <time stamp format> ]\n");
+  fprintf(stderr, "\t[ -T <tree view height> ] [ -w savefile ]\n");
 #else
-  fprintf(stderr, "%s [-vh] [-b <bold font>] [-B <byte view height>] [-m <medium font>]\n",
+  fprintf(stderr, "%s [ -vh ] [ -b <bold font> ] [ -B <byte view height> ]\n",
          PACKAGE);
-  fprintf(stderr, "         [-n] [-P <packet list height>] [-r infile] [-R <read filter>]\n");
-  fprintf(stderr, "         [-t <time stamp format>] [-T <tree view height>]\n");
+  fprintf(stderr, "\t[ -m <medium font> ] [ -n ] [ -P <packet list height> ] [ -r infile ]\n");
+  fprintf(stderr, "\t[ -R <read filter> ] [ -t <time stamp format> ]\n");
+  fprintf(stderr, "\t[ -T <tree view height> ]\n");
 #endif
 }
 
@@ -1026,6 +1027,7 @@ main(int argc, char *argv[])
 #ifdef HAVE_LIBPCAP
   gboolean             start_capture = FALSE;
   gchar               *save_file = NULL;
+  GList               *if_list;
   gchar                err_str[PCAP_ERRBUF_SIZE];
 #else
   gboolean             capture_option_specified = FALSE;
@@ -1039,11 +1041,7 @@ main(int argc, char *argv[])
   ethereal_path = argv[0];
 
 #ifdef HAVE_LIBPCAP
-  command_name = strrchr(ethereal_path, '/');
-  if (command_name == NULL)
-    command_name = ethereal_path;
-  else
-    command_name++;
+  command_name = get_basename(ethereal_path);
   /* Set "capture_child" to indicate whether this is going to be a child
      process for a "-S" capture. */
   capture_child = (strcmp(command_name, CHILD_NAME) == 0);
@@ -1156,7 +1154,7 @@ main(int argc, char *argv[])
 
 #ifndef WIN32
   /* Now get our args */
-  while ((opt = getopt(argc, argv, "b:B:c:f:hi:km:nP:Qr:R:Ss:t:T:w:W:v")) != EOF) {
+  while ((opt = getopt(argc, argv, "b:B:c:Df:hi:km:nP:Qr:R:Ss:t:T:w:W:v")) != EOF) {
     switch (opt) {
       case 'b':               /* Bold font */
        bold_font = g_strdup(optarg);
@@ -1172,6 +1170,9 @@ main(int argc, char *argv[])
         arg_error = TRUE;
 #endif
         break;
+      case 'D':        /* Turn off DSCP printing */
+       g_ip_dscp_actif = FALSE;
+       break;
       case 'f':
 #ifdef HAVE_LIBPCAP
        if (cf.cfilter)
@@ -1304,13 +1305,24 @@ main(int argc, char *argv[])
     /* We're supposed to do a live capture; did the user specify an interface
        to use? */
     if (cf.iface == NULL) {
-      /* No - have libpcap pick one. */
-      cf.iface = pcap_lookupdev(err_str);
-      if (cf.iface == NULL) {
-        /* It couldn't pick one. */
-        fprintf(stderr, "ethereal: %s\n", err_str);
+      /* No - pick the first one from the list of interfaces. */
+      if_list = get_interface_list(&err, err_str);
+      if (if_list == NULL) {
+        switch (err) {
+
+        case CANT_GET_INTERFACE_LIST:
+            fprintf(stderr, "ethereal: Can't get list of interfaces: %s\n",
+                       err_str);
+            break;
+
+        case NO_INTERFACES_FOUND:
+            fprintf(stderr, "ethereal: There are no interfaces on which a capture can be done\n");
+            break;
+        }
         exit(2);
       }
+      cf.iface = g_strdup(if_list->data);      /* first interface */
+      free_interface_list(if_list);
     }
   }
   if (capture_child) {
@@ -1527,6 +1539,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
                                get_column_longest_string(get_column_format(i)));
   }
   gtk_widget_set_usize(packet_list, -1, pl_size);
+  gtk_signal_connect_object(GTK_OBJECT(packet_list), "button_press_event",
+    GTK_SIGNAL_FUNC(popup_menu_handler), gtk_object_get_data(GTK_OBJECT(popup_menu_object), PM_PACKET_LIST_KEY));
   gtk_widget_show(packet_list);
   
   /* Tree view */
@@ -1550,6 +1564,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs)
     GTK_SIGNAL_FUNC(tree_view_select_row_cb), NULL);
   gtk_signal_connect(GTK_OBJECT(tree_view), "tree-unselect-row",
     GTK_SIGNAL_FUNC(tree_view_unselect_row_cb), NULL);
+  gtk_signal_connect_object(GTK_OBJECT(tree_view), "button_press_event",
+    GTK_SIGNAL_FUNC(popup_menu_handler), gtk_object_get_data(GTK_OBJECT(popup_menu_object), PM_TREE_VIEW_KEY));
   gtk_widget_show(tree_view);
 
   item_style = gtk_style_new();