From: Guus Sliepen Date: Sat, 19 Apr 2014 11:49:31 +0000 (+0200) Subject: Renamed meshlink-sample/ to examples/. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=781eec3832e2e4eca97e3deff55e451c57418fb1;p=meshlink Renamed meshlink-sample/ to examples/. --- diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 00000000..24600083 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1 @@ +!Makefile diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 00000000..6c69ac8f --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,18 @@ +# Simple Makefile + +CC=gcc +LIBS= -L../src/.libs/ -lmeshlink -lcrypto -lz -ldl -lpthread -static +INCLUDE= -I../src/ +LOADLIBES= $(LIBS) +OBJS= meshlinkapp.o +CFLAGS= -g -D_PC_ $(INCLUDE) -Wall +EXEC=meshlinkapp +default: all +all: $(OBJS) $(EXEC) +$(EXEC): $(OBJS) +clean: + -rm -f $(OBJS) + -rm -f $(EXEC) + + +rebuild: clean all diff --git a/examples/fixlib.txt b/examples/fixlib.txt new file mode 100644 index 00000000..e230dcd1 --- /dev/null +++ b/examples/fixlib.txt @@ -0,0 +1,3 @@ +MYPATH=`pwd` +echo $MYPATH +export LD_LIBRARY_PATH=$MYPATH'/../src/.libs/' diff --git a/examples/meshlinkapp.c b/examples/meshlinkapp.c new file mode 100644 index 00000000..aa9b30c5 --- /dev/null +++ b/examples/meshlinkapp.c @@ -0,0 +1,44 @@ +#include + + +void handle_recv_data(void *data); +void handle_recv_data(void *data) { +printf("Data received is %s\n",data); + +} + +int main(int argc , char **argv){ + +char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/"; +char *name = argc > 2 ? argv[2] : "foo"; +debug_level = 5; + +node_t* remotenode = new_node(); +char *remotename = argc > 3 ? argv[3] : "bar"; + +//TODO: change this, calling a function that returns node_t +remotenode->name = malloc(16); +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) { + +//sample data to send out +char mydata[200]; +memset(mydata,0,200); +strcpy(mydata,"Hello World!"); + +//send out data +tinc_send_packet(remotenode,mydata,sizeof(mydata)); +sleep(10); //give time to this thread to finish before we exit +} +free(remotenode); +return 0; +} + diff --git a/meshlink-sample/.gitignore b/meshlink-sample/.gitignore deleted file mode 100644 index 24600083..00000000 --- a/meshlink-sample/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!Makefile diff --git a/meshlink-sample/Makefile b/meshlink-sample/Makefile deleted file mode 100644 index 6c69ac8f..00000000 --- a/meshlink-sample/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Simple Makefile - -CC=gcc -LIBS= -L../src/.libs/ -lmeshlink -lcrypto -lz -ldl -lpthread -static -INCLUDE= -I../src/ -LOADLIBES= $(LIBS) -OBJS= meshlinkapp.o -CFLAGS= -g -D_PC_ $(INCLUDE) -Wall -EXEC=meshlinkapp -default: all -all: $(OBJS) $(EXEC) -$(EXEC): $(OBJS) -clean: - -rm -f $(OBJS) - -rm -f $(EXEC) - - -rebuild: clean all diff --git a/meshlink-sample/fixlib.txt b/meshlink-sample/fixlib.txt deleted file mode 100644 index e230dcd1..00000000 --- a/meshlink-sample/fixlib.txt +++ /dev/null @@ -1,3 +0,0 @@ -MYPATH=`pwd` -echo $MYPATH -export LD_LIBRARY_PATH=$MYPATH'/../src/.libs/' diff --git a/meshlink-sample/meshlinkapp.c b/meshlink-sample/meshlinkapp.c deleted file mode 100644 index aa9b30c5..00000000 --- a/meshlink-sample/meshlinkapp.c +++ /dev/null @@ -1,44 +0,0 @@ -#include - - -void handle_recv_data(void *data); -void handle_recv_data(void *data) { -printf("Data received is %s\n",data); - -} - -int main(int argc , char **argv){ - -char *confbase = argc > 1 ? argv[1] : "/tmp/meshlink/"; -char *name = argc > 2 ? argv[2] : "foo"; -debug_level = 5; - -node_t* remotenode = new_node(); -char *remotename = argc > 3 ? argv[3] : "bar"; - -//TODO: change this, calling a function that returns node_t -remotenode->name = malloc(16); -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) { - -//sample data to send out -char mydata[200]; -memset(mydata,0,200); -strcpy(mydata,"Hello World!"); - -//send out data -tinc_send_packet(remotenode,mydata,sizeof(mydata)); -sleep(10); //give time to this thread to finish before we exit -} -free(remotenode); -return 0; -} -