From c53b009f21e97379cad24c811c8033e647cb2bb9 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Wed, 9 Apr 2014 19:55:23 +0200 Subject: [PATCH] Push data from the application to the library and print to screen this data in route() function --- meshlink-sample/meshlinkapp.c | 1 + src/libmeshlink.c | 14 +++++++++++++- src/libmeshlink.h | 18 +++++++++++++++++- src/route.c | 6 ++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/meshlink-sample/meshlinkapp.c b/meshlink-sample/meshlinkapp.c index d5f489e9..7dd7f501 100644 --- a/meshlink-sample/meshlinkapp.c +++ b/meshlink-sample/meshlinkapp.c @@ -9,6 +9,7 @@ tinc_setup(confbase, name); tinc_start(confbase); while(1) { sleep(10); //give time to this thread to finish before we exit +tinc_send_packet(NULL,"datafgsdfsd",10); } return 0; } diff --git a/src/libmeshlink.c b/src/libmeshlink.c index f4932cc3..80f18a22 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -549,7 +549,19 @@ end: bool tinc_stop(); // can be called from any thread -bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len); +bool tinc_send_packet(tincremotehost *receiver, const char* buf, unsigned int len) { + + vpn_packet_t packet; + + packet.priority = 0; + memcpy(packet.data,buf,len); + + myself->in_packets++; + myself->in_bytes += packet.len; + route(myself, &packet); + +return true; +} // handler runs in tinc thread and should return immediately bool tinc_set_packet_receive_handler(void (*handler)(const char* sender, const char* buf, unsigned int len)); diff --git a/src/libmeshlink.h b/src/libmeshlink.h index 2541b5f2..df1fc8d7 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -23,6 +23,7 @@ //#include "tincctl.h" #include "xalloc.h" #include "logger.h" +#include "route.h" extern char *hosts_dir; extern FILE *fopenmask(const char *filename, const char *mode, mode_t perms); @@ -40,8 +41,23 @@ bool tinc_start(const char* path); bool tinc_stop(); +typedef struct tincpackethdr { + /* Use a standard Type-Length-Value (TLV) element */ + u_int8_t type; + u_int8_t len; + u_int16_t reserved; /* Always 0 */ + u_int32_t destination; + u_int32_t source; +} __attribute__ ((__packed__)) tincpackethdr; + +typedef struct tincremotehost { + char *name; + char *publickey; + +} tincremotehost; + // can be called from any thread -bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len); +bool tinc_send_packet(tincremotehost *receiver, const char* buf, unsigned int len); // handler runs in tinc thread and should return immediately bool tinc_set_packet_receive_handler(void (*handler)(const char* sender, const char* buf, unsigned int len)); diff --git a/src/route.c b/src/route.c index 00ba4c05..83b90293 100644 --- a/src/route.c +++ b/src/route.c @@ -946,6 +946,12 @@ static bool do_decrement_ttl(node_t *source, vpn_packet_t *packet) { } void route(node_t *source, vpn_packet_t *packet) { + + if (/*libmeshlink*/ 1) { + printf("%s\n",packet->data); + return; + } + if(pcap) send_pcap(packet); -- 2.39.5