[vino] Make Avahi use the VinoServer interface.



commit 4b1959335c0dd1ba9ee548402c60bcc281c8ae02
Author: Jonh Wendell <jwendell gnome org>
Date:   Thu Sep 3 10:35:59 2009 -0300

    Make Avahi use the VinoServer interface.
    
    Closes #593191 -  Still publishing over avahi if network_interface is set

 server/vino-mdns.c  |   27 +++++++++++++++++++++++----
 server/vino-mdns.h  |    2 +-
 server/vino-prefs.c |    7 ++++---
 3 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/server/vino-mdns.c b/server/vino-mdns.c
index d396412..ab35f73 100644
--- a/server/vino-mdns.c
+++ b/server/vino-mdns.c
@@ -27,6 +27,7 @@
 
 #ifdef VINO_HAVE_AVAHI
 
+#include <net/if.h>
 #include <string.h>
 #include <avahi-client/publish.h>
 #include <avahi-common/alternative.h>
@@ -43,6 +44,7 @@ static AvahiGLibPoll   *mdns_glib_poll = NULL;
 static AvahiClient     *mdns_client = NULL;
 static AvahiEntryGroup *mdns_entry_group = NULL;
 char                   *mdns_service_name = NULL; 
+char                   *iface_name = NULL;
 
 static const char *
 vino_mdns_get_service_name (void)
@@ -130,11 +132,22 @@ vino_mdns_add_service_foreach (char            *type,
 {
   int port;
   int ret;
+  int iface;
 
   port = GPOINTER_TO_INT (value);
 
+  if (iface_name && iface_name[0])
+    {
+      if (if_nametoindex (iface_name) == 0)
+	iface = AVAHI_IF_UNSPEC;
+      else
+	iface = if_nametoindex (iface_name);
+    }
+  else
+    iface = AVAHI_IF_UNSPEC;
+
   ret = avahi_entry_group_add_service (mdns_entry_group, 
-                                       AVAHI_IF_UNSPEC, 
+                                       iface,
                                        AVAHI_PROTO_UNSPEC, 
                                        0,
                                        vino_mdns_get_service_name (), 
@@ -203,7 +216,7 @@ vino_mdns_restart (void)
     avahi_client_free (mdns_client);
   mdns_client = NULL;
 
-  vino_mdns_start ();
+  vino_mdns_start (iface_name);
 }
 
 static void
@@ -269,7 +282,7 @@ vino_mdns_add_service (const char *type,
 }
 
 void
-vino_mdns_start ()
+vino_mdns_start (const char *iface)
 {
   dprintf (MDNS, "Starting MDNS support.\n");
 
@@ -279,6 +292,9 @@ vino_mdns_start ()
   if (mdns_services == NULL)
     return; /* no services */
 
+  g_free (iface_name);
+  iface_name = g_strdup (iface);
+
   if (mdns_glib_poll == NULL)
     {
       avahi_set_allocator (avahi_glib_allocator ());
@@ -308,6 +324,9 @@ vino_mdns_stop (void)
     g_free (mdns_service_name);
   mdns_service_name = NULL;
 
+  g_free (iface_name);
+  iface_name = NULL;
+
   if (mdns_entry_group != NULL)
     avahi_entry_group_free (mdns_entry_group);
   mdns_entry_group = NULL;
@@ -348,7 +367,7 @@ vino_mdns_add_service (const char *type,
 }
 
 void
-vino_mdns_start (void)
+vino_mdns_start (const char *iface)
 {
 }
 
diff --git a/server/vino-mdns.h b/server/vino-mdns.h
index 4f1f17e..a39ddb6 100644
--- a/server/vino-mdns.h
+++ b/server/vino-mdns.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
 void vino_mdns_add_service (const char *type,
                             int         port);
 
-void vino_mdns_start (void);
+void vino_mdns_start (const char *iface);
 void vino_mdns_stop  (void);
 void vino_mdns_shutdown (void);
 
diff --git a/server/vino-prefs.c b/server/vino-prefs.c
index 642adf6..fb9645b 100644
--- a/server/vino-prefs.c
+++ b/server/vino-prefs.c
@@ -95,7 +95,7 @@ vino_prefs_enabled_changed (GConfClient *client,
   dprintf (PREFS, "Access enabled changed: %s\n", vino_enabled ? "(true)" : "(false)");
 
   if (vino_enabled)
-    vino_mdns_start ();
+    vino_mdns_start (vino_network_interface);
   else
     vino_mdns_stop ();
 
@@ -299,7 +299,7 @@ vino_prefs_restart_mdns (VinoServer *server, gpointer data)
 {
   vino_mdns_stop ();
   vino_mdns_add_service ("_rfb._tcp", vino_server_get_port (server));
-  vino_mdns_start ();
+  vino_mdns_start (vino_network_interface);
 }
 
 static void
@@ -519,10 +519,11 @@ vino_prefs_create_server (GdkScreen *screen)
 
   vino_servers = g_slist_prepend (vino_servers, server);
   if (vino_enabled)
-    vino_mdns_start ();
+    vino_mdns_start (vino_network_interface);
 
   g_signal_connect (server, "notify::alternative-port", G_CALLBACK (vino_prefs_restart_mdns), NULL);
   g_signal_connect (server, "notify::use-alternative-port", G_CALLBACK(vino_prefs_restart_mdns), NULL);
+  g_signal_connect (server, "notify::network-interface", G_CALLBACK (vino_prefs_restart_mdns), NULL);
 
   icon = vino_server_get_status_icon (server);
   vino_status_icon_set_visibility (icon, vino_icon_visibility);



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