packet-iwarp-mpa: give more information if the ULPDU length doesn't match
[metze/wireshark/wip.git] / capture_ui_utils.c
index e58f789b034926dbdef580f34229fef3b7dbb3a4..b0dd7413828d1cb284001c4b6c5c6f4daf6f242d 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #ifdef HAVE_LIBPCAP
 
@@ -38,7 +36,6 @@
 #include "epan/ex-opt.h"
 #include "capture_ifinfo.h"
 #include "capture_ui_utils.h"
-#include "simple_dialog.h"
 #include "wiretap/wtap.h"
 #include "epan/to_str.h"
 
 char *
 capture_dev_user_descr_find(const gchar *if_name)
 {
-       char    *p;
-       char    *p2 = NULL;
-       char    *descr = NULL;
-       int     lp = 0;
-       int     ct = 0;
-
-       if (prefs.capture_devices_descr == NULL) {
-               /* There are no descriptions. */
-               return NULL;
-       }
-
-       if ((p = strstr(prefs.capture_devices_descr, if_name)) == NULL) {
-               /* There are, but there isn't one for this interface. */
-               return NULL;
-       }
-
-       while (*p != '\0') {
-               /* error: ran into next interface description */
-               if (*p == ',')
-                       return NULL;
-               /* found left parenthesis, start of description */
-               else if (*p == '(') {
-                       ct = 0;
-                       lp++;
-                       /* skip over left parenthesis */
-                       p++;
-                       /* save pointer to beginning of description */
-                       p2 = p;
-                       continue;
-               }
-               else if (*p == ')') {
-                       /* end of description */
-                       break;
-               }
-               else {
-                       p++;
-                       ct++;
-               }
-       }
-
-       if ((lp == 1) && (ct > 0) && (p2 != NULL)) {
-               /* Allocate enough space to return the string,
-                  which runs from p2 to p, plus a terminating
-                  '\0'. */
-               descr = g_malloc(p - p2 + 1);
-               memcpy(descr, p2, p - p2);
-               descr[p - p2] = '\0';
-               return descr;
-       }
-       else
-               return NULL;
+  char *p;
+  char *p2 = NULL;
+  char *descr = NULL;
+  int lp = 0;
+  int ct = 0;
+
+  if ((prefs.capture_devices_descr == NULL) ||
+      (*prefs.capture_devices_descr == '\0')) {
+    /* There are no descriptions. */
+    return NULL;
+  }
+
+  if ((p = strstr(prefs.capture_devices_descr, if_name)) == NULL) {
+    /* There are, but there isn't one for this interface. */
+    return NULL;
+  }
+
+  while (*p != '\0') {
+    /* error: ran into next interface description */
+    if (*p == ',')
+      return NULL;
+    /* found left parenthesis, start of description */
+    else if (*p == '(') {
+      ct = 0;
+      lp++;
+      /* skip over left parenthesis */
+      p++;
+      /* save pointer to beginning of description */
+      p2 = p;
+      continue;
+    }
+    else if (*p == ')') {
+      /* end of description */
+      break;
+    }
+    else {
+        p++;
+        ct++;
+    }
+  }
+
+  if ((lp == 1) && (ct > 0) && (p2 != NULL)) {
+    /* Allocate enough space to return the string,
+       which runs from p2 to p, plus a terminating
+       '\0'. */
+    descr = (char *)g_malloc(p - p2 + 1);
+    memcpy(descr, p2, p - p2);
+    descr[p - p2] = '\0';
+    return descr;
+  }
+  else
+    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;
+  gchar *p, *next;
+  long linktype;
+
+  if ((prefs.capture_devices_linktypes == NULL) ||
+      (*prefs.capture_devices_linktypes == '\0')) {
+    /* 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;
+}
+
+#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;
 }
 
 /*
@@ -174,17 +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->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);
+          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->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;
         }
@@ -211,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;
@@ -240,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. */
@@ -267,8 +390,8 @@ build_capture_combo_list(GList *if_list, gboolean do_hide)
   if (if_list != NULL) {
     /* 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_entry = g_list_next(if_entry)) {
+      if_info = (if_info_t *)if_entry->data;
 
       /* Is this interface hidden and, if so, should we include it
          anyway? */
@@ -278,16 +401,17 @@ build_capture_combo_list(GList *if_list, gboolean do_hide)
         /* 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);
+          /* 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) {
+             one from the OS or libpcap? */
+          if (if_info->vendor_description != NULL) {
             /* Yes - use it. */
-               if_string = g_strdup_printf("%s: %s", if_info->description,
-                                       if_info->name);
+            if_string = g_strdup_printf("%s: %s",
+                                        if_info->vendor_description,
+                                        if_info->name);
           } else {
             /* No. */
             if_string = g_strdup(if_info->name);