[gssdp/wip/ipv6: 38/43] wip: ipv6 opts



commit 5fbf7063038481387336ecdd525852353f9a73b3
Author: Jens Georg <mail jensge org>
Date:   Thu Feb 18 10:00:21 2016 +0100

    wip: ipv6 opts

 libgssdp/gssdp-client.c           |  3 +++
 libgssdp/gssdp-socket-functions.c | 28 +++++++++++++-------
 libgssdp/gssdp-socket-functions.h |  1 +
 libgssdp/gssdp-socket-source.c    | 55 ++++++++++++++++++++++++++++++++-------
 libgssdp/gssdp-socket-source.h    |  1 +
 5 files changed, 69 insertions(+), 19 deletions(-)
---
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index 1c2e86b..aa54d55 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -255,6 +255,7 @@ gssdp_client_initable_init (GInitable                   *initable,
                                          client->priv->device.host_addr,
                                          client->priv->socket_ttl,
                                          client->priv->device.iface_name,
+                                         client->priv->device.index,
                                          &internal_error);
         if (client->priv->request_socket != NULL) {
                 gssdp_socket_source_set_callback
@@ -270,6 +271,7 @@ gssdp_client_initable_init (GInitable                   *initable,
                                          client->priv->device.host_addr,
                                          client->priv->socket_ttl,
                                          client->priv->device.iface_name,
+                                         client->priv->device.index,
                                          &internal_error);
         if (client->priv->multicast_socket != NULL) {
                 gssdp_socket_source_set_callback
@@ -291,6 +293,7 @@ gssdp_client_initable_init (GInitable                   *initable,
                                          "ttl", client->priv->socket_ttl,
                                          "port", client->priv->msearch_port,
                                          "device-name", client->priv->device.iface_name,
+                                         "index", client->priv->device.index,
                                          NULL));
 
         if (client->priv->search_socket != NULL) {
diff --git a/libgssdp/gssdp-socket-functions.c b/libgssdp/gssdp-socket-functions.c
index 0ba8c6d..70b3566 100644
--- a/libgssdp/gssdp-socket-functions.c
+++ b/libgssdp/gssdp-socket-functions.c
@@ -93,20 +93,30 @@ gssdp_socket_option_set (GSocket    *socket,
 gboolean
 gssdp_socket_mcast_interface_set (GSocket      *socket,
                                   GInetAddress *iface_address,
+                                  gint          index,
                                   GError      **error) {
 
         const guint8 *address;
         gsize native_size;
 
-        address = g_inet_address_to_bytes (iface_address);
-        native_size = g_inet_address_get_native_size (iface_address);
-
-        return gssdp_socket_option_set (socket,
-                                        IPPROTO_IP,
-                                        IP_MULTICAST_IF,
-                                        (char *) address,
-                                        native_size,
-                                        error);
+        if (g_inet_address_get_family (iface_address) == G_SOCKET_FAMILY_IPV6) {
+                return gssdp_socket_option_set (socket,
+                                                IPPROTO_IPV6,
+                                                IPV6_MULTICAST_IF,
+                                                (char *)&index,
+                                                sizeof (index),
+                                                error);
+        } else {
+                address = g_inet_address_to_bytes (iface_address);
+                native_size = g_inet_address_get_native_size (iface_address);
+
+                return gssdp_socket_option_set (socket,
+                                                IPPROTO_IP,
+                                                IP_MULTICAST_IF,
+                                                (char *) address,
+                                                native_size,
+                                                error);
+        }
 }
 
 #define __GSSDP_UNUSED(x) (void)(x)
diff --git a/libgssdp/gssdp-socket-functions.h b/libgssdp/gssdp-socket-functions.h
index 7eaae59..29ecc99 100644
--- a/libgssdp/gssdp-socket-functions.h
+++ b/libgssdp/gssdp-socket-functions.h
@@ -27,6 +27,7 @@
 G_GNUC_INTERNAL gboolean
 gssdp_socket_mcast_interface_set (GSocket       *socket,
                                   GInetAddress  *iface_address,
+                                  gint           index,
                                   GError       **error);
 G_GNUC_INTERNAL gboolean
 gssdp_socket_reuse_address       (GSocket *socket,
diff --git a/libgssdp/gssdp-socket-source.c b/libgssdp/gssdp-socket-source.c
index 931a44e..98f7b21 100644
--- a/libgssdp/gssdp-socket-source.c
+++ b/libgssdp/gssdp-socket-source.c
@@ -51,6 +51,7 @@ struct _GSSDPSocketSourcePrivate {
 
         GInetAddress         *address;
         char                 *device_name;
+        guint                 index;
         guint                 ttl;
         guint                 port;
 };
@@ -61,7 +62,8 @@ enum {
     PROP_ADDRESS,
     PROP_TTL,
     PROP_PORT,
-    PROP_IFA_NAME
+    PROP_IFA_NAME,
+    PROP_IFA_IDX
 };
 
 static void
@@ -125,6 +127,9 @@ gssdp_socket_source_set_property (GObject          *object,
         case PROP_PORT:
                 self->priv->port = g_value_get_uint (value);
                 break;
+        case PROP_IFA_IDX:
+                self->priv->index = g_value_get_uint (value);
+                break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                 break;
@@ -141,6 +146,7 @@ gssdp_socket_source_new (GSSDPSocketSourceType type,
                          GInetAddress         *address,
                          guint                 ttl,
                          const char           *device_name,
+                         guint                 index,
                          GError              **error)
 {
         return g_initable_new (GSSDP_TYPE_SOCKET_SOURCE,
@@ -154,6 +160,8 @@ gssdp_socket_source_new (GSSDPSocketSourceType type,
                                ttl,
                                "device-name",
                                device_name,
+                               "index",
+                               index,
                                NULL);
 }
 
@@ -168,6 +176,7 @@ gssdp_socket_source_do_init (GInitable                   *initable,
         GError *inner_error = NULL;
         GSocketFamily family;
         gboolean success = FALSE;
+        gboolean link_local = FALSE;
 
         self = GSSDP_SOCKET_SOURCE (initable);
 
@@ -181,6 +190,7 @@ gssdp_socket_source_do_init (GInitable                   *initable,
                  * address to use the proper multicast group */
                 if (g_inet_address_get_is_link_local (self->priv->address)) {
                             group = g_inet_address_new_from_string (SSDP_V6_LL);
+                            link_local = TRUE;
                 } else {
                             group = g_inet_address_new_from_string (SSDP_V6_SL);
                 }
@@ -202,7 +212,7 @@ gssdp_socket_source_do_init (GInitable                   *initable,
         }
 
         /* Enable broadcasting */
-        g_socket_set_broadcast (self->priv->socket, TRUE);
+/*        g_socket_set_broadcast (self->priv->socket, TRUE);
 
         if (!gssdp_socket_enable_info (self->priv->socket,
                                        TRUE,
@@ -213,13 +223,13 @@ gssdp_socket_source_do_init (GInitable                   *initable,
 
                 goto error;
         }
-
+*/
         /* TTL */
         if (!self->priv->ttl)
                 /* UDA/1.0 says 4, UDA/1.1 says 2 */
                 self->priv->ttl = 4;
 
-        g_socket_set_multicast_ttl (self->priv->socket, self->priv->ttl);
+        //g_socket_set_multicast_ttl (self->priv->socket, self->priv->ttl);
 
 
         /* Set up additional things according to the type of socket desired */
@@ -229,6 +239,7 @@ gssdp_socket_source_do_init (GInitable                   *initable,
 
                 if (!gssdp_socket_mcast_interface_set (self->priv->socket,
                                                        self->priv->address,
+                                                       (guint32) self->priv->index,
                                                        &inner_error)) {
                         g_propagate_prefixed_error (
                                         error,
@@ -242,8 +253,11 @@ gssdp_socket_source_do_init (GInitable                   *initable,
                 bind_address = g_inet_socket_address_new (iface_address,
                                                           SSDP_PORT);
 #else
-                bind_address = g_inet_socket_address_new (group,
-                                                          SSDP_PORT);
+                bind_address = g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
+                                             "address", group,
+                                             "port", SSDP_PORT,
+                                             "scope-id", self->priv->index,
+                                             NULL);
 #endif
         } else {
                 guint port = SSDP_PORT;
@@ -253,8 +267,17 @@ gssdp_socket_source_do_init (GInitable                   *initable,
                 if (self->priv->type == GSSDP_SOCKET_SOURCE_TYPE_SEARCH)
                         port = self->priv->port;
 
-                bind_address = g_inet_socket_address_new (self->priv->address,
-                                                          port);
+                if (link_local) {
+                    bind_address = g_object_new (G_TYPE_INET_SOCKET_ADDRESS,
+                                                 "address", self->priv->address,
+                                                 "port", port,
+                                                 "scope-id", self->priv->index,
+                                                 NULL);
+                } else {
+                    bind_address = g_inet_socket_address_new (self->priv->address,
+                                                              port);
+                }
+
         }
 
         /* Normally g_socket_bind does this, but it is disabled on
@@ -262,7 +285,7 @@ gssdp_socket_source_do_init (GInitable                   *initable,
          * there, also we nees SO_REUSEPORT on OpenBSD. This is a nop
          * everywhere else.
          */
-        if (!gssdp_socket_reuse_address (self->priv->socket,
+/*        if (!gssdp_socket_reuse_address (self->priv->socket,
                                          TRUE,
                                          &inner_error)) {
                 g_propagate_prefixed_error (
@@ -271,7 +294,7 @@ gssdp_socket_source_do_init (GInitable                   *initable,
                                 "Failed to enable reuse");
 
                 goto error;
-        }
+        } */
 
         /* Bind to requested port and address */
         if (!g_socket_bind (self->priv->socket,
@@ -469,4 +492,16 @@ gssdp_socket_source_class_init (GSSDPSocketSourceClass *klass)
                          0,
                          G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_STATIC_STRINGS));
+
+        g_object_class_install_property
+                (object_class,
+                 PROP_IFA_IDX,
+                 g_param_spec_uint
+                        ("index",
+                         "Interface index",
+                         "Interface index of the network device",
+                         0, G_MAXUINT16,
+                         0,
+                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS));
 }
diff --git a/libgssdp/gssdp-socket-source.h b/libgssdp/gssdp-socket-source.h
index 8aeca21..c7160dc 100644
--- a/libgssdp/gssdp-socket-source.h
+++ b/libgssdp/gssdp-socket-source.h
@@ -77,6 +77,7 @@ gssdp_socket_source_new        (GSSDPSocketSourceType  type,
                                 GInetAddress          *address,
                                 guint                  ttl,
                                 const char            *device_name,
+                                guint                  index,
                                 GError               **error);
 
 G_GNUC_INTERNAL GSocket*


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