]> git.meshlink.io Git - meshlink/blob - examples/meshlinkapp.c
Renamed meshlink-sample/ to examples/.
[meshlink] / examples / meshlinkapp.c
1 #include <libmeshlink.h>
2
3
4 void handle_recv_data(void *data);
5 void handle_recv_data(void *data) {
6 printf("Data received is %s\n",data);
7
8 }
9
10 int main(int argc , char **argv){
11
12 char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/";
13 char *name = argc > 2 ? argv[2] : "foo";
14 debug_level = 5;
15
16 node_t* remotenode = new_node();
17 char *remotename = argc > 3 ? argv[3] : "bar";
18
19 //TODO: change this, calling a function that returns node_t
20 remotenode->name = malloc(16);
21 remotenode->name = remotename;
22
23 tinc_setup(confbase, name);
24 tinc_start(confbase);
25
26 //Register callback function for incoming data
27 recvdata_register_cb(handle_recv_data);
28
29 sleep(2); //there is a race condition here, tinc_start detaches to a thread the needs time to setup stuff
30 while(1) {
31
32 //sample data to send out
33 char mydata[200];
34 memset(mydata,0,200);
35 strcpy(mydata,"Hello World!");
36
37 //send out data
38 tinc_send_packet(remotenode,mydata,sizeof(mydata));
39 sleep(10); //give time to this thread to finish before we exit
40 }
41 free(remotenode);
42 return 0;
43 }
44