[Automatic manuf and enterprise-numbers update for 2010-04-04]
[obnox/wireshark/wip.git] / capture_ui_utils.c
index 0c58a0ccd1cbfc0973649660435f89e03b6a1ebb..f6ff8c3fb85fe4b8b11e99956dfdaf16e333b4d6 100644 (file)
 #ifdef HAVE_LIBPCAP
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #include <glib.h>
 
-#include <epan/prefs.h>
-#include "capture-pcap-util.h"
+#include "epan/prefs.h"
+#include "epan/ex-opt.h"
+#include "capture_ifinfo.h"
 #include "capture_ui_utils.h"
 
 /*
  * Find user-specified capture device description that matches interface
  * name, if any.
  */
-static char *
+char *
 capture_dev_user_descr_find(const gchar *if_name)
 {
        char    *p;
@@ -96,15 +99,45 @@ capture_dev_user_descr_find(const gchar *if_name)
                return NULL;
 }
 
+gint
+capture_dev_user_linktype_find(const gchar *if_name)
+{
+       gchar *p, *next;
+       long linktype;
+
+       if (prefs.capture_devices_linktypes == NULL) {
+               /* There are no link-layer header types */
+               return -1;
+       }
+
+       if ((p = strstr(prefs.capture_devices_linktypes, if_name)) == NULL) {
+               /* There are, but there isn't one for this interface. */
+               return -1;
+       }
+
+       p += strlen(if_name) + 1;
+       linktype = strtol(p, &next, 10);
+       if (next == p || *next != ')' || linktype < 0) {
+               /* Syntax error */
+               return -1;
+       }
+       if (linktype > G_MAXINT) {
+               /* Value doesn't fit in a gint */
+               return -1;
+       }
+
+       return (gint)linktype;
+}
+
 /*
  * Return as descriptive a name for an interface as we can get.
  * If the user has specified a comment, use that.  Otherwise,
- * if get_interface_list() supplies a description, use that,
+ * if capture_interface_list() supplies a description, use that,
  * otherwise use the interface name.
  *
  * The result must be g_free()'d when you're done with it.
  *
- * Note: given that this calls get_interface_list(), which attempts to
+ * Note: given that this calls capture_interface_list(), which attempts to
  * open all adapters it finds in order to check whether they can be
  * captured on, this is an expensive routine to call, so don't call it
  * frequently.
@@ -123,11 +156,16 @@ get_interface_descriptive_name(const char *if_name)
   if (descr != NULL) {
     /* Yes - make a copy of that. */
     descr = g_strdup(descr);
+  } else if (strcmp(if_name, "-") == 0) {
+    descr = g_strdup(ex_opt_get_nth("stdin_descr", 0));
+    if (!descr) {
+      descr = g_strdup("Standard input");
+    }
   } else {
     /* No, we don't have a user-supplied description; did we get
        one from the OS or libpcap? */
     descr = NULL;
-    if_list = get_interface_list(&err, NULL);
+    if_list = capture_interface_list(&err, NULL);
     if (if_list != NULL && if_name != NULL) {
       if_entry = if_list;
       do {
@@ -227,29 +265,29 @@ build_capture_combo_list(GList *if_list, gboolean do_hide)
       /* Is this interface hidden and, if so, should we include it
          anyway? */
       if (!prefs_is_capture_device_hidden(if_info->name) || !do_hide) {
-       /* It's not hidden, or it is but we should include it in the list. */
-
-       /* Do we have a user-supplied description? */
-       descr = capture_dev_user_descr_find(if_info->name);
-       if (descr != NULL) {
-         /* Yes, we have a user-supplied description; use it. */
-         if_string = g_strdup_printf("%s: %s", descr, if_info->name);
-         g_free(descr);
-       } else {
-         /* No, we don't have a user-supplied description; did we get
-            one from the OS or libpcap? */
-         if (if_info->description != NULL) {
-           /* Yes - use it. */
-           if_string = g_strdup_printf("%s: %s", if_info->description,
+        /* It's not hidden, or it is but we should include it in the list. */
+
+        /* Do we have a user-supplied description? */
+        descr = capture_dev_user_descr_find(if_info->name);
+        if (descr != NULL) {
+             /* Yes, we have a user-supplied description; use it. */
+             if_string = g_strdup_printf("%s: %s", descr, if_info->name);
+          g_free(descr);
+        } else {
+          /* No, we don't have a user-supplied description; did we get
+                one from the OS or libpcap? */
+          if (if_info->description != NULL) {
+            /* Yes - use it. */
+               if_string = g_strdup_printf("%s: %s", if_info->description,
                                        if_info->name);
-         } else {
-           /* No. */
-           if_string = g_strdup(if_info->name);
-         }
-       }
-       combo_list = g_list_append(combo_list, if_string);
+          } else {
+            /* No. */
+            if_string = g_strdup(if_info->name);
+          }
+        }
+        combo_list = g_list_append(combo_list, if_string);
       }
-    }
+    }/*for*/
   }
   return combo_list;
 }