gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18194 - in gnunet/src: transport util


From: gnunet
Subject: [GNUnet-SVN] r18194 - in gnunet/src: transport util
Date: Thu, 17 Nov 2011 19:04:31 +0100

Author: wachs
Date: 2011-11-17 19:04:31 +0100 (Thu, 17 Nov 2011)
New Revision: 18194

Modified:
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/util/os_network.c
Log:
send broadcasts on every interface


Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2011-11-17 16:39:10 UTC (rev 
18193)
+++ gnunet/src/transport/plugin_transport_udp.c 2011-11-17 18:04:31 UTC (rev 
18194)
@@ -262,7 +262,16 @@
 
 };
 
+struct BroadcastAddress
+{
+  struct BroadcastAddress *next;
+  struct BroadcastAddress *prev;
 
+  void * addr;
+  socklen_t addrlen;
+};
+
+
 /**
  * Encapsulation of all of the state of the plugin.
  */
@@ -351,6 +360,9 @@
    */
   struct GNUNET_NETWORK_Handle *sockv4_broadcast;
 
+  struct BroadcastAddress *head;
+  struct BroadcastAddress *tail;
+
   /**
    * ID of select broadcast task
    */
@@ -1506,15 +1518,11 @@
 //  /ssize_t ret;
   const struct GNUNET_MessageHeader *hello;
   struct UDP_Beacon_Message *msg;
+  struct BroadcastAddress * baddr;
 
   plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
 
-  struct sockaddr_in baddr;
 
-  baddr.sin_family = AF_INET;
-  baddr.sin_port = htons (plugin->broadcast_port);
-  baddr.sin_addr.s_addr = htonl (-1);   /* send message to 255.255.255.255 */
-
   hello = plugin->env->get_our_hello ();
   hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
   msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
@@ -1528,15 +1536,22 @@
   msg->header.size = ntohs (msg_size);
   msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
   memcpy (&msg[1], hello, hello_size);
+  sent = 0;
 
-  sent =
-      GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size,
-                                    (const struct sockaddr *) &baddr,
-                                    sizeof (struct sockaddr_in));
+  baddr = plugin->head;
+  while (baddr != NULL)
+  {
+    sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, 
msg_size,
+                                      baddr->addr,
+                                      baddr->addrlen);
+    if (sent == GNUNET_SYSERR)
+      GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "sendto");
+    else
+      LOG (GNUNET_ERROR_TYPE_ERROR, "Sent HELLO beacon broadcast with  %i 
bytes to address %s\n",
+           sent, GNUNET_a2s(baddr->addr, baddr->addrlen));
+      baddr = baddr->next;
+  }
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent HELLO beacon broadcast with  %i bytes\n",
-       sent);
-
   plugin->send_broadcast_task =
       GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
                                     &udp_broadcast_send, plugin);
@@ -1869,6 +1884,32 @@
 }
 
 
+static int
+iface_proc (void *cls, const char *name,
+            int isDefault,
+            const struct sockaddr * addr,
+            const struct sockaddr * broadcast_addr,
+            const struct sockaddr * netmask,
+            socklen_t addrlen)
+{
+  struct Plugin *plugin = cls;
+
+  if (broadcast_addr != NULL)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding broadcast address %s for 
interface %s %p\n ",
+        GNUNET_a2s(broadcast_addr,addrlen), name, broadcast_addr);
+
+    struct BroadcastAddress * ba = GNUNET_malloc(sizeof (struct 
BroadcastAddress));
+    ba->addr = GNUNET_malloc(addrlen);
+    memcpy(ba->addr, broadcast_addr, addrlen);
+    ba->addrlen = addrlen;
+
+    GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, ba);
+  }
+  return GNUNET_OK;
+}
+
+
 /**
  * The exported method. Makes the core api available via a global and
  * returns the udp transport API.
@@ -2183,8 +2224,10 @@
                                        plugin->broadcast_rs, NULL,
                                        &udp_plugin_broadcast_select, plugin);
 
+      GNUNET_OS_network_interfaces_list(iface_proc, plugin);
       plugin->send_broadcast_task =
-          GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin);
+        GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin);
+
     }
     else
       plugin->broadcast = GNUNET_NO;
@@ -2265,6 +2308,14 @@
       plugin->sockv4_broadcast = NULL;
     }
     GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs);
+
+    while (plugin->head != NULL)
+    {
+      struct BroadcastAddress * p= plugin->head;
+      GNUNET_CONTAINER_DLL_remove(plugin->head, plugin->tail, p);
+      GNUNET_free (p->addr);
+      GNUNET_free (p);
+    }
   }
 
   GNUNET_SERVER_mst_destroy (plugin->mst);

Modified: gnunet/src/util/os_network.c
===================================================================
--- gnunet/src/util/os_network.c        2011-11-17 16:39:10 UTC (rev 18193)
+++ gnunet/src/util/os_network.c        2011-11-17 18:04:31 UTC (rev 18194)
@@ -194,8 +194,8 @@
             proc (proc_cls, ifa_ptr->ifa_name,
                   0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE),
                   ifa_ptr->ifa_addr,
-                  NULL,
-                  NULL,
+                  ifa_ptr->ifa_broadaddr,
+                  ifa_ptr->ifa_netmask,
                   alen))
           break;
       }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]