X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Flibmeshlink.c;h=cd9e8a745f496ecdbe3e38a19aec652e364acfdc;hb=8fb3cf697d16e4870d7305866d03240acd49b386;hp=fd7426cace616e9e48e2e2a377689ad7d81169ef;hpb=9097c5bb92396e2471e99f0e61a75756a1e9200b;p=meshlink diff --git a/src/libmeshlink.c b/src/libmeshlink.c index fd7426ca..cd9e8a74 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; @@ -411,26 +411,24 @@ bool tinc_stop(); bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) { vpn_packet_t packet; - tincpackethdr* hdr = malloc(sizeof(tincpackethdr)); + tincpackethdr* hdr = (tincpackethdr *)packet.data; if (sizeof(tincpackethdr) + len > MAXSIZE) { //log something return false; } - memset(hdr->legacymtu,1,sizeof(hdr->legacymtu)); + packet.probe = false; + memset(hdr, 0, sizeof *hdr); memcpy(hdr->destination,receiver->name,sizeof(hdr->destination)); - memcpy(hdr->source,myself->name,sizeof(hdr->source)); + memcpy(hdr->source,mesh->self->name,sizeof(hdr->source)); - packet.priority = 0; packet.len = sizeof(tincpackethdr) + len; - - memcpy(packet.data,hdr,sizeof(tincpackethdr)); memcpy(packet.data+sizeof(tincpackethdr),buf,len); - myself->in_packets++; - myself->in_bytes += packet.len; - route(myself, &packet); + mesh->self->in_packets++; + mesh->self->in_bytes += packet.len; + route(mesh->self, &packet); return true; } @@ -491,6 +489,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; +};