[gupnp/wip/ipv6] wip: Handle link-local scope id things



commit a1c8cb3746d1fc8b6eb0e3e1410194c5f0636da0
Author: Jens Georg <mail jensge org>
Date:   Thu Feb 18 14:24:51 2016 +0100

    wip: Handle link-local scope id things
    
    Signed-off-by: Jens Georg <mail jensge org>

 libgupnp/gupnp-context.c     |   27 ++++++++++++++++++++-------
 libgupnp/gupnp-root-device.c |   12 ++++++++++++
 2 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 12d9da4..7515df0 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -576,9 +576,8 @@ gupnp_context_get_server (GUPnPContext *context)
         g_return_val_if_fail (GUPNP_IS_CONTEXT (context), NULL);
 
         if (context->priv->server == NULL) {
-                const char *ip = NULL;
-                guint port = 0;
-                GSocketAddress *addr = NULL;
+                GSocketAddress *addr;
+                GInetAddress *inet_addr;
                 GError *error = NULL;
 
                 context->priv->server = soup_server_new (NULL, NULL);
@@ -589,13 +588,26 @@ gupnp_context_get_server (GUPnPContext *context)
                                          context,
                                          NULL);
 
-                ip = gssdp_client_get_host_ip (GSSDP_CLIENT (context));
-                port = context->priv->port;
-                addr = g_inet_socket_address_new_from_string (ip, port);
+                inet_addr = gssdp_client_get_address (GSSDP_CLIENT (context));
+                if (g_inet_address_get_family (inet_addr) == G_SOCKET_FAMILY_IPV6 &&
+                    g_inet_address_get_is_link_local (inet_addr)) {
+                        guint scope;
+
+                        scope = gssdp_client_get_index (GSSDP_CLIENT (context));
+                        addr = g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
+                                             "address", inet_addr,
+                                             "port", context->priv->port,
+                                             "scope-id", scope,
+                                             NULL);
+                } else {
+                        addr = g_inet_socket_address_new (inet_addr,
+                                                          context->priv->port);
+                }
+                g_object_unref (inet_addr);
 
                 if (! soup_server_listen (context->priv->server,
                                           addr, (SoupServerListenOptions) 0, &error)) {
-                        g_warning ("GUPnPContext: Unable to listen on %s:%u %s", ip, port, error->message);
+                        g_warning ("GUPnPContext: Unable to listen on %s:%u %s", "", 0,  error->message);
                         g_error_free (error);
                 }
 
@@ -617,6 +629,7 @@ make_server_uri (GUPnPContext *context)
         {
                 SoupURI *uri = soup_uri_copy (uris->data);
                 g_slist_free_full (uris, (GDestroyNotify) soup_uri_free);
+
                 return uri;
         }
         return NULL;
diff --git a/libgupnp/gupnp-root-device.c b/libgupnp/gupnp-root-device.c
index cf207fc..e442acf 100644
--- a/libgupnp/gupnp-root-device.c
+++ b/libgupnp/gupnp-root-device.c
@@ -423,6 +423,18 @@ gupnp_root_device_constructor (GType                  type,
         /* Generate full location */
         uri = _gupnp_context_get_server_uri (context);
         soup_uri_set_path (uri, relative_location);
+        {
+                GInetAddress *addr = g_inet_address_new_from_string (soup_uri_get_host (uri));
+                if (g_inet_address_get_family (addr) == G_SOCKET_FAMILY_IPV6 &&
+                    g_inet_address_get_is_link_local (addr)) {
+                        char *new_host = g_strdup_printf ("%s%%%d",
+                                        soup_uri_get_host (uri),
+                                        gssdp_client_get_index (GSSDP_CLIENT (context)));
+                        soup_uri_set_host (uri, new_host);
+                        g_free (new_host);
+                }
+                g_object_unref (addr);
+        }
         location = soup_uri_to_string (uri, FALSE);
         soup_uri_free (uri);
 


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