]> git.meshlink.io Git - meshlink/blobdiff - src/libmeshlink.c
Use snprintf() instead of xasprintf() when generating filenames
[meshlink] / src / libmeshlink.c
index fd7426cace616e9e48e2e2a377689ad7d81169ef..cd9e8a745f496ecdbe3e38a19aec652e364acfdc 100644 (file)
@@ -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;
+};