sec_vt_header: dissect call_id
[metze/wireshark/wip.git] / capture_ui_utils.c
index 7af80a9a720783e7c3065bc6de52905e5b420654..b0dd7413828d1cb284001c4b6c5c6f4daf6f242d 100644 (file)
@@ -36,7 +36,6 @@
 #include "epan/ex-opt.h"
 #include "capture_ifinfo.h"
 #include "capture_ui_utils.h"
-#include "ui/simple_dialog.h"
 #include "wiretap/wtap.h"
 #include "epan/to_str.h"
 
@@ -92,7 +91,7 @@ capture_dev_user_descr_find(const gchar *if_name)
     /* Allocate enough space to return the string,
        which runs from p2 to p, plus a terminating
        '\0'. */
-    descr = g_malloc(p - p2 + 1);
+    descr = (char *)g_malloc(p - p2 + 1);
     memcpy(descr, p2, p - p2);
     descr[p - p2] = '\0';
     return descr;
@@ -132,6 +131,123 @@ capture_dev_user_linktype_find(const gchar *if_name)
   return (gint)linktype;
 }
 
+#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
+gint
+capture_dev_user_buffersize_find(const gchar *if_name)
+{
+  gchar *p, *next;
+  gint buffersize;
+
+  if ((prefs.capture_devices_buffersize == NULL) ||
+      (*prefs.capture_devices_buffersize == '\0')) {
+    /* There are no buffersizes defined */
+    return -1;
+  }
+
+  if ((p = strstr(prefs.capture_devices_buffersize, if_name)) == NULL) {
+    /* There are, but there isn't one for this interface. */
+    return -1;
+  }
+
+  p += strlen(if_name) + 1;
+  buffersize = (gint)strtol(p, &next, 10);
+  if (next == p || *next != ')' || buffersize < 0) {
+    /* Syntax error */
+    return -1;
+  }
+  if (buffersize > G_MAXINT) {
+    /* Value doesn't fit in a gint */
+    return -1;
+  }
+
+  return (gint)buffersize;
+}
+#endif
+
+gint
+capture_dev_user_snaplen_find(const gchar *if_name)
+{
+  gchar *p, *next;
+  gint snaplen;
+
+  if ((prefs.capture_devices_snaplen == NULL) ||
+      (*prefs.capture_devices_snaplen == '\0')) {
+    /* There is no snap length defined */
+    return -1;
+  }
+
+  if ((p = strstr(prefs.capture_devices_snaplen, if_name)) == NULL) {
+    /* There are, but there isn't one for this interface. */
+    return -1;
+  }
+
+  p += strlen(if_name) + 3;
+  snaplen = (gint)strtol(p, &next, 10);
+  if (next == p || *next != ')' || snaplen < 0) {
+    /* Syntax error */
+    return -1;
+  }
+  if (snaplen > WTAP_MAX_PACKET_SIZE) {
+    /* Value doesn't fit in a gint */
+    return -1;
+  }
+
+  return (gint)snaplen;
+}
+
+gboolean
+capture_dev_user_hassnap_find(const gchar *if_name)
+{
+  gchar *p, *next;
+  gboolean hassnap;
+
+  if ((prefs.capture_devices_snaplen == NULL) ||
+      (*prefs.capture_devices_snaplen == '\0')) {
+    /* There is no snap length defined */
+    return -1;
+  }
+
+  if ((p = strstr(prefs.capture_devices_snaplen, if_name)) == NULL) {
+    /* There are, but there isn't one for this interface. */
+    return -1;
+  }
+
+  p += strlen(if_name) + 1;
+  hassnap = (gboolean)strtol(p, &next, 10);
+  if (next == p || *next != '(') {
+    /* Syntax error */
+    return -1;
+  }
+
+  return (gboolean)hassnap;
+}
+
+gboolean
+capture_dev_user_pmode_find(const gchar *if_name)
+{
+  gchar *p, *next;
+  gboolean pmode;
+
+  if ((prefs.capture_devices_pmode == NULL) ||
+      (*prefs.capture_devices_pmode == '\0')) {
+    /* There is no promiscuous mode defined */
+    return -1;
+  }
+
+  if ((p = strstr(prefs.capture_devices_pmode, if_name)) == NULL) {
+    /* There are, but there isn't one for this interface. */
+    return -1;
+  }
+
+  p += strlen(if_name) + 1;
+  pmode = (gboolean)strtol(p, &next, 10);
+  if (next == p || *next != ')') {
+    /* Syntax error */
+    return -1;
+  }
+  return (gboolean)pmode;
+}
+
 /*
  * Return as descriptive a name for an interface as we can get.
  * If the user has specified a comment, use that.  Otherwise,
@@ -174,20 +290,24 @@ get_interface_descriptive_name(const char *if_name)
     /* No, we don't have a user-supplied description; did we get
        one from the OS or libpcap? */
     descr = NULL;
-    if_list = capture_interface_list(&err, NULL);
+    if_list = capture_interface_list(&err, NULL, NULL);
     if (if_list != NULL) {
       if_entry = if_list;
       do {
-        if_info = if_entry->data;
+        if_info = (if_info_t *)if_entry->data;
         if (strcmp(if_info->name, if_name) == 0) {
-          if (if_info->friendly_name!= NULL) {
-              /* use the friendly name */
+          if (if_info->friendly_name != NULL) {
+              /* We have a "friendly name"; return a copy of that
+                 as the description - when we free the interface
+                 list, that'll also free up the strings to which
+                 it refers. */
               descr = g_strdup(if_info->friendly_name);
-          }else if (if_info->description != NULL) {
-            /* Return a copy of that - when we free the interface
-               list, that'll also free up the strings to which
-               it refers. */
-            descr = g_strdup(if_info->description);
+          } else if (if_info->vendor_description != NULL) {
+            /* We have no "friendly name", but we have a vendor
+               description; return a copy of that - when we free
+               the interface list, that'll also free up the strings
+               to which it refers. */
+            descr = g_strdup(if_info->vendor_description);
           }
           break;
         }
@@ -214,7 +334,7 @@ search_info(GList *if_list, gchar *if_name)
 
 
   for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
-    if_info = if_entry->data;
+    if_info = (if_info_t *)if_entry->data;
 
     if(strcmp(if_name, if_info->name) == 0) {
       return if_info;
@@ -243,9 +363,9 @@ build_capture_combo_name(GList *if_list, gchar *if_name)
     /* No, we don't have a user-supplied description; did we get
      one from the OS or libpcap? */
     if_info = search_info(if_list, if_name);
-    if (if_info != NULL && if_info->description != NULL) {
+    if (if_info != NULL && if_info->vendor_description != NULL) {
       /* Yes - use it. */
-      if_string = g_strdup_printf("%s: %s", if_info->description,
+      if_string = g_strdup_printf("%s: %s", if_info->vendor_description,
                                   if_info->name);
     } else {
       /* No. */
@@ -271,7 +391,7 @@ build_capture_combo_list(GList *if_list, gboolean do_hide)
     /* Scan through the list and build a list of strings to display. */
     for (if_entry = if_list; if_entry != NULL;
          if_entry = g_list_next(if_entry)) {
-      if_info = if_entry->data;
+      if_info = (if_info_t *)if_entry->data;
 
       /* Is this interface hidden and, if so, should we include it
          anyway? */
@@ -287,9 +407,10 @@ build_capture_combo_list(GList *if_list, gboolean do_hide)
         } else {
           /* No, we don't have a user-supplied description; did we get
              one from the OS or libpcap? */
-          if (if_info->description != NULL) {
+          if (if_info->vendor_description != NULL) {
             /* Yes - use it. */
-            if_string = g_strdup_printf("%s: %s", if_info->description,
+            if_string = g_strdup_printf("%s: %s",
+                                        if_info->vendor_description,
                                         if_info->name);
           } else {
             /* No. */