[gvfs/wip/oholy/davs-sd-ipv6: 15/16] dnssd: Add support for interfaces



commit 5b4599d6f3dc8f098197f6395c482a47f761557d
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Oct 10 17:26:12 2019 +0200

    dnssd: Add support for interfaces
    
    GVfsDnsSdResolver doesn't store interface for the resolved service,
    however, we need this for link-local address support. Let's add the
    missing bits for it.

 common/gvfsdnssdresolver.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 common/gvfsdnssdresolver.h |  1 +
 2 files changed, 53 insertions(+)
---
diff --git a/common/gvfsdnssdresolver.c b/common/gvfsdnssdresolver.c
index 8782f5fc..0e5356ab 100644
--- a/common/gvfsdnssdresolver.c
+++ b/common/gvfsdnssdresolver.c
@@ -37,6 +37,8 @@
 #include <avahi-glib/glib-watch.h>
 #include <avahi-glib/glib-malloc.h>
 
+#include <net/if.h>
+
 #include "gvfsdnssdutils.h"
 #include "gvfsdnssdresolver.h"
 
@@ -52,6 +54,7 @@ enum
 
   PROP_IS_RESOLVED,
   PROP_ADDRESS,
+  PROP_INTERFACE,
   PROP_PORT,
   PROP_TXT_RECORDS,
 };
@@ -77,6 +80,7 @@ struct _GVfsDnsSdResolver
 
   gboolean is_resolved;
   char *address;
+  gchar *interface;
   guint port;
   char **txt_records;
 
@@ -293,6 +297,10 @@ g_vfs_dns_sd_resolver_get_property (GObject    *object,
       g_value_set_string (value, resolver->address);
       break;
 
+    case PROP_INTERFACE:
+      g_value_set_string (value, resolver->interface);
+      break;
+
     case PROP_PORT:
       g_value_set_uint (value, resolver->port);
       break;
@@ -365,6 +373,7 @@ g_vfs_dns_sd_resolver_finalize (GObject *object)
   g_strfreev (resolver->required_txt_keys_broken_out);
 
   g_free (resolver->address);
+  g_free (resolver->interface);
   g_strfreev (resolver->txt_records);
 
   if (resolver->avahi_resolver != NULL)
@@ -633,6 +642,22 @@ g_vfs_dns_sd_resolver_class_init (GVfsDnsSdResolverClass *klass)
                                                         G_PARAM_STATIC_BLURB |
                                                         G_PARAM_STATIC_NICK));
 
+  /**
+   * GVfsDnsSdResolver:interface:
+   *
+   * The resolved interface.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_INTERFACE,
+                                   g_param_spec_string ("interface",
+                                                        "Interface",
+                                                        "Interface",
+                                                        NULL,
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_STATIC_NICK));
+
   /**
    * GVfsDnsSdResolver:port:
    *
@@ -722,6 +747,13 @@ g_vfs_dns_sd_resolver_get_address (GVfsDnsSdResolver *resolver)
   return g_strdup (resolver->address);
 }
 
+gchar *
+g_vfs_dns_sd_resolver_get_interface (GVfsDnsSdResolver *resolver)
+{
+  g_return_val_if_fail (G_VFS_IS_DNS_SD_RESOLVER (resolver), NULL);
+  return g_strdup (resolver->interface);
+}
+
 guint
 g_vfs_dns_sd_resolver_get_port (GVfsDnsSdResolver *resolver)
 {
@@ -883,10 +915,12 @@ set_avahi_data (GVfsDnsSdResolver    *resolver,
                 const char           *host_name,
                 AvahiProtocol         protocol,
                 const AvahiAddress   *a,
+                AvahiIfIndex          interface,
                 uint16_t              port,
                 AvahiStringList      *txt)
 {
   char *address;
+  gchar ifname[IF_NAMESIZE];
   gboolean changed;
   AvahiStringList *l;
   GPtrArray *p;
@@ -925,6 +959,15 @@ set_avahi_data (GVfsDnsSdResolver    *resolver,
 
   g_free (address);
 
+  if_indextoname (interface, ifname);
+  if (safe_strcmp (resolver->interface, ifname) != 0)
+    {
+      g_free (resolver->interface);
+      resolver->interface = g_strdup (ifname);
+      g_object_notify (G_OBJECT (resolver), "interface");
+      changed = TRUE;
+    }
+
   if (resolver->port != port)
     {
       resolver->port = port;
@@ -987,6 +1030,14 @@ clear_avahi_data (GVfsDnsSdResolver *resolver)
       changed = TRUE;
     }
 
+  if (resolver->interface != NULL)
+    {
+      g_free (resolver->interface);
+      resolver->interface = NULL;
+      g_object_notify (G_OBJECT (resolver), "interface");
+      changed = TRUE;
+    }
+
   if (resolver->port != 0)
     {
       resolver->port = 0;
@@ -1029,6 +1080,7 @@ service_resolver_cb (AvahiServiceResolver   *avahi_resolver,
                       host_name,
                       protocol,
                       a,
+                      interface,
                       port,
                       txt);
       break;
diff --git a/common/gvfsdnssdresolver.h b/common/gvfsdnssdresolver.h
index 425a4603..00a8976c 100644
--- a/common/gvfsdnssdresolver.h
+++ b/common/gvfsdnssdresolver.h
@@ -70,6 +70,7 @@ gboolean             g_vfs_dns_sd_resolver_resolve_sync           (GVfsDnsSdReso
 
 gboolean             g_vfs_dns_sd_resolver_is_resolved            (GVfsDnsSdResolver  *resolver);
 gchar               *g_vfs_dns_sd_resolver_get_address            (GVfsDnsSdResolver  *resolver);
+gchar               *g_vfs_dns_sd_resolver_get_interface          (GVfsDnsSdResolver  *resolver);
 guint                g_vfs_dns_sd_resolver_get_port               (GVfsDnsSdResolver  *resolver);
 gchar              **g_vfs_dns_sd_resolver_get_txt_records        (GVfsDnsSdResolver  *resolver);
 gchar               *g_vfs_dns_sd_resolver_lookup_txt_record      (GVfsDnsSdResolver  *resolver,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]