From: Saverio Proto Date: Sun, 13 Apr 2014 21:53:54 +0000 (+0200) Subject: Initial callback support for data received from the VPN to the Application X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=6d4bb373f73f7fc76e1b8c030438a8e039e85366;p=meshlink Initial callback support for data received from the VPN to the Application --- diff --git a/meshlink-sample/meshlinkapp.c b/meshlink-sample/meshlinkapp.c index ff9bad1e..25949b16 100644 --- a/meshlink-sample/meshlinkapp.c +++ b/meshlink-sample/meshlinkapp.c @@ -1,5 +1,12 @@ #include + +void handle_recv_data(void *data); +void handle_recv_data(void *data) { +printf("do nothing for now\n"); + +} + int main(int argc , char **argv){ char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/"; @@ -15,6 +22,10 @@ remotenode->name = remotename; tinc_setup(confbase, name); tinc_start(confbase); + +//Register callback function for incoming data +recvdata_register_cb(handle_recv_data); + sleep(2); //there is a race condition here, tinc_start detaches to a thread the needs time to setup stuff while(1) { diff --git a/src/libmeshlink.c b/src/libmeshlink.c index fd7426ca..e900dd11 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -31,6 +31,7 @@ #include "protocol.h" char *hosts_dir = NULL; +recvdata_cb_t recv_callback; static char *name = NULL; char *tinc_conf = NULL; static bool tty = false; @@ -363,7 +364,6 @@ __attribute__((destructor)) static void meshlink_exit(void) { void *tinc_main_thread(void * in) { static bool status = false; - /* If nonzero, write log entries to a separate file. */ bool use_logfile = false; @@ -491,6 +491,8 @@ automatically distributed blacklist or whitelist would be the next step. */ bool tinc_blacklist(node_t *host); - +void recvdata_register_cb(recvdata_cb_t cb) { +recv_callback = cb; +}; diff --git a/src/libmeshlink.h b/src/libmeshlink.h index e70f89f0..0cbfec7e 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -24,6 +24,11 @@ #include "logger.h" #include "route.h" +typedef void (*recvdata_cb_t)(void *data); +void recvdata_register_cb(recvdata_cb_t cb); + +extern recvdata_cb_t recv_callback; + extern char *hosts_dir; extern FILE *fopenmask(const char *filename, const char *mode, mode_t perms); diff --git a/src/route.c b/src/route.c index f09a1041..539796df 100644 --- a/src/route.c +++ b/src/route.c @@ -74,6 +74,7 @@ void route(node_t *source,vpn_packet_t *packet) { if (owner == myself ) { //TODO: implement sending received data from meshlink library to the application logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + 46); + (recv_callback)(NULL); return; }