From a337cef0be4a75ff0f4d88264d242444240fcc66 Mon Sep 17 00:00:00 2001 From: Saverio Proto Date: Thu, 10 Apr 2014 12:03:52 +0200 Subject: [PATCH] Get rid of tincremotehost structure, we use directly node_t --- meshlink-sample/meshlinkapp.c | 6 +++--- src/libmeshlink.c | 22 +++++++++++++++++++--- src/libmeshlink.h | 8 +------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/meshlink-sample/meshlinkapp.c b/meshlink-sample/meshlinkapp.c index 0ec564e3..647e6b77 100644 --- a/meshlink-sample/meshlinkapp.c +++ b/meshlink-sample/meshlinkapp.c @@ -5,12 +5,12 @@ int main(int argc , char **argv){ char *confbase = "/tmp/meshlink/"; char *name = "test"; -tincremotehost* remotenode = malloc(sizeof(tincremotehost)); +node_t* remotenode = new_node(); char *remotename = "nameofremotenode"; -//TODO: change this, calling a function that returns tincremotehost +//TODO: change this, calling a function that returns node_t +remotenode->name = malloc(16); remotenode->name = remotename; -remotenode->publickey = NULL; tinc_setup(confbase, name); tinc_start(confbase); diff --git a/src/libmeshlink.c b/src/libmeshlink.c index 80f18a22..f84642df 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -549,12 +549,24 @@ end: bool tinc_stop(); // can be called from any thread -bool tinc_send_packet(tincremotehost *receiver, const char* buf, unsigned int len) { +bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) { vpn_packet_t packet; + tincpackethdr* hdr = malloc(sizeof(tincpackethdr)); + + if (sizeof(hdr) + len > MAXSIZE) { + + //log something + return false; + } + + memcpy(hdr->destination,receiver->name,sizeof(hdr->destination)); + memcpy(hdr->source,myself->name,sizeof(hdr->source)); packet.priority = 0; - memcpy(packet.data,buf,len); + + memcpy(packet.data,hdr,sizeof(hdr)); + memcpy(packet.data+sizeof(hdr),buf,len); myself->in_packets++; myself->in_bytes += packet.len; @@ -570,7 +582,11 @@ bool tinc_set_packet_receive_handler(void (*handler)(const char* sender, const c //It might also be a good idea to add the option of looking up hosts by public //key (fingerprints) instead of names. -node_t *tinc_get_host(const char *name); +node_t *tinc_get_host(const char *name) { + + + +}; bool tinc_get_hosts(node_t** hosts); diff --git a/src/libmeshlink.h b/src/libmeshlink.h index ab7cdded..e99f8957 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -46,14 +46,8 @@ typedef struct tincpackethdr { u_int8_t source[16]; } __attribute__ ((__packed__)) tincpackethdr; -typedef struct tincremotehost { - char *name; - char *publickey; - -} tincremotehost; - // can be called from any thread -bool tinc_send_packet(tincremotehost *receiver, const char* buf, unsigned int len); +bool tinc_send_packet(node_t *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)); -- 2.39.5