diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-10 22:31:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-10 22:31:34 +0000 |
commit | b1ab6811dd4518fd54bd99678c3563e92373d1e5 (patch) | |
tree | 3867979be72e561e9cef4a5336dad3c3ffaf8cbc /src/transport/plugin_transport_wlan.c | |
parent | 8b7ba67e4e201aaa44ef60b51396e29dc379d1fd (diff) | |
download | gnunet-b1ab6811dd4518fd54bd99678c3563e92373d1e5.tar.gz gnunet-b1ab6811dd4518fd54bd99678c3563e92373d1e5.zip |
-implementing WLAN string to address
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 03d9b4361..dbede94a8 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -23,9 +23,6 @@ | |||
23 | * @brief transport plugin for wlan | 23 | * @brief transport plugin for wlan |
24 | * @author David Brodski | 24 | * @author David Brodski |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | * | ||
27 | * TODO: | ||
28 | * - HELPER-continuation may be called after fragment times out (-> use after free, see FIXME) | ||
29 | */ | 26 | */ |
30 | #include "platform.h" | 27 | #include "platform.h" |
31 | #include "gnunet_hello_lib.h" | 28 | #include "gnunet_hello_lib.h" |
@@ -40,8 +37,6 @@ | |||
40 | #include "gnunet_fragmentation_lib.h" | 37 | #include "gnunet_fragmentation_lib.h" |
41 | #include "gnunet_constants.h" | 38 | #include "gnunet_constants.h" |
42 | 39 | ||
43 | #define PROTOCOL_PREFIX "wlan" | ||
44 | |||
45 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__) | 40 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__) |
46 | 41 | ||
47 | /** | 42 | /** |
@@ -1463,7 +1458,6 @@ wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) | |||
1463 | static const char * | 1458 | static const char * |
1464 | wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 1459 | wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
1465 | { | 1460 | { |
1466 | static char ret[40]; | ||
1467 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; | 1461 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; |
1468 | 1462 | ||
1469 | if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen) | 1463 | if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen) |
@@ -1472,10 +1466,7 @@ wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
1472 | return NULL; | 1466 | return NULL; |
1473 | } | 1467 | } |
1474 | mac = addr; | 1468 | mac = addr; |
1475 | GNUNET_snprintf (ret, sizeof (ret), "%s MAC address %s", | 1469 | return GNUNET_strdup (mac_to_string (mac)); |
1476 | PROTOCOL_PREFIX, | ||
1477 | mac_to_string (mac)); | ||
1478 | return ret; | ||
1479 | } | 1470 | } |
1480 | 1471 | ||
1481 | 1472 | ||
@@ -1512,10 +1503,7 @@ wlan_plugin_address_pretty_printer (void *cls, const char *type, | |||
1512 | return; | 1503 | return; |
1513 | } | 1504 | } |
1514 | mac = addr; | 1505 | mac = addr; |
1515 | GNUNET_asprintf (&ret, | 1506 | ret = GNUNET_strdup (mac_to_string (mac)); |
1516 | "%s MAC address %s", | ||
1517 | PROTOCOL_PREFIX, | ||
1518 | mac_to_string (mac)); | ||
1519 | asc (asc_cls, ret); | 1507 | asc (asc_cls, ret); |
1520 | GNUNET_free (ret); | 1508 | GNUNET_free (ret); |
1521 | asc (asc_cls, NULL); | 1509 | asc (asc_cls, NULL); |
@@ -1579,6 +1567,57 @@ libgnunet_plugin_transport_wlan_done (void *cls) | |||
1579 | 1567 | ||
1580 | 1568 | ||
1581 | /** | 1569 | /** |
1570 | * Function called to convert a string address to | ||
1571 | * a binary address. | ||
1572 | * | ||
1573 | * @param cls closure ('struct Plugin*') | ||
1574 | * @param addr string address | ||
1575 | * @param addrlen length of the address | ||
1576 | * @param buf location to store the buffer | ||
1577 | * @param added location to store the number of bytes in the buffer. | ||
1578 | * If the function returns GNUNET_SYSERR, its contents are undefined. | ||
1579 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
1580 | */ | ||
1581 | static int | ||
1582 | wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen, | ||
1583 | void **buf, size_t *added) | ||
1584 | { | ||
1585 | struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; | ||
1586 | unsigned int a[6]; | ||
1587 | unsigned int i; | ||
1588 | |||
1589 | if ((NULL == addr) || (addrlen == 0)) | ||
1590 | { | ||
1591 | GNUNET_break (0); | ||
1592 | return GNUNET_SYSERR; | ||
1593 | } | ||
1594 | if ('\0' != addr[addrlen - 1]) | ||
1595 | { | ||
1596 | GNUNET_break (0); | ||
1597 | return GNUNET_SYSERR; | ||
1598 | } | ||
1599 | if (strlen (addr) != addrlen - 1) | ||
1600 | { | ||
1601 | GNUNET_break (0); | ||
1602 | return GNUNET_SYSERR; | ||
1603 | } | ||
1604 | if (6 != SSCANF (addr, | ||
1605 | "%X:%X:%X:%X:%X:%X", | ||
1606 | &a[0], &a[1], &a[2], &a[3], &a[4], &a[5])) | ||
1607 | { | ||
1608 | GNUNET_break (0); | ||
1609 | return GNUNET_SYSERR; | ||
1610 | } | ||
1611 | mac = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); | ||
1612 | for (i=0;i<6;i++) | ||
1613 | mac->mac[i] = a[i]; | ||
1614 | *buf = mac; | ||
1615 | *added = sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress); | ||
1616 | return GNUNET_OK; | ||
1617 | } | ||
1618 | |||
1619 | |||
1620 | /** | ||
1582 | * Entry point for the plugin. | 1621 | * Entry point for the plugin. |
1583 | * | 1622 | * |
1584 | * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*' | 1623 | * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*' |
@@ -1602,7 +1641,7 @@ libgnunet_plugin_transport_wlan_init (void *cls) | |||
1602 | api->cls = NULL; | 1641 | api->cls = NULL; |
1603 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | 1642 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; |
1604 | api->address_to_string = &wlan_plugin_address_to_string; | 1643 | api->address_to_string = &wlan_plugin_address_to_string; |
1605 | api->string_to_address = NULL; // FIXME! | 1644 | api->string_to_address = &wlan_string_to_address; |
1606 | return api; | 1645 | return api; |
1607 | } | 1646 | } |
1608 | 1647 | ||
@@ -1697,6 +1736,7 @@ libgnunet_plugin_transport_wlan_init (void *cls) | |||
1697 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | 1736 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; |
1698 | api->check_address = &wlan_plugin_address_suggested; | 1737 | api->check_address = &wlan_plugin_address_suggested; |
1699 | api->address_to_string = &wlan_plugin_address_to_string; | 1738 | api->address_to_string = &wlan_plugin_address_to_string; |
1739 | api->string_to_address = &wlan_string_to_address; | ||
1700 | return api; | 1740 | return api; |
1701 | } | 1741 | } |
1702 | 1742 | ||