Updated README
This commit is contained in:
15
Makefile
15
Makefile
@@ -328,14 +328,12 @@ static_lib: picotcp picotcp_driver libzt_socket_layer utilities $(ZTO_OBJS)
|
|||||||
mv ext/picotcp/build/lib/*.o obj
|
mv ext/picotcp/build/lib/*.o obj
|
||||||
mv ext/picotcp/build/modules/*.o obj
|
mv ext/picotcp/build/modules/*.o obj
|
||||||
$(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o
|
$(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
endif
|
endif
|
||||||
ifeq ($(STACK_LWIP),1)
|
ifeq ($(STACK_LWIP),1)
|
||||||
static_lib: lwip lwip_driver libzt_socket_layer utilities $(ZTO_OBJS)
|
static_lib: lwip lwip_driver libzt_socket_layer utilities $(ZTO_OBJS)
|
||||||
@mkdir -p $(BUILD) obj
|
@mkdir -p $(BUILD) obj
|
||||||
mv *.o obj
|
mv *.o obj
|
||||||
$(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o
|
$(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
endif
|
endif
|
||||||
# for layer-2 only (this will omit all userspace network stack code)
|
# for layer-2 only (this will omit all userspace network stack code)
|
||||||
ifeq ($(NO_STACK),1)
|
ifeq ($(NO_STACK),1)
|
||||||
@@ -343,7 +341,6 @@ static_lib: libzt_socket_layer utilities $(ZTO_OBJS)
|
|||||||
@mkdir -p $(BUILD) obj
|
@mkdir -p $(BUILD) obj
|
||||||
mv *.o obj
|
mv *.o obj
|
||||||
$(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o
|
$(ARTOOL) $(ARFLAGS) -o $(STATIC_LIB) obj/*.o
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
@@ -379,28 +376,24 @@ tests: selftest nativetest ztproxy
|
|||||||
|
|
||||||
ZT_UTILS:=zto/node/Utils.cpp -Izto/node
|
ZT_UTILS:=zto/node/Utils.cpp -Izto/node
|
||||||
|
|
||||||
|
sample:
|
||||||
|
$(CXX) $(CXXFLAGS) -D__SELFTEST__ $(STACK_DRIVER_DEFS) $(LIBZT_DEFS) \
|
||||||
|
$(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) $(ZT_UTILS) test/sample.cpp -o \
|
||||||
|
$(BUILD)/sample -L$(BUILD) -lzt
|
||||||
selftest:
|
selftest:
|
||||||
$(CXX) $(CXXFLAGS) -D__SELFTEST__ $(STACK_DRIVER_DEFS) $(LIBZT_DEFS) \
|
$(CXX) $(CXXFLAGS) -D__SELFTEST__ $(STACK_DRIVER_DEFS) $(LIBZT_DEFS) \
|
||||||
$(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) $(ZT_UTILS) test/selftest.cpp -o \
|
$(SANFLAGS) $(LIBZT_INCLUDES) $(ZT_INCLUDES) $(ZT_UTILS) test/selftest.cpp -o \
|
||||||
$(BUILD)/selftest -L$(BUILD) -lzt -lpthread
|
$(BUILD)/selftest -L$(BUILD) -lzt -lpthread
|
||||||
@./check.sh $(BUILD)/selftest
|
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
nativetest:
|
nativetest:
|
||||||
$(CXX) $(CXXFLAGS) -D__NATIVETEST__ $(STACK_DRIVER_DEFS) $(SANFLAGS) \
|
$(CXX) $(CXXFLAGS) -D__NATIVETEST__ $(STACK_DRIVER_DEFS) $(SANFLAGS) \
|
||||||
$(LIBZT_INCLUDES) $(ZT_INCLUDES) test/selftest.cpp -o $(BUILD)/nativetest
|
$(LIBZT_INCLUDES) $(ZT_INCLUDES) test/selftest.cpp -o $(BUILD)/nativetest
|
||||||
@./check.sh $(BUILD)/nativetest
|
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
ztproxy:
|
ztproxy:
|
||||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) $(ZT_INCLUDES) \
|
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(LIBZT_INCLUDES) $(LIBZT_DEFS) $(ZT_INCLUDES) \
|
||||||
examples/apps/ztproxy/ztproxy.cpp -o $(BUILD)/ztproxy $< -L$(BUILD) -lzt -lpthread $(WINDEFS)
|
examples/apps/ztproxy/ztproxy.cpp -o $(BUILD)/ztproxy $< -L$(BUILD) -lzt -lpthread $(WINDEFS)
|
||||||
@./check.sh $(BUILD)/ztproxy
|
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
intercept:
|
intercept:
|
||||||
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(STACK_DRIVER_DEFS) $(LIBZT_INCLUDES) \
|
$(CXX) $(CXXFLAGS) $(SANFLAGS) $(STACK_DRIVER_DEFS) $(LIBZT_INCLUDES) \
|
||||||
$(ZT_INCLUDES) examples/intercept/intercept.cpp -D_GNU_SOURCE \
|
$(ZT_INCLUDES) examples/intercept/intercept.cpp -D_GNU_SOURCE \
|
||||||
-shared -o $(BUILD)/intercept.so $< -ldl
|
-shared -o $(BUILD)/intercept.so $< -ldl
|
||||||
@./check.sh $(BUILD)/intercept.so
|
|
||||||
@date +"Build script finished on %F %T"
|
|
||||||
dlltest:
|
dlltest:
|
||||||
$(CXX) $(CXXFLAGS)
|
$(CXX) $(CXXFLAGS)
|
||||||
|
|
||||||
|
|||||||
63
README.md
63
README.md
@@ -14,46 +14,49 @@ Pre-Built Binaries Here: [zerotier.com/download.shtml](https://zerotier.com/down
|
|||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
### Example
|
### C++ Example
|
||||||
|
|
||||||
```
|
```
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#include "libzt.h"
|
#include "libzt.h"
|
||||||
|
|
||||||
char *str = "welcome to the machine";
|
int main()
|
||||||
char *nwid = "c7cd7c9e1b0f52a2"; // network to join
|
{
|
||||||
char *path = "zt1"; // path where this node's keys and configs will be stored
|
char *str = "welcome to the machine";
|
||||||
char *ip = "10.8.8.42"; // remote address
|
char *nwid = "c7cd7c981b0f52a2"; // network
|
||||||
int port = 8080; // remote port
|
char *path = "config_path"; // where this instance's keys and configs are stored
|
||||||
|
char *ip = "10.8.8.42"; // remote address
|
||||||
|
int port = 8080; // remote port
|
||||||
|
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = inet_addr(ip);
|
addr.sin_addr.s_addr = inet_addr(ip);
|
||||||
addr.sin_port = hton(port);
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
zts_startjoin(path, nwid);
|
zts_startjoin(path, nwid);
|
||||||
|
|
||||||
int fd, err = 0;
|
int fd, err = 0;
|
||||||
if ((fd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((fd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
printf("error creating socket\n");
|
printf("error creating socket\n");
|
||||||
return -1;
|
}
|
||||||
|
if ((err = zts_connect(fd, (const struct sockaddr *)&addr, sizeof(addr))) < 0) {
|
||||||
|
printf("error connecting to remote host\n");
|
||||||
|
}
|
||||||
|
if ((err = zts_write(fd, str, strlen(str))) < 0) {
|
||||||
|
printf("error writing to socket\n");
|
||||||
|
}
|
||||||
|
if ((err = zts_close(fd)) < 0) {
|
||||||
|
printf("error closing socket\n");
|
||||||
|
}
|
||||||
|
zts_stop();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if ((err = zts_connect(fd, (const struct sockaddr *)addr, sizeof(addr))) < 0) {
|
|
||||||
printf("error connecting to remote host\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if ((err = zts_write(fd, str, strlen(str))) < 0) {
|
|
||||||
printf("error writing to socket\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if ((err = zts_close(fd)) < 0) {
|
|
||||||
printf("error closing socket\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
zts_stop();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Bindings for various [languages](examples)
|
Other bindings for popular [languages](examples)
|
||||||
|
|
||||||
For an example using only the [Virtual Layer 2](https://www.zerotier.com/manual.shtml#2_2?pk_campaign=github_libzt), see [test/layer2.cpp](test/layer2.cpp)
|
For an example using only the [Virtual Layer 2](https://www.zerotier.com/manual.shtml#2_2?pk_campaign=github_libzt), see [test/layer2.cpp](test/layer2.cpp)
|
||||||
|
|
||||||
|
|||||||
37
test/sample.cpp
Normal file
37
test/sample.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include "libzt.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char *str = "welcome to the machine";
|
||||||
|
char *nwid = "c7cd7c9e1b0f52a2"; // network
|
||||||
|
char *path = "config_path"; // where this instance's keys and configs are stored
|
||||||
|
char *ip = "10.8.8.42"; // remote address
|
||||||
|
int port = 8080; // remote port
|
||||||
|
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = inet_addr(ip);
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
|
zts_startjoin(path, nwid);
|
||||||
|
|
||||||
|
int fd, err = 0;
|
||||||
|
if ((fd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
|
printf("error creating socket\n");
|
||||||
|
}
|
||||||
|
if ((err = zts_connect(fd, (const struct sockaddr *)&addr, sizeof(addr))) < 0) {
|
||||||
|
printf("error connecting to remote host\n");
|
||||||
|
}
|
||||||
|
if ((err = zts_write(fd, str, strlen(str))) < 0) {
|
||||||
|
printf("error writing to socket\n");
|
||||||
|
}
|
||||||
|
if ((err = zts_close(fd)) < 0) {
|
||||||
|
printf("error closing socket\n");
|
||||||
|
}
|
||||||
|
zts_stop();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user