#ifdef HAVE_LIBPCAP
+#include <stdio.h>
#include <string.h>
#include <glib.h>
* If the user has specified a comment, use that. Otherwise,
* if get_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
+ * 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.
*/
char *
get_interface_descriptive_name(const char *if_name)
one from the OS or libpcap? */
descr = NULL;
if_list = get_interface_list(&err, NULL);
- if (if_list != NULL) {
+ if (if_list != NULL && if_name != NULL) {
if_entry = if_list;
do {
if_info = if_entry->data;
/* 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 == ' ')
return if_name;
}
+/* Return capture_opts->iface_descr (after setting it if it is not set)
+ * This is necessary because capture_opts.c can't set iface_descr (at least
+ * not without adding significant dependencies there).
+ */
+const char *
+get_iface_description(capture_options *capture_opts)
+{
+ if (!capture_opts->iface_descr && capture_opts->iface)
+ capture_opts->iface_descr = get_interface_descriptive_name(capture_opts->iface);
+
+ return(capture_opts->iface_descr);
+
+}
#endif /* HAVE_LIBPCAP */