[gssdp/wip/ipv6: 4/7] wip: ipv6 opts
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gssdp/wip/ipv6: 4/7] wip: ipv6 opts
- Date: Thu, 18 Feb 2016 10:21:00 +0000 (UTC)
commit 425752f0107b719139bbf99ed86788527782514b
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 0769885..32bbb60 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -242,6 +242,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
@@ -257,6 +258,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
@@ -278,6 +280,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 68109a2..bcc2d68 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 7fbc354..7a815a8 100644
--- a/libgssdp/gssdp-socket-source.c
+++ b/libgssdp/gssdp-socket-source.c
@@ -60,6 +60,7 @@ struct _GSSDPSocketSourcePrivate {
GInetAddress *address;
char *device_name;
+ guint index;
guint ttl;
guint port;
};
@@ -70,7 +71,8 @@ enum {
PROP_ADDRESS,
PROP_TTL,
PROP_PORT,
- PROP_IFA_NAME
+ PROP_IFA_NAME,
+ PROP_IFA_IDX
};
static void
@@ -134,6 +136,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;
@@ -150,6 +155,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,
@@ -163,6 +169,8 @@ gssdp_socket_source_new (GSSDPSocketSourceType type,
ttl,
"device-name",
device_name,
+ "index",
+ index,
NULL);
}
@@ -177,6 +185,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);
@@ -190,6 +199,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);
}
@@ -211,7 +221,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,
@@ -222,13 +232,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 */
@@ -238,6 +248,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,
@@ -251,8 +262,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;
@@ -262,8 +276,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
@@ -271,7 +294,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 (
@@ -280,7 +303,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,
@@ -478,4 +501,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]