gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r21433 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r21433 - gnunet/src/transport
Date: Fri, 11 May 2012 00:31:34 +0200

Author: grothoff
Date: 2012-05-11 00:31:34 +0200 (Fri, 11 May 2012)
New Revision: 21433

Modified:
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_wlan.c
Log:
-implementing WLAN string to address

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2012-05-10 22:24:00 UTC (rev 
21432)
+++ gnunet/src/transport/plugin_transport_tcp.c 2012-05-10 22:31:34 UTC (rev 
21433)
@@ -584,7 +584,7 @@
  *        If the function returns GNUNET_SYSERR, its contents are undefined.
  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
  */
-int
+static int
 tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen,
     void **buf, size_t *added)
 {

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2012-05-10 22:24:00 UTC 
(rev 21432)
+++ gnunet/src/transport/plugin_transport_wlan.c        2012-05-10 22:31:34 UTC 
(rev 21433)
@@ -23,9 +23,6 @@
  * @brief transport plugin for wlan
  * @author David Brodski
  * @author Christian Grothoff
- *
- * TODO:
- * - HELPER-continuation may be called after fragment times out (-> use after 
free, see FIXME)
  */
 #include "platform.h"
 #include "gnunet_hello_lib.h"
@@ -40,8 +37,6 @@
 #include "gnunet_fragmentation_lib.h"
 #include "gnunet_constants.h"
 
-#define PROTOCOL_PREFIX "wlan"
-
 #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__)
 
 /**
@@ -1463,7 +1458,6 @@
 static const char *
 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
 {
-  static char ret[40];
   const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
 
   if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
@@ -1472,10 +1466,7 @@
     return NULL;
   }
   mac = addr;
-  GNUNET_snprintf (ret, sizeof (ret), "%s MAC address %s",
-                   PROTOCOL_PREFIX, 
-                  mac_to_string (mac));
-  return ret;
+  return GNUNET_strdup (mac_to_string (mac));
 }
 
 
@@ -1512,10 +1503,7 @@
     return;
   }
   mac = addr;
-  GNUNET_asprintf (&ret,
-                   "%s MAC address %s",
-                   PROTOCOL_PREFIX, 
-                  mac_to_string (mac));
+  ret = GNUNET_strdup (mac_to_string (mac));
   asc (asc_cls, ret);
   GNUNET_free (ret);
   asc (asc_cls, NULL);
@@ -1579,6 +1567,57 @@
 
 
 /**
+ * Function called to convert a string address to
+ * a binary address.
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param addr string address
+ * @param addrlen length of the address
+ * @param buf location to store the buffer
+ * @param added location to store the number of bytes in the buffer.
+ *        If the function returns GNUNET_SYSERR, its contents are undefined.
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+static int
+wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
+                       void **buf, size_t *added)
+{
+  struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
+  unsigned int a[6];
+  unsigned int i;
+
+  if ((NULL == addr) || (addrlen == 0))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if ('\0' != addr[addrlen - 1])
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (strlen (addr) != addrlen - 1)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (6 != SSCANF (addr,
+                  "%X:%X:%X:%X:%X:%X", 
+                  &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  mac = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+  for (i=0;i<6;i++)
+    mac->mac[i] = a[i];
+  *buf = mac;
+  *added = sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress);
+  return GNUNET_OK;
+}
+
+
+/**
  * Entry point for the plugin.
  *
  * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
@@ -1602,7 +1641,7 @@
     api->cls = NULL;
     api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
     api->address_to_string = &wlan_plugin_address_to_string;
-    api->string_to_address = NULL; // FIXME!
+    api->string_to_address = &wlan_string_to_address;
     return api;
   }
 
@@ -1697,6 +1736,7 @@
   api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
   api->check_address = &wlan_plugin_address_suggested;
   api->address_to_string = &wlan_plugin_address_to_string;
+  api->string_to_address = &wlan_string_to_address;
   return api;
 }
 




reply via email to

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