+ interface_opts.console_display_name = g_strdup(optarg_str_p);
+ interface_opts.if_type = capture_opts->default_options.if_type;
+#ifdef HAVE_EXTCAP
+ interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
+#endif
+ } else {
+ /*
+ * Retrieve the interface list so that we can search for the
+ * specified option amongst both the interface names and the
+ * friendly names and so that we find the friendly name even
+ * if an interface name was specified.
+ *
+ * If we can't get the list, just use the specified option as
+ * the interface name, so that the user can try specifying an
+ * interface explicitly for testing purposes.
+ */
+ if_list = capture_interface_list(&err, NULL, NULL);
+ if (if_list != NULL) {
+ /* try and do an exact match (case insensitive) */
+ GList *if_entry;
+ gboolean matched;
+
+ matched = FALSE;
+ for (if_entry = g_list_first(if_list); if_entry != NULL;
+ if_entry = g_list_next(if_entry))
+ {
+ if_info = (if_info_t *)if_entry->data;
+ /* exact name check */
+ if (g_ascii_strcasecmp(if_info->name, optarg_str_p) == 0) {
+ /* exact match on the interface name, use that for displaying etc */
+ interface_opts.name = g_strdup(if_info->name);
+
+ if (if_info->friendly_name != NULL) {
+ /*
+ * If we have a friendly name, use that for the
+ * console display name, as it is the basis for
+ * the auto generated temp filename.
+ */
+ interface_opts.console_display_name = g_strdup(if_info->friendly_name);
+ } else {
+ interface_opts.console_display_name = g_strdup(if_info->name);
+ }
+ interface_opts.if_type = if_info->type;
+#ifdef HAVE_EXTCAP
+ interface_opts.extcap = g_strdup(if_info->extcap);
+#endif
+ matched = TRUE;
+ break;
+ }
+
+ /* exact friendly name check */
+ if (if_info->friendly_name != NULL &&
+ g_ascii_strcasecmp(if_info->friendly_name, optarg_str_p) == 0) {
+ /* exact match - use the friendly name for display */
+ interface_opts.name = g_strdup(if_info->name);
+ interface_opts.console_display_name = g_strdup(if_info->friendly_name);
+ interface_opts.if_type = if_info->type;
+#ifdef HAVE_EXTCAP
+ interface_opts.extcap = g_strdup(if_info->extcap);
+#endif
+ matched = TRUE;
+ break;
+ }
+ }
+
+ /* didn't find, attempt a case insensitive prefix match of the friendly name*/
+ if (!matched) {
+ size_t prefix_length;
+
+ prefix_length = strlen(optarg_str_p);
+ for (if_entry = g_list_first(if_list); if_entry != NULL;
+ if_entry = g_list_next(if_entry))
+ {
+ if_info = (if_info_t *)if_entry->data;
+
+ if (if_info->friendly_name != NULL &&
+ g_ascii_strncasecmp(if_info->friendly_name, optarg_str_p, prefix_length) == 0) {
+ /* prefix match - use the friendly name for display */
+ interface_opts.name = g_strdup(if_info->name);
+ interface_opts.console_display_name = g_strdup(if_info->friendly_name);
+ interface_opts.if_type = if_info->type;
+#ifdef HAVE_EXTCAP
+ interface_opts.extcap = g_strdup(if_info->extcap);
+#endif
+ matched = TRUE;
+ break;
+ }
+ }
+ }
+ if (!matched) {
+ /*
+ * We didn't find the interface in the list; just use
+ * the specified name, so that, for example, if an
+ * interface doesn't show up in the list for some
+ * reason, the user can try specifying it explicitly
+ * for testing purposes.
+ */
+ interface_opts.name = g_strdup(optarg_str_p);
+ interface_opts.console_display_name = g_strdup(optarg_str_p);
+ interface_opts.if_type = capture_opts->default_options.if_type;
+#ifdef HAVE_EXTCAP
+ interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
+#endif
+ }
+ free_interface_list(if_list);
+ } else {
+ interface_opts.name = g_strdup(optarg_str_p);
+ interface_opts.console_display_name = g_strdup(optarg_str_p);
+ interface_opts.if_type = capture_opts->default_options.if_type;
+#ifdef HAVE_EXTCAP
+ interface_opts.extcap = g_strdup(capture_opts->default_options.extcap);
+#endif
+ }