From 9eeec649fb91784d26cbfcad876cff1d6b950408 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 25 Sep 2012 00:38:19 +0200 Subject: Send hello packets --- ffd/ffd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'ffd/ffd.c') diff --git a/ffd/ffd.c b/ffd/ffd.c index fcf41e3..27e5c29 100644 --- a/ffd/ffd.c +++ b/ffd/ffd.c @@ -27,6 +27,8 @@ #include "ffd.h" #include "netif.h" #include "packet.h" +#include "tlv.h" +#include "tlv_types.h" #include #include @@ -46,6 +48,7 @@ static const eth_addr_t ffd_addr = {{0x03, 0x00, 0x00, 0x00, 0x0f, 0xfd}}; #define HELLO_INTERVAL 10 +#define PACKET_MAX 1000 static char *mesh = "bat0"; @@ -161,19 +164,28 @@ static void send_hello(const char *ifname, unsigned ifindex, void *arg) { ffd_packet_t *packet = arg; - if (!send_eth(&ffd_addr, ifindex, packet, sizeof(ffd_packet_t)+packet->len)) + if (!send_eth(&ffd_addr, ifindex, packet, sizeof(ffd_packet_t)+ntohs(packet->len))) fprintf(stderr, "send_eth: %m\n"); } static void send_hellos() { /*if (!orig_data) return;*/ + static uint16_t seqno = 0; - ffd_packet_t *packet = alloca(sizeof(ffd_packet_t)+1000); + ffd_packet_t *packet = alloca(sizeof(ffd_packet_t)+PACKET_MAX); packet->version_magic = htons(FFD_VERSION_MAGIC); packet->len = 0; + ffd_tlv_hello_t *hello = ffd_tlv_add(packet, PACKET_MAX, TLV_HELLO, sizeof(ffd_tlv_hello_t)); + if (!hello) + return; + + memset(hello, 0, sizeof(ffd_tlv_hello_t)); + hello->seqno = htons(seqno++); + hello->interval = htons(HELLO_INTERVAL*100); + netif_foreach(send_hello, packet); } -- cgit v1.2.3