summaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp_broadcasting.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-12-18 08:57:03 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-12-18 08:57:03 +0000
commitba6439dcf325a3e6e598c034e60815f39646562b (patch)
treedf633a1005504e92bb3abfdbc7623d968e1cf844 /src/transport/plugin_transport_udp_broadcasting.c
parent7f7906e96922d1f0410439ad08b3900937186ca5 (diff)
fixing 0003221: Crash in UDP broadcast: plugin_transport_udp_broadcasting.c:253.
Diffstat (limited to 'src/transport/plugin_transport_udp_broadcasting.c')
-rw-r--r--src/transport/plugin_transport_udp_broadcasting.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c
index 35c2a0ea5..61ac3d10e 100644
--- a/src/transport/plugin_transport_udp_broadcasting.c
+++ b/src/transport/plugin_transport_udp_broadcasting.c
@@ -612,6 +612,10 @@ setup_broadcast (struct Plugin *plugin,
GNUNET_SERVER_mst_create (&broadcast_ipv4_mst_cb, plugin);
plugin->broadcast_ipv6_mst =
GNUNET_SERVER_mst_create (&broadcast_ipv6_mst_cb, plugin);
+
+ if (GNUNET_YES != plugin->enable_broadcasting)
+ return; /* We do not send, just receive */
+
/* create IPv4 broadcast socket */
if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
{
@@ -626,6 +630,7 @@ setup_broadcast (struct Plugin *plugin,
ntohs (server_addrv4->sin_port));
}
}
+ /* create IPv6 multicast socket */
if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
{
memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6));
@@ -642,49 +647,55 @@ setup_broadcast (struct Plugin *plugin,
void
stop_broadcast (struct Plugin *plugin)
{
- while (plugin->broadcast_head != NULL)
+ if (GNUNET_YES == plugin->enable_broadcasting)
{
- struct BroadcastAddress *p = plugin->broadcast_head;
-
- if (p->broadcast_task != GNUNET_SCHEDULER_NO_TASK)
+ /* Disable broadcasting */
+ while (plugin->broadcast_head != NULL)
{
- GNUNET_SCHEDULER_cancel (p->broadcast_task);
- p->broadcast_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if ((GNUNET_YES == plugin->enable_ipv6) &&
- (NULL != plugin->sockv6) &&
- (p->addrlen == sizeof (struct sockaddr_in6)))
- {
- /* Create IPv6 multicast request */
- struct ipv6_mreq multicastRequest;
- const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
+ struct BroadcastAddress *p = plugin->broadcast_head;
- multicastRequest.ipv6mr_multiaddr =
- plugin->ipv6_multicast_address.sin6_addr;
- multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
-
- /* Leave the multicast group */
- if (GNUNET_OK ==
- GNUNET_NETWORK_socket_setsockopt
- (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
- &multicastRequest, sizeof (multicastRequest)))
+ if (p->broadcast_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, setsockopt);
+ GNUNET_SCHEDULER_cancel (p->broadcast_task);
+ p->broadcast_task = GNUNET_SCHEDULER_NO_TASK;
}
- else
+ if ((GNUNET_YES == plugin->enable_ipv6) &&
+ (NULL != plugin->sockv6) &&
+ (p->addrlen == sizeof (struct sockaddr_in6)))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
+ /* Create IPv6 multicast request */
+ struct ipv6_mreq multicastRequest;
+ const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
+
+ multicastRequest.ipv6mr_multiaddr =
+ plugin->ipv6_multicast_address.sin6_addr;
+ multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
+
+ /* Leave the multicast group */
+ if (GNUNET_OK ==
+ GNUNET_NETWORK_socket_setsockopt
+ (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
+ &multicastRequest, sizeof (multicastRequest)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, setsockopt);
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n");
+ }
}
- }
#if LINUX
GNUNET_DISK_file_close(p->cryogenic_fd);
#endif
- GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head,
- plugin->broadcast_tail, p);
- GNUNET_free (p->addr);
- GNUNET_free (p);
+ GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head,
+ plugin->broadcast_tail, p);
+ GNUNET_free (p->addr);
+ GNUNET_free (p);
+ }
}
+
+ /* Destroy MSTs */
if (NULL != plugin->broadcast_ipv4_mst)
{
GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv4_mst);