diff --git a/examples/cpp/earthtest.cpp b/examples/cpp/earthtest.cpp
deleted file mode 100644
index df51df9..0000000
--- a/examples/cpp/earthtest.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-
-#include "libzt.h"
-
-int main(int argc, char **argv)
-{
- uint64_t nwid = 0x8056c2e21c000001;
- zts_startjoin(".", nwid);
- fprintf(stderr, "%llx", (unsigned long long)zts_get_node_id());
- zts_leave(nwid);
- zts_stop();
- return 0;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv4simple/ipv4client.cpp b/examples/cpp/ipv4simple/ipv4client.cpp
deleted file mode 100644
index 9d0100b..0000000
--- a/examples/cpp/ipv4simple/ipv4client.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "libzt.h"
-
-char *msg = (char*)"welcome to the machine";
-
-int main(int argc, char **argv)
-{
- if (argc != 5) {
- printf("\nlibzt example client\n");
- printf("client [config_file_path] [nwid] [remote_addr] [remote_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- std::string remote_addr = argv[3];
- int remote_port = atoi(argv[4]);
- int r=0, w=0, err=0, sockfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in in4;
- in4.sin_port = htons(remote_port);
- in4.sin_addr.s_addr = inet_addr(remote_addr.c_str());
- in4.sin_family = AF_INET;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_connect(sockfd, (const struct sockaddr *)&in4, sizeof(in4))) < 0) {
- printf("error connecting to remote host (%d)\n", err);
- }
-
- printf("sending to server...\n");
- w = zts_write(sockfd, msg, strlen(msg));
-
- printf("reading from server...\n");
- r = zts_read(sockfd, rbuf, strlen(msg));
-
- printf("Sent : %s\n", msg);
- printf("Received : %s\n", rbuf);
-
- err = zts_close(sockfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv4simple/ipv4client_udp.cpp b/examples/cpp/ipv4simple/ipv4client_udp.cpp
deleted file mode 100644
index 273c797..0000000
--- a/examples/cpp/ipv4simple/ipv4client_udp.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "libzt.h"
-
-char *msg = (char*)"welcome to the machine";
-
-int main(int argc, char **argv)
-{
- if (argc != 5) {
- printf("\nlibzt example client\n");
- printf("client [config_file_path] [nwid] [remote_addr] [remote_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- std::string remote_addr = argv[3];
- int remote_port = atoi(argv[4]);
- int r=0, w=0, err=0, sockfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in in4;
- in4.sin_port = htons(remote_port);
- in4.sin_addr.s_addr = INADDR_ANY;
- in4.sin_family = AF_INET;
-
- struct sockaddr_in remote4;
- remote4.sin_port = htons(remote_port);
- remote4.sin_addr.s_addr = inet_addr(remote_addr.c_str());
- remote4.sin_family = AF_INET;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
- printf("error binding to interface (%d)\n", err);
- }
- int flags = 0;
- int len = strlen(msg);
-
- while(true) {
- sleep(1);
- if ((err = zts_sendto(sockfd, msg, len, flags, (const struct sockaddr *)&remote4, sizeof(remote4))) < 0) {
- printf("error sending message to remote host (%d)\n", err);
- }
- printf("sent=%d\n", err);
- }
- /*
- printf("reading from server...\n");
- r = zts_read(sockfd, rbuf, strlen(msg));
-
- printf("Sent : %s\n", msg);
- printf("Received : %s\n", rbuf);
- */
- err = zts_close(sockfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv4simple/ipv4server.cpp b/examples/cpp/ipv4simple/ipv4server.cpp
deleted file mode 100644
index 260e9e4..0000000
--- a/examples/cpp/ipv4simple/ipv4server.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-#include "libzt.h"
-
-int main(int argc, char **argv)
-{
- if (argc != 4) {
- printf("\nlibzt example server\n");
- printf("server [config_file_path] [nwid] [bind_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- int bind_port = atoi(argv[3]);
- int w=0, r=0, err=0, sockfd, accfd;
- char rbuf[1000];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in in4, acc_in4;
- in4.sin_port = htons(bind_port);
- in4.sin_addr.s_addr = INADDR_ANY;
- in4.sin_family = AF_INET;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
- printf("error binding to interface (%d)\n", err);
- }
-
- if ((err = zts_listen(sockfd, 100)) < 0) {
- printf("error placing socket in LISTENING state (%d)\n", err);
- }
-
- socklen_t client_addrlen = sizeof(sockaddr_in);
- if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in4, &client_addrlen)) < 0) {
- printf("error accepting connection (%d)\n", err);
- }
-
- socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
- zts_getpeername(accfd, (struct sockaddr*)&acc_in4, &peer_addrlen);
- printf("accepted connection from %s : %d\n", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
-
- int tot = 0;
- printf("reading from client...\n");
- while(true) {
- memset(rbuf, 0, sizeof rbuf);
- if (tot == 500000)
- {
- break;
- }
- r = zts_read(accfd, rbuf, sizeof rbuf);
- printf("r=%d\n", r);
- printf("Received : %s\n", rbuf);
- tot+= r;
- printf("tot=%d\n", tot);
- }
- printf("tot=%d\n", tot);
-
- printf("sending to client...\n");
- w = zts_write(accfd, rbuf, strlen(rbuf));
- printf("w=%d\n", r);
-
- printf("Received : %s\n", rbuf);
-
- err = zts_close(sockfd);
- err = zts_close(accfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv4simple/ipv4server_udp.cpp b/examples/cpp/ipv4simple/ipv4server_udp.cpp
deleted file mode 100644
index 1a7f5eb..0000000
--- a/examples/cpp/ipv4simple/ipv4server_udp.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-#include "libzt.h"
-
-int main(int argc, char **argv)
-{
- if (argc != 4) {
- printf("\nlibzt example server\n");
- printf("server [config_file_path] [nwid] [bind_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- int bind_port = atoi(argv[3]);
- int w=0, r=0, err=0, sockfd = 0, accfd = 0, flags = 0;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in in4, acc_in4;
- in4.sin_port = htons(bind_port);
- in4.sin_addr.s_addr = INADDR_ANY;
- in4.sin_family = AF_INET;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
- if ((err = zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
- printf("error binding to interface (%d)\n", err);
- }
-
-/*
- socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
- zts_getpeername(accfd, (struct sockaddr*)&acc_in4, &peer_addrlen);
- DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
-*/
-
- printf("reading from client...\n");
- socklen_t addrlen = sizeof(acc_in4);
- memset(&acc_in4, 0, sizeof acc_in4);
-
- while(true) {
- memset(&rbuf, 0, sizeof rbuf);
- r = zts_recvfrom(accfd, rbuf, sizeof(rbuf), flags, (struct sockaddr *)&acc_in4, &addrlen);
- if (r >= 0) {
- char *ip = inet_ntoa(acc_in4.sin_addr);
- printf("Received : r=%d, %s -- from: %s : %d\n", r, rbuf, ip, ntohs(acc_in4.sin_port));
- }
- }
-
-/*
- printf("sending to client...\n");
- w = zts_write(accfd, rbuf, strlen(rbuf));
-
-*/
-
- err = zts_close(sockfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv6adhoc/ipv6adhocclient.cpp b/examples/cpp/ipv6adhoc/ipv6adhocclient.cpp
deleted file mode 100644
index ab1ee0e..0000000
--- a/examples/cpp/ipv6adhoc/ipv6adhocclient.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "libzt.h"
-
-char *msg = (char*)"welcome to the machine";
-
-uint64_t generate_adhoc_nwid_from_port(int port)
-{
- std::string padding;
- if(port < 10) {
- padding = "000";
- } else if(port < 100) {
- padding = "00";
- } else if(port < 1000) {
- padding = "0";
- }
- // We will join ad-hoc network ffSSSSEEEE000000
- // Where SSSS = start port
- // EEEE = end port
- padding = padding + std::to_string(port); // SSSS
- std::string nwidstr = "ff" + padding + padding + "000000"; // ff + SSSS + EEEE + 000000
- return strtoull(nwidstr.c_str(), NULL, 16);
-}
-
-int main(int argc, char **argv)
-{
- if (argc != 5) {
- printf("\nlibzt example client\n");
- printf("client [config_file_path] [nwid] [remote_addr] [remote_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- std::string remote_addr = argv[3];
- int remote_port = atoi(argv[4]);
- int r=0, w=0, err=0, sockfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in6 in6;
- in6.sin6_port = htons(remote_port);
- inet_pton(AF_INET6, remote_addr.c_str(), &(in6.sin6_addr));
- in6.sin6_family = AF_INET6;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = generate_adhoc_nwid_from_port(remote_port);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_connect(sockfd, (const struct sockaddr *)&in6, sizeof(in6))) < 0) {
- printf("error connecting to remote host (%d)\n", err);
- }
-
- printf("sending to server...\n");
- w = zts_write(sockfd, msg, strlen(msg));
-
- printf("reading from server...\n");
- r = zts_read(sockfd, rbuf, strlen(msg));
-
- printf("Sent : %s\n", msg);
- printf("Received : %s\n", rbuf);
-
- err = zts_close(sockfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv6adhoc/ipv6adhocserver.cpp b/examples/cpp/ipv6adhoc/ipv6adhocserver.cpp
deleted file mode 100644
index 512a568..0000000
--- a/examples/cpp/ipv6adhoc/ipv6adhocserver.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "libzt.h"
-
-uint64_t generate_adhoc_nwid_from_port(int port)
-{
- std::string padding;
- if(port < 10) {
- padding = "000";
- } else if(port < 100) {
- padding = "00";
- } else if(port < 1000) {
- padding = "0";
- }
- // We will join ad-hoc network ffSSSSEEEE000000
- // Where SSSS = start port
- // EEEE = end port
- padding = padding + std::to_string(port); // SSSS
- std::string nwidstr = "ff" + padding + padding + "000000"; // ff + SSSS + EEEE + 000000
- return strtoull(nwidstr.c_str(), NULL, 16);
-}
-
-int main(int argc, char **argv)
-{
- if (argc != 4) {
- printf("\nlibzt example server\n");
- printf("server [config_file_path] [bind_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- int bind_port = atoi(argv[2]);
- uint64_t nwid = generate_adhoc_nwid_from_port(bind_port);
- int w=0, r=0, err=0, sockfd, accfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in6 in6, acc_in6;
- in6.sin6_port = htons(bind_port);
- in6.sin6_family = AF_INET6;
- in6.sin6_addr = in6addr_any;
-
- fprintf(stderr, "nwid=%llx\n", (unsigned long long)nwid);
- exit(-1);
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- nwid = generate_adhoc_nwid_from_port(bind_port);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_bind(sockfd, (struct sockaddr *)&in6, sizeof(struct sockaddr_in6)) < 0)) {
- printf("error binding to interface (%d)\n", err);
- }
-
- if ((err = zts_listen(sockfd, 100)) < 0) {
- printf("error placing socket in LISTENING state (%d)\n", err);
- }
-
- socklen_t client_addrlen = sizeof(sockaddr_in6);
- if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in6, &client_addrlen)) < 0) {
- printf("error accepting connection (%d)\n", err);
- }
-
- socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
- zts_getpeername(accfd, (struct sockaddr*)&acc_in6, &peer_addrlen);
- //printf("accepted connection from %s : %d", inet_ntoa(acc_in6.sin6_addr), ntohs(acc_in6.sin6_port));
-
- printf("reading from client...\n");
- r = zts_read(accfd, rbuf, sizeof rbuf);
-
- printf("sending to client...\n");
- w = zts_write(accfd, rbuf, strlen(rbuf));
-
- printf("Received : %s\n", rbuf);
-
- err = zts_close(sockfd);
- err = zts_close(accfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv6simple/ipv6client.cpp b/examples/cpp/ipv6simple/ipv6client.cpp
deleted file mode 100644
index 3bf3099..0000000
--- a/examples/cpp/ipv6simple/ipv6client.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "libzt.h"
-
-char *msg = (char*)"welcome to the machine";
-
-int main(int argc, char **argv)
-{
- if (argc != 5) {
- printf("\nlibzt example client\n");
- printf("client [config_file_path] [nwid] [remote_addr] [remote_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- std::string remote_addr = argv[3];
- int remote_port = atoi(argv[4]);
- int r=0, w=0, err=0, sockfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in6 in6;
- in6.sin6_port = htons(remote_port);
- inet_pton(AF_INET6, remote_addr.c_str(), &(in6.sin6_addr));
- in6.sin6_family = AF_INET6;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_connect(sockfd, (const struct sockaddr *)&in6, sizeof(in6))) < 0) {
- printf("error connecting to remote host (%d)\n", err);
- }
-
- printf("sending to server...\n");
- w = zts_write(sockfd, msg, strlen(msg));
-
- printf("reading from server...\n");
- r = zts_read(sockfd, rbuf, strlen(msg));
-
- printf("Sent : %s\n", msg);
- printf("Received : %s\n", rbuf);
-
- err = zts_close(sockfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/ipv6simple/ipv6server.cpp b/examples/cpp/ipv6simple/ipv6server.cpp
deleted file mode 100644
index 7062d4f..0000000
--- a/examples/cpp/ipv6simple/ipv6server.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-
-#if defined(_WIN32)
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#include
-#endif
-
-#include "libzt.h"
-
-int main(int argc, char **argv)
-{
- if (argc != 4) {
- printf("\nlibzt example server\n");
- printf("server [config_file_path] [nwid] [bind_port]\n");
- exit(0);
- }
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- int bind_port = atoi(argv[3]);
- int w=0, r=0, err=0, sockfd, accfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in6 in6, acc_in6;
- in6.sin6_port = htons(bind_port);
- in6.sin6_family = AF_INET6;
- in6.sin6_addr = in6addr_any;
-
- // --- BEGIN EXAMPLE CODE
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = zts_bind(sockfd, (struct sockaddr *)&in6, sizeof(struct sockaddr_in6)) < 0)) {
- printf("error binding to interface (%d)\n", err);
- }
-
- if ((err = zts_listen(sockfd, 100)) < 0) {
- printf("error placing socket in LISTENING state (%d)\n", err);
- }
-
- socklen_t client_addrlen = sizeof(sockaddr_in6);
- if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in6, &client_addrlen)) < 0) {
- printf("error accepting connection (%d)\n", err);
- }
-
- socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
- zts_getpeername(accfd, (struct sockaddr*)&acc_in6, &peer_addrlen);
- //DEBUG_INFO("accepted connection from %s : %d", inet_ntoa(acc_in6.sin6_addr), ntohs(acc_in6.sin6_port));
-
- printf("reading from client...\n");
- r = zts_read(accfd, rbuf, sizeof rbuf);
-
- printf("sending to client...\n");
- w = zts_write(accfd, rbuf, strlen(rbuf));
-
- printf("Received : %s\n", rbuf);
-
- err = zts_close(sockfd);
- err = zts_close(accfd);
-
- return err;
-}
\ No newline at end of file
diff --git a/examples/cpp/sharedlib/ipv4client_shared.cpp b/examples/cpp/sharedlib/ipv4client_shared.cpp
deleted file mode 100644
index 83a0782..0000000
--- a/examples/cpp/sharedlib/ipv4client_shared.cpp
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#if !defined(_MSC_VER)
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "libzt.h"
-
-// function pointers which will have values assigned once the dynamic library is loaded
-
-int (*_zts_set_service_port)(int portno);
-int (*_zts_start)(const char *path, bool blocking);
-int (*_zts_startjoin)(const char*, uint64_t);
-void (*_zts_stop)(void);
-int (*_zts_core_running)(void);
-int (*_zts_stack_running)(void);
-int (*_zts_ready)(void);
-int (*_zts_join)(const uint64_t);
-int (*_zts_leave)(const uint64_t);
-void (*_zts_get_path)(char *homePath, const size_t len);
-uint64_t (*_zts_get_node_id)(void);
-int (*_zts_has_address)(const uint64_t);
-int (*_zts_get_num_assigned_addresses)(const uint64_t nwid);
-int (*_zts_get_address_at_index)(const uint64_t nwid, const int index, struct sockaddr_storage *addr);
-int (*_zts_get_address)(const uint64_t nwid, struct sockaddr_storage *addr, const int address_family);
-void (*_zts_get_6plane_addr)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId);
-void (*_zts_get_rfc4193_addr)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId);
-unsigned long (*_zts_get_peer_count)(void);
-int (*_zts_get_peer_address)(char *peer, const uint64_t nodeId);
-int (*_zts_socket)(int socket_family, int socket_type, int protocol);
-int (*_zts_connect)(int fd, const struct sockaddr *addr, socklen_t addrlen);
-int (*_zts_bind)(int fd, const struct sockaddr *addr, socklen_t addrlen);
-int (*_zts_listen)(int fd, int backlog);
-int (*_zts_accept)(int fd, struct sockaddr *addr, socklen_t *addrlen);
-#if defined(__linux__)
-int (*_zts_accept4)(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags);
-#endif
-int (*_zts_setsockopt)(int fd, int level, int optname, const void *optval, socklen_t optlen);
-int (*_zts_getsockopt)(int fd, int level, int optname, void *optval, socklen_t *optlen);
-int (*_zts_getsockname)(int fd, struct sockaddr *addr, socklen_t *addrlen);
-int (*_zts_getpeername)(int fd, struct sockaddr *addr, socklen_t *addrlen);
-int (*_zts_gethostname)(char *name, size_t len);
-int (*_zts_sethostname)(const char *name, size_t len);
-struct hostent *(*_zts_gethostbyname)(const char *name);
-int (*_zts_close)(int fd);
-int(*_zts_fcntl)(int fd, int cmd, int flags);
-int (*_zts_ioctl)(int fd, unsigned long request, void *argp);
-ssize_t (*_zts_send)(int fd, const void *buf, size_t len, int flags);
-ssize_t (*_zts_sendto)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen);
-ssize_t (*_zts_sendmsg)(int fd, const struct msghdr *msg, int flags);
-ssize_t (*_zts_recv)(int fd, void *buf, size_t len, int flags);
-ssize_t (*_zts_recvfrom)(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen);
-ssize_t (*_zts_recvmsg)(int fd, struct msghdr *msg,int flags);
-int (*_zts_read)(int fd, void *buf, size_t len);
-int (*_zts_write)(int fd, const void *buf, size_t len);
-int (*_zts_shutdown)(int fd, int how);
-int (*_zts_add_dns_nameserver)(struct sockaddr *addr);
-int (*_zts_del_dns_nameserver)(struct sockaddr *addr);
-
-
-void load_library_symbols(char *library_path)
-{
- void *libHandle = dlopen(library_path, RTLD_LAZY);
- if (libHandle == NULL) {
- DEBUG_ERROR("unable to load dynamic libs: %s", dlerror());
- exit(-1);
- }
-
- // Load symbols from library (call these directly)
-
- _zts_set_service_port = (int(*)(int portno))dlsym(libHandle, "zts_set_service_port");
- _zts_start = (int(*)(const char *path, bool blocking))dlsym(libHandle, "zts_start");
- _zts_startjoin = (int(*)(const char*, uint64_t))dlsym(libHandle, "zts_startjoin");
- _zts_stop = (void(*)(void))dlsym(libHandle, "zts_stop");
- _zts_core_running = (int(*)(void))dlsym(libHandle, "zts_core_running");
- _zts_stack_running = (int(*)(void))dlsym(libHandle, "zts_stack_running");
- _zts_ready = (int(*)(void))dlsym(libHandle, "zts_ready");
- _zts_join = (int(*)(const uint64_t))dlsym(libHandle, "zts_join");
- _zts_leave = (int(*)(const uint64_t))dlsym(libHandle, "zts_leave");
- _zts_get_path = (void(*)(char *homePath, const size_t len))dlsym(libHandle, "zts_get_path");
- _zts_get_node_id = (uint64_t(*)(void))dlsym(libHandle, "zts_get_node_id");
- _zts_has_address = (int(*)(const uint64_t))dlsym(libHandle, "zts_has_address");
- _zts_get_num_assigned_addresses = (int(*)(const uint64_t nwid))dlsym(libHandle, "zts_get_num_assigned_addresses");
- _zts_get_address_at_index = (int(*)(const uint64_t nwid, const int index, struct sockaddr_storage *addr))dlsym(libHandle, "zts_get_address_at_index");
- _zts_get_address = (int(*)(const uint64_t nwid, struct sockaddr_storage *addr, const int address_family))dlsym(libHandle, "zts_get_address");
- _zts_get_6plane_addr = (void(*)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId))dlsym(libHandle, "zts_get_6plane_addr");
- _zts_get_rfc4193_addr = (void(*)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId))dlsym(libHandle, "zts_get_rfc4193_addr");
- _zts_get_peer_count = (unsigned long(*)(void))dlsym(libHandle, "zts_get_peer_count");
- _zts_get_peer_address = (int(*)(char *peer, const uint64_t nodeId))dlsym(libHandle, "zts_get_peer_address");
- _zts_socket = (int(*)(int socket_family, int socket_type, int protocol))dlsym(libHandle, "zts_socket");
- _zts_connect = (int(*)(int fd, const struct sockaddr *addr, socklen_t addrlen))dlsym(libHandle, "zts_connect");
- _zts_bind = (int(*)(int fd, const struct sockaddr *addr, socklen_t addrlen))dlsym(libHandle, "zts_bind");
- _zts_listen = (int(*)(int fd, int backlog))dlsym(libHandle, "zts_listen");
- _zts_accept = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_accept");
- #if defined(__linux__)
- _zts_accept4 = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags))dlsym(libHandle, "zts_accept4");
- #endif
- _zts_setsockopt = (int(*)(int fd, int level, int optname, const void *optval, socklen_t optlen))dlsym(libHandle, "zts_setsockopt");
- _zts_getsockopt = (int(*)(int fd, int level, int optname, void *optval, socklen_t *optlen))dlsym(libHandle, "zts_getsockopt");
- _zts_getsockname = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_getsockname");
- _zts_getpeername = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_getpeername");
- _zts_gethostname = (int(*)(char *name, size_t len))dlsym(libHandle, "zts_gethostname");
- _zts_sethostname = (int(*)(const char *name, size_t len))dlsym(libHandle, "zts_sethostname");
- _zts_gethostbyname = (struct hostent*(*)(const char *name))dlsym(libHandle, "zts_gethostbyname");
- _zts_close = (int(*)(int fd))dlsym(libHandle, "zts_close");
- _zts_fcntl = (int(*)(int fd, int cmd, int flags))dlsym(libHandle, "zts_fcntl");
- _zts_ioctl = (int(*)(int fd, unsigned long request, void *argp))dlsym(libHandle, "zts_ioctl");
- _zts_send = (ssize_t(*)(int fd, const void *buf, size_t len, int flags))dlsym(libHandle, "zts_send");
- _zts_sendto = (ssize_t(*)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen))dlsym(libHandle, "zts_sendto");
- _zts_sendmsg = (ssize_t(*)(int fd, const struct msghdr *msg, int flags))dlsym(libHandle, "zts_sendmsg");
- _zts_recv = (ssize_t(*)(int fd, void *buf, size_t len, int flags))dlsym(libHandle, "zts_recv");
- _zts_recvfrom = (ssize_t(*)(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_recvfrom");
- _zts_recvmsg = (ssize_t(*)(int fd, struct msghdr *msg,int flags))dlsym(libHandle, "zts_recvmsg");
- _zts_read = (int(*)(int fd, void *buf, size_t len))dlsym(libHandle, "zts_read");
- _zts_write = (int(*)(int fd, const void *buf, size_t len))dlsym(libHandle, "zts_write");
- _zts_shutdown = (int(*)(int fd, int how))dlsym(libHandle, "zts_shutdown");
- _zts_add_dns_nameserver = (int(*)(struct sockaddr *addr))dlsym(libHandle, "zts_add_dns_nameserver");
-}
-
-char *msg = (char*)"welcome to the machine";
-
-int main(int argc, char **argv)
-{
- if (argc != 5) {
- printf("\nlibzt example client\n");
- printf("client [config_file_path] [nwid] [remote_addr] [remote_port]\n");
- exit(0);
- }
-
-#ifdef __linux__
- char *library_path = (char*)"./libzt.so";
-#endif
-#ifdef __APPLE__
- char *library_path = (char*)"./libzt.dylib";
-#endif
- load_library_symbols(library_path);
-
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- std::string remote_addr = argv[3];
- int remote_port = atoi(argv[4]);
- int r=0, w=0, err=0, sockfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in in4;
- in4.sin_port = htons(remote_port);
- in4.sin_addr.s_addr = inet_addr(remote_addr.c_str());
- in4.sin_family = AF_INET;
-
- //
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- _zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = _zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = _zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
-
- if ((err = _zts_connect(sockfd, (const struct sockaddr *)&in4, sizeof(in4))) < 0) {
- printf("error connecting to remote host (%d)\n", err);
- }
-
- printf("sending to server...\n");
- w = _zts_write(sockfd, msg, strlen(msg));
-
- printf("reading from server...\n");
- r = _zts_read(sockfd, rbuf, strlen(msg));
-
- printf("Sent : %s\n", msg);
- printf("Received : %s\n", rbuf);
-
- err = _zts_close(sockfd);
-
- return err;
-}
-
-#endif // _MSC_VER
\ No newline at end of file
diff --git a/examples/cpp/sharedlib/ipv4server_shared.cpp b/examples/cpp/sharedlib/ipv4server_shared.cpp
deleted file mode 100644
index e5262cb..0000000
--- a/examples/cpp/sharedlib/ipv4server_shared.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * ZeroTier SDK - Network Virtualization Everywhere
- * Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#if !defined(_MSC_VER)
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "libzt.h"
-
-// function pointers which will have values assigned once the dynamic library is loaded
-
-int (*_zts_set_service_port)(int portno);
-int (*_zts_start)(const char *path, bool blocking);
-int (*_zts_startjoin)(const char*, uint64_t);
-void (*_zts_stop)(void);
-int (*_zts_core_running)(void);
-int (*_zts_stack_running)(void);
-int (*_zts_ready)(void);
-int (*_zts_join)(const uint64_t);
-int (*_zts_leave)(const uint64_t);
-void (*_zts_get_path)(char *homePath, const size_t len);
-uint64_t (*_zts_get_node_id)(void);
-int (*_zts_has_address)(const uint64_t);
-int (*_zts_get_num_assigned_addresses)(const uint64_t nwid);
-int (*_zts_get_address_at_index)(const uint64_t nwid, const int index, struct sockaddr_storage *addr);
-int (*_zts_get_address)(const uint64_t nwid, struct sockaddr_storage *addr, const int address_family);
-void (*_zts_get_6plane_addr)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId);
-void (*_zts_get_rfc4193_addr)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId);
-unsigned long (*_zts_get_peer_count)(void);
-int (*_zts_get_peer_address)(char *peer, const uint64_t nodeId);
-int (*_zts_socket)(int socket_family, int socket_type, int protocol);
-int (*_zts_connect)(int fd, const struct sockaddr *addr, socklen_t addrlen);
-int (*_zts_bind)(int fd, const struct sockaddr *addr, socklen_t addrlen);
-int (*_zts_listen)(int fd, int backlog);
-int (*_zts_accept)(int fd, struct sockaddr *addr, socklen_t *addrlen);
-#if defined(__linux__)
-int (*_zts_accept4)(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags);
-#endif
-int (*_zts_setsockopt)(int fd, int level, int optname, const void *optval, socklen_t optlen);
-int (*_zts_getsockopt)(int fd, int level, int optname, void *optval, socklen_t *optlen);
-int (*_zts_getsockname)(int fd, struct sockaddr *addr, socklen_t *addrlen);
-int (*_zts_getpeername)(int fd, struct sockaddr *addr, socklen_t *addrlen);
-int (*_zts_gethostname)(char *name, size_t len);
-int (*_zts_sethostname)(const char *name, size_t len);
-struct hostent *(*_zts_gethostbyname)(const char *name);
-int (*_zts_close)(int fd);
-int(*_zts_fcntl)(int fd, int cmd, int flags);
-int (*_zts_ioctl)(int fd, unsigned long request, void *argp);
-ssize_t (*_zts_send)(int fd, const void *buf, size_t len, int flags);
-ssize_t (*_zts_sendto)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen);
-ssize_t (*_zts_sendmsg)(int fd, const struct msghdr *msg, int flags);
-ssize_t (*_zts_recv)(int fd, void *buf, size_t len, int flags);
-ssize_t (*_zts_recvfrom)(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen);
-ssize_t (*_zts_recvmsg)(int fd, struct msghdr *msg,int flags);
-int (*_zts_read)(int fd, void *buf, size_t len);
-int (*_zts_write)(int fd, const void *buf, size_t len);
-int (*_zts_shutdown)(int fd, int how);
-int (*_zts_add_dns_nameserver)(struct sockaddr *addr);
-int (*_zts_del_dns_nameserver)(struct sockaddr *addr);
-
-
-void load_library_symbols(char *library_path)
-{
- void *libHandle = dlopen(library_path, RTLD_LAZY);
- if (libHandle == NULL) {
- DEBUG_ERROR("unable to load dynamic libs: %s", dlerror());
- exit(-1);
- }
-
- // Load symbols from library (call these directly)
-
- _zts_set_service_port = (int(*)(int portno))dlsym(libHandle, "zts_set_service_port");
- _zts_start = (int(*)(const char *path, bool blocking))dlsym(libHandle, "zts_start");
- _zts_startjoin = (int(*)(const char*, uint64_t))dlsym(libHandle, "zts_startjoin");
- _zts_stop = (void(*)(void))dlsym(libHandle, "zts_stop");
- _zts_core_running = (int(*)(void))dlsym(libHandle, "zts_core_running");
- _zts_stack_running = (int(*)(void))dlsym(libHandle, "zts_stack_running");
- _zts_ready = (int(*)(void))dlsym(libHandle, "zts_ready");
- _zts_join = (int(*)(const uint64_t))dlsym(libHandle, "zts_join");
- _zts_leave = (int(*)(const uint64_t))dlsym(libHandle, "zts_leave");
- _zts_get_path = (void(*)(char *homePath, const size_t len))dlsym(libHandle, "zts_get_path");
- _zts_get_node_id = (uint64_t(*)(void))dlsym(libHandle, "zts_get_node_id");
- _zts_has_address = (int(*)(const uint64_t))dlsym(libHandle, "zts_has_address");
- _zts_get_num_assigned_addresses = (int(*)(const uint64_t nwid))dlsym(libHandle, "zts_get_num_assigned_addresses");
- _zts_get_address_at_index = (int(*)(const uint64_t nwid, const int index, struct sockaddr_storage *addr))dlsym(libHandle, "zts_get_address_at_index");
- _zts_get_address = (int(*)(const uint64_t nwid, struct sockaddr_storage *addr, const int address_family))dlsym(libHandle, "zts_get_address");
- _zts_get_6plane_addr = (void(*)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId))dlsym(libHandle, "zts_get_6plane_addr");
- _zts_get_rfc4193_addr = (void(*)(struct sockaddr_storage *addr, const uint64_t nwid, const uint64_t nodeId))dlsym(libHandle, "zts_get_rfc4193_addr");
- _zts_get_peer_count = (unsigned long(*)(void))dlsym(libHandle, "zts_get_peer_count");
- _zts_get_peer_address = (int(*)(char *peer, const uint64_t nodeId))dlsym(libHandle, "zts_get_peer_address");
- _zts_socket = (int(*)(int socket_family, int socket_type, int protocol))dlsym(libHandle, "zts_socket");
- _zts_connect = (int(*)(int fd, const struct sockaddr *addr, socklen_t addrlen))dlsym(libHandle, "zts_connect");
- _zts_bind = (int(*)(int fd, const struct sockaddr *addr, socklen_t addrlen))dlsym(libHandle, "zts_bind");
- _zts_listen = (int(*)(int fd, int backlog))dlsym(libHandle, "zts_listen");
- _zts_accept = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_accept");
- #if defined(__linux__)
- _zts_accept4 = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags))dlsym(libHandle, "zts_accept4");
- #endif
- _zts_setsockopt = (int(*)(int fd, int level, int optname, const void *optval, socklen_t optlen))dlsym(libHandle, "zts_setsockopt");
- _zts_getsockopt = (int(*)(int fd, int level, int optname, void *optval, socklen_t *optlen))dlsym(libHandle, "zts_getsockopt");
- _zts_getsockname = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_getsockname");
- _zts_getpeername = (int(*)(int fd, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_getpeername");
- _zts_gethostname = (int(*)(char *name, size_t len))dlsym(libHandle, "zts_gethostname");
- _zts_sethostname = (int(*)(const char *name, size_t len))dlsym(libHandle, "zts_sethostname");
- _zts_gethostbyname = (struct hostent*(*)(const char *name))dlsym(libHandle, "zts_gethostbyname");
- _zts_close = (int(*)(int fd))dlsym(libHandle, "zts_close");
- _zts_fcntl = (int(*)(int fd, int cmd, int flags))dlsym(libHandle, "zts_fcntl");
- _zts_ioctl = (int(*)(int fd, unsigned long request, void *argp))dlsym(libHandle, "zts_ioctl");
- _zts_send = (ssize_t(*)(int fd, const void *buf, size_t len, int flags))dlsym(libHandle, "zts_send");
- _zts_sendto = (ssize_t(*)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen))dlsym(libHandle, "zts_sendto");
- _zts_sendmsg = (ssize_t(*)(int fd, const struct msghdr *msg, int flags))dlsym(libHandle, "zts_sendmsg");
- _zts_recv = (ssize_t(*)(int fd, void *buf, size_t len, int flags))dlsym(libHandle, "zts_recv");
- _zts_recvfrom = (ssize_t(*)(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen))dlsym(libHandle, "zts_recvfrom");
- _zts_recvmsg = (ssize_t(*)(int fd, struct msghdr *msg,int flags))dlsym(libHandle, "zts_recvmsg");
- _zts_read = (int(*)(int fd, void *buf, size_t len))dlsym(libHandle, "zts_read");
- _zts_write = (int(*)(int fd, const void *buf, size_t len))dlsym(libHandle, "zts_write");
- _zts_shutdown = (int(*)(int fd, int how))dlsym(libHandle, "zts_shutdown");
- _zts_add_dns_nameserver = (int(*)(struct sockaddr *addr))dlsym(libHandle, "zts_add_dns_nameserver");
-}
-
-int main(int argc, char **argv)
-{
- if (argc != 4) {
- printf("\nlibzt example server\n");
- printf("server [config_file_path] [nwid] [bind_port]\n");
- exit(0);
- }
-
-#ifdef __linux__
- char *library_path = (char*)"./libzt.so";
-#endif
-#ifdef __APPLE__
- char *library_path = (char*)"./libzt.dylib";
-#endif
- load_library_symbols(library_path);
-
- std::string path = argv[1];
- std::string nwidstr = argv[2];
- int bind_port = atoi(argv[3]);
- int w=0, r=0, err=0, sockfd, accfd;
- char rbuf[32];
- memset(rbuf, 0, sizeof rbuf);
-
- struct sockaddr_in in4, acc_in4;
- in4.sin_port = htons(bind_port);
- in4.sin_addr.s_addr = INADDR_ANY;
- in4.sin_family = AF_INET;
-
- //
-
- printf("Waiting for libzt to come online...\n");
- uint64_t nwid = strtoull(nwidstr.c_str(),NULL,16);
- printf("nwid=%llx\n", (unsigned long long)nwid);
- _zts_startjoin(path.c_str(), nwid);
- uint64_t nodeId = _zts_get_node_id();
- printf("I am %llx\n", (unsigned long long)nodeId);
-
- if ((sockfd = _zts_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- printf("error creating ZeroTier socket\n");
- }
- if ((err = _zts_bind(sockfd, (struct sockaddr *)&in4, sizeof(struct sockaddr_in)) < 0)) {
- printf("error binding to interface (%d)\n", err);
- }
- if ((err = _zts_listen(sockfd, 100)) < 0) {
- printf("error placing socket in LISTENING state (%d)\n", err);
- }
- socklen_t client_addrlen = sizeof(sockaddr_in);
- if ((accfd = _zts_accept(sockfd, (struct sockaddr *)&acc_in4, &client_addrlen)) < 0) {
- printf("error accepting connection (%d)\n", err);
- }
-
- socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
- _zts_getpeername(accfd, (struct sockaddr*)&acc_in4, &peer_addrlen);
- DEBUG_INFO("accepted connection from %s : %d\n", inet_ntoa(acc_in4.sin_addr), ntohs(acc_in4.sin_port));
-
- printf("reading from client...\n");
- r = _zts_read(accfd, rbuf, sizeof rbuf);
-
- printf("sending to client...\n");
- w = _zts_write(accfd, rbuf, strlen(rbuf));
-
- printf("Received : %s\n", rbuf);
-
- err = _zts_close(sockfd);
- err = _zts_close(accfd);
-
- return err;
-}
-
-#endif // _MSC_VER
diff --git a/test/example.cpp b/test/example.cpp
deleted file mode 100644
index 11ff33c..0000000
--- a/test/example.cpp
+++ /dev/null
@@ -1,280 +0,0 @@
-#include
-#include
-#include
-#include
-
-#include "ZeroTier.h"
-
-bool node_ready = false;
-bool network_ready = false;
-
-// Example callbacks
-void myZeroTierEventCallback(struct zts_callback_msg *msg)
-{
- //
- // Node events
- //
- if (msg->eventCode == ZTS_EVENT_NODE_ONLINE) {
- printf("ZTS_EVENT_NODE_ONLINE, node=%llx\n", msg->node->address);
- node_ready = true;
- // ZeroTier service is running and online
- }
- if (msg->eventCode == ZTS_EVENT_NODE_OFFLINE) {
- printf("ZTS_EVENT_NODE_OFFLINE\n");
- node_ready = false;
- // ZeroTier service is running and online
- }
- if (msg->eventCode == ZTS_EVENT_NODE_NORMAL_TERMINATION) {
- printf("ZTS_EVENT_NODE_NORMAL_TERMINATION\n");
- // ZeroTier service has stopped
- }
-
- //
- // Virtual network events
- //
- if (msg->eventCode == ZTS_EVENT_NETWORK_NOT_FOUND) {
- printf("ZTS_EVENT_NETWORK_NOT_FOUND --- network=%llx\n", msg->network->nwid);
- // Is your nwid incorrect?
- }
- if (msg->eventCode == ZTS_EVENT_NETWORK_REQUESTING_CONFIG) {
- printf("ZTS_EVENT_NETWORK_REQUESTING_CONFIG --- network=%llx\n", msg->network->nwid);
- // Node is requesting network config details from controller, please wait
- }
- if (msg->eventCode == ZTS_EVENT_NETWORK_ACCESS_DENIED) {
- printf("ZTS_EVENT_NETWORK_ACCESS_DENIED --- network=%llx\n", msg->network->nwid);
- // This node is not authorized to join nwid
- }
- if (msg->eventCode == ZTS_EVENT_NETWORK_READY_IP4) {
- printf("ZTS_EVENT_NETWORK_READY_IP4 --- network=%llx\n", msg->network->nwid);
- network_ready = true;
- // IPv4 traffic can now be processed for nwid
- }
- if (msg->eventCode == ZTS_EVENT_NETWORK_READY_IP6) {
- printf("ZTS_EVENT_NETWORK_READY_IP6 --- network=%llx\n", msg->network->nwid);
- network_ready = true;
- }
- if (msg->eventCode == ZTS_EVENT_NETWORK_DOWN) {
- printf("ZTS_EVENT_NETWORK_DOWN --- network=%llx\n", msg->network->nwid);
- // Can happen if another thread called zts_leave()
- }
-
- //
- // Network stack events
- //
- if (msg->eventCode == ZTS_EVENT_NETIF_UP) {
- printf("ZTS_EVENT_NETIF_UP --- network=%llx, mac=%llx, mtu=%d\n",
- msg->netif->nwid,
- msg->netif->mac,
- msg->netif->mtu);
- network_ready = true;
- }
- if (msg->eventCode == ZTS_EVENT_NETIF_DOWN) {
- printf("ZTS_EVENT_NETIF_DOWN --- network=%llx, mac=%llx\n",
- msg->netif->nwid,
- msg->netif->mac);
-
- network_ready = true;
- }
-
- //
- // Address events
- //
- if (msg->eventCode == ZTS_EVENT_ADDR_ADDED_IP4) {
- char ipstr[INET_ADDRSTRLEN];
- struct sockaddr_in *in4 = (struct sockaddr_in*)&(msg->addr->addr);
- inet_ntop(AF_INET, &(in4->sin_addr), ipstr, INET_ADDRSTRLEN);
- printf("ZTS_EVENT_ADDR_NEW_IP4 --- addr=%s (on network=%llx)\n",
- ipstr, msg->addr->nwid);
- }
- if (msg->eventCode == ZTS_EVENT_ADDR_ADDED_IP6) {
- char ipstr[INET6_ADDRSTRLEN];
- struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&(msg->addr->addr);
- inet_ntop(AF_INET6, &(in6->sin6_addr), ipstr, INET6_ADDRSTRLEN);
- printf("ZTS_EVENT_ADDR_NEW_IP6 --- addr=%s (on network=%llx)\n",
- ipstr, msg->addr->nwid);
- }
- if (msg->eventCode == ZTS_EVENT_ADDR_REMOVED_IP4) {
- char ipstr[INET_ADDRSTRLEN];
- struct sockaddr_in *in4 = (struct sockaddr_in*)&(msg->addr->addr);
- inet_ntop(AF_INET, &(in4->sin_addr), ipstr, INET_ADDRSTRLEN);
- printf("ZTS_EVENT_ADDR_REMOVED_IP4 --- addr=%s (on network=%llx)\n",
- ipstr, msg->addr->nwid);
- }
- if (msg->eventCode == ZTS_EVENT_ADDR_REMOVED_IP6) {
- char ipstr[INET6_ADDRSTRLEN];
- struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&(msg->addr->addr);
- inet_ntop(AF_INET6, &(in6->sin6_addr), ipstr, INET6_ADDRSTRLEN);
- printf("ZTS_EVENT_ADDR_REMOVED_IP6 --- addr=%s (on network=%llx)\n",
- ipstr, msg->addr->nwid);
- }
-
- //
- // Peer events
- //
- if (msg->eventCode == ZTS_EVENT_PEER_P2P) {
- printf("ZTS_EVENT_PEER_P2P --- node=%llx\n", msg->peer->address);
- // A direct path is known for nodeId
- }
- if (msg->eventCode == ZTS_EVENT_PEER_RELAY) {
- printf("ZTS_EVENT_PEER_RELAY --- node=%llx\n", msg->peer->address);
- // No direct path is known for nodeId
- }
-}
-
-void printPeerDetails(struct zts_peer_details *pd)
-{
- printf("\npeer=%llx, latency=%d, version=%d.%d.%d, pathCount=%d\n",
- pd->address,
- pd->latency,
- pd->versionMajor,
- pd->versionMinor,
- pd->versionRev,
- pd->pathCount);
- // Print all known paths for each peer
- for (int j=0; jpathCount; j++) {
- char ipstr[INET6_ADDRSTRLEN];
- int port;
- struct sockaddr *sa = (struct sockaddr *)&(pd->paths[j].address);
- if (sa->sa_family == AF_INET) {
- struct sockaddr_in *in4 = (struct sockaddr_in*)sa;
- inet_ntop(AF_INET, &(in4->sin_addr), ipstr, INET_ADDRSTRLEN);
- port = ntohs(in4->sin_port);
- }
- if (sa->sa_family == AF_INET6) {
- struct sockaddr_in6 *in6 = (struct sockaddr_in6*)sa;
- inet_ntop(AF_INET6, &(in6->sin6_addr), ipstr, INET6_ADDRSTRLEN);
- }
- printf("\tpath[%d]=%s, port=%d\n", j, ipstr, port);
- }
-}
-
-void getSinglePeerDetails(uint64_t peerId)
-{
- struct zts_peer_details pd;
- int err = zts_get_peer(&pd, peerId);
-
- if (err == ZTS_ERR_OK) {
- printf("(%d) call succeeded\n", err);
- } if (err == ZTS_ERR_INVALID_ARG) {
- printf("(%d) invalid argument\n", err);
- return;
- } if (err == ZTS_ERR_SERVICE) {
- printf("(%d) error: service is unavailable\n", err);
- return;
- } if (err == ZTS_ERR_INVALID_OP) {
- printf("(%d) error: invalid API operation\n", err);
- return;
- } if (err == ZTS_ERR_NO_RESULT) {
- printf("(%d) error: object or result not found\n", err);
- return;
- }
- if (err == 0) { // ZTS_ERR_OK
- printPeerDetails(&pd);
- }
-}
-
-// Similar to "zerotier-cli listpeers"
-void getAllPeerDetails()
-{
- struct zts_peer_details pd[128];
- /* This number should be large enough to handle the
- expected number of peers. This call can also get
- expensive for large numbers of peers. Consider using
- get_peer(struct zts_peer_details *pds, uint64_t peerId)
- instead */
- int num = 128;
- int err;
- if ((err = zts_get_peers(pd, &num)) < 0) {
- printf("error (%d)\n", err);
- return;
- }
- if (num) {
- printf("num=%d\n", num);
- for (int i=0; i.
- *
- * --
- *
- * You can be released from the requirements of the license by purchasing
- * a commercial license. Buying such a license is mandatory as soon as you
- * develop commercial closed-source software that incorporates or links
- * directly against ZeroTier software without disclosing the source code
- * of your own application.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include