#ifdef HAVE_LIBPCAP
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <glib.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;
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,
/* Is this interface hidden and, if so, should we include it
anyway? */
- if (prefs.capture_devices_hide == NULL ||
- strstr(prefs.capture_devices_hide, if_info->name) == NULL ||
- !do_hide) {
+ 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? */
* it'll be followed by a blank if it separates the description
* and the interface name. (We don't wire in "rpcap", in case we
* support other protocols in the same syntax.)
+ * Unfortunately, another colon can be used in "rpcap://host:port/"
+ * before port. Check if colon is followed by digit.
*/
- if (strncmp(if_name, "://", 3) != 0) {
+ if ((strncmp(if_name, "://", 3) != 0) && !isdigit(if_name[1])) {
/*
- * OK, we've found a colon not followed by "//". Skip blanks
- * following it.
+ * OK, we've found a colon followed neither by "//" nor by digit.
+ * Skip blanks following it.
*/
if_name++;
while (*if_name == ' ')
const char *
get_iface_description(capture_options *capture_opts)
{
- if (!capture_opts->iface_descr)
+ if (!capture_opts->iface_descr && capture_opts->iface)
capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
return(capture_opts->iface_descr);