diff --git a/make-linux.mk b/make-linux.mk index fafff5d..ca8b1a7 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -80,6 +80,7 @@ INCLUDES+= -Iext \ -I../$(ZT1)/service \ -I. \ -Isrc \ + -Isrc/stack_drivers \ -I$(LWIP_DIR)/src/include \ -I$(LWIP_DIR)/src/include/ipv4 \ -I$(LWIP_DIR)/src/include/ipv6 \ @@ -125,7 +126,7 @@ endif # Debug output for the SDK -# Specific levels can be controlled in src/SDK_Debug.h +# Specific levels can be controlled in src/debug.h ifeq ($(SDK_DEBUG),1) DEFS+=-DSDK_DEBUG -g endif @@ -173,11 +174,11 @@ one: $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/LinuxEthernet # Build only the intercept library linux_intercept: # Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility - cd src ; gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o ../$(INTERCEPT) SDK_Sockets.c SDK_Intercept.c SDK_RPC.c -ldl + cd src ; gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o ../$(INTERCEPT) sockets.c intercept.c rpc.c -ldl # Build only the SDK service linux_sdk_service: pico lwip $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) -DSDK -DZT_ONE_NO_ROOT_CHECK -o $(SDK_SERVICE) $(OBJS) $(ZT1)/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp $(ZT1)/one.cpp src/SDK_RPC.c $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) -DSDK -DZT_ONE_NO_ROOT_CHECK -o $(SDK_SERVICE) $(OBJS) $(ZT1)/service/OneService.cpp src/tap.cpp src/proxy.cpp $(ZT1)/one.cpp src/rpc.c $(LDLIBS) -ldl ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-cli ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-idtool @@ -186,7 +187,7 @@ linux_service_and_intercept: linux_intercept linux_sdk_service # Builds a single shared library which contains everything linux_shared_lib: $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) -DSDK -DZT_ONE_NO_ROOT_CHECK -shared -o $(SHARED_LIB) $(OBJS) zerotierone/service/OneService.cpp src/SDK_Service.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_Sockets.c src/SDK_Intercept.c src/SDK_RPC.c $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) -DSDK -DZT_ONE_NO_ROOT_CHECK -shared -o $(SHARED_LIB) $(OBJS) zerotierone/service/OneService.cpp src/service.cpp src/tap.cpp src/proxy.cpp zerotierone/one.cpp -x c src/sockets.c src/intercept.c src/rpc.c $(LDLIBS) -ldl diff --git a/make-mac.mk b/make-mac.mk index 58e5b88..3b05994 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -24,8 +24,6 @@ ONE_CLI = $(BUILD)/$(ONE_CLI_NAME) ONE_IDTOOL = $(BUILD)/$(ONE_IDTOOL_NAME) LWIP_LIB = $(BUILD)/$(LWIP_LIB_NAME) # -LWIP_2_DIR = ext/lwip_2.0.0 -LWIP_1_DIR = ext/lwip_1.4.1 LWIP_BASE_DIR = ext/lwip # Automagically pick clang or gcc, with preference for clang diff --git a/objects.mk b/objects.mk index 05930ac..2c02cb1 100644 --- a/objects.mk +++ b/objects.mk @@ -2,15 +2,14 @@ OBJS=\ zerotierone/ext/lz4/lz4.o \ zerotierone/ext/json-parser/json.o \ zerotierone/ext/http-parser/http_parser.o \ - zerotierone/controller/EmbeddedNetworkController.o \ zerotierone/node/C25519.o \ - zerotierone/node/Capability.o \ zerotierone/node/CertificateOfMembership.o \ zerotierone/node/Cluster.o \ + zerotierone/node/DeferredPackets.o \ + zerotierone/node/Dictionary.o \ zerotierone/node/Identity.o \ zerotierone/node/IncomingPacket.o \ zerotierone/node/InetAddress.o \ - zerotierone/node/Membership.o \ zerotierone/node/Multicaster.o \ zerotierone/node/Network.o \ zerotierone/node/NetworkConfig.o \ @@ -20,16 +19,13 @@ OBJS=\ zerotierone/node/Path.o \ zerotierone/node/Peer.o \ zerotierone/node/Poly1305.o \ - zerotierone/node/Revocation.o \ zerotierone/node/Salsa20.o \ zerotierone/node/SelfAwareness.o \ zerotierone/node/SHA512.o \ zerotierone/node/Switch.o \ - zerotierone/node/Tag.o \ zerotierone/node/Topology.o \ zerotierone/node/Utils.o \ zerotierone/osdep/BackgroundResolver.o \ - zerotierone/osdep/ManagedRoute.o \ zerotierone/osdep/Http.o \ zerotierone/osdep/OSUtils.o \ zerotierone/service/ClusterGeoIpService.o \ diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..1b3e623 --- /dev/null +++ b/src/README.md @@ -0,0 +1,5 @@ +Source Directory Structure +==== + +`wrappers` - Example bindings of the ZeroTierSDK Sockets API to your favorite native languages +`stack_drivers` - Drivers to mate various network stacks to the ZeroTier tap interface diff --git a/src/SDK.h b/src/SDK.h index 3fb1d08..6704f63 100644 --- a/src/SDK.h +++ b/src/SDK.h @@ -30,14 +30,14 @@ #include #include -#include "SDK_Signatures.h" +#include "signatures.h" #if defined(__ANDROID__) // For defining the Android direct-call API #include #endif -#include "SDK_LocalBuild.h" +#include "build.h" #ifdef __cplusplus extern "C" { diff --git a/src/SDK_LocalBuild.h b/src/build.h similarity index 100% rename from src/SDK_LocalBuild.h rename to src/build.h diff --git a/src/SDK_Debug.h b/src/debug.h similarity index 100% rename from src/SDK_Debug.h rename to src/debug.h diff --git a/src/SDK_defs.h b/src/defs.h similarity index 100% rename from src/SDK_defs.h rename to src/defs.h diff --git a/src/SDK_Intercept.c b/src/intercept.c similarity index 99% rename from src/SDK_Intercept.c rename to src/intercept.c index 7122ca6..d570b25 100644 --- a/src/SDK_Intercept.c +++ b/src/intercept.c @@ -42,7 +42,6 @@ #include #include #include -//#include #include #include #include @@ -55,9 +54,9 @@ #include #endif -#include "SDK.h" -#include "SDK_Debug.h" -#include "SDK_RPC.h" +#include "sdk.h" +#include "debug.h" +#include "rpc.h" pthread_key_t thr_id_key; //char *api_netpath; diff --git a/src/SDK_Proxy.cpp b/src/proxy.cpp similarity index 99% rename from src/SDK_Proxy.cpp rename to src/proxy.cpp index d55953c..919ed67 100644 --- a/src/SDK_Proxy.cpp +++ b/src/proxy.cpp @@ -25,8 +25,9 @@ * LLC. Start here: http://www.zerotier.com/ */ -#include "SDK_Debug.h" -#include "SDK_EthernetTap.hpp" +#include "debug.h" +#include "tap.hpp" + #include "Phy.hpp" #include "Utils.hpp" #include "OSUtils.hpp" diff --git a/src/SDK_RPC.c b/src/rpc.c similarity index 99% rename from src/SDK_RPC.c rename to src/rpc.c index cd8505c..a968627 100644 --- a/src/SDK_RPC.c +++ b/src/rpc.c @@ -41,12 +41,11 @@ #include #include #include -//#include #include -#include "SDK.h" -#include "SDK_RPC.h" -#include "SDK_Debug.h" +#include "sdk.h" +#include "rpc.h" +#include "debug.h" // externs common between SDK_Intercept and SDK_Socket from SDK.h diff --git a/src/SDK_RPC.h b/src/rpc.h similarity index 100% rename from src/SDK_RPC.h rename to src/rpc.h diff --git a/src/SDK_Service.cpp b/src/service.cpp similarity index 99% rename from src/SDK_Service.cpp rename to src/service.cpp index 8dccbc9..8274ece 100644 --- a/src/SDK_Service.cpp +++ b/src/service.cpp @@ -46,10 +46,10 @@ #include "Utils.hpp" #include "OSUtils.hpp" -#include "SDK_EthernetTap.hpp" -#include "SDK.h" -#include "SDK_Debug.h" -#include "SDK_LocalBuild.h" +#include "tap.hpp" +#include "sdk.h" +#include "debug.h" +#include "build.h" std::string service_path; pthread_t intercept_thread; diff --git a/src/SDK_Signatures.h b/src/signatures.h similarity index 100% rename from src/SDK_Signatures.h rename to src/signatures.h diff --git a/src/SDK_Sockets.c b/src/sockets.c similarity index 99% rename from src/SDK_Sockets.c rename to src/sockets.c index b88e6a5..b121162 100644 --- a/src/SDK_Sockets.c +++ b/src/sockets.c @@ -68,10 +68,11 @@ #endif #define SOCK_TYPE_MASK 0xf -#include "SDK.h" -#include "SDK_Signatures.h" -#include "SDK_Debug.h" -#include "SDK_RPC.h" +#include "sdk.h" +#include "signatures.h" +#include "debug.h" +#include "rpc.h" + #include "Constants.hpp" // For Tap's MTU // Prototypes diff --git a/src/stack_drivers/README.md b/src/stack_drivers/README.md new file mode 100644 index 0000000..ba713dc --- /dev/null +++ b/src/stack_drivers/README.md @@ -0,0 +1,4 @@ +Stack Drivers +==== + +These files contain code to load and interface with network stacks. diff --git a/src/SDK_jip.hpp b/src/stack_drivers/jip.hpp similarity index 99% rename from src/SDK_jip.hpp rename to src/stack_drivers/jip.hpp index b004c5a..b0b796e 100644 --- a/src/SDK_jip.hpp +++ b/src/stack_drivers/jip.hpp @@ -30,7 +30,7 @@ #include "Mutex.hpp" #include "OSUtils.hpp" -#include "SDK_Debug.h" +#include "debug.h" #include #include diff --git a/src/SDK_lwip.hpp b/src/stack_drivers/lwip.hpp similarity index 99% rename from src/SDK_lwip.hpp rename to src/stack_drivers/lwip.hpp index 2e4719c..bfc0df8 100644 --- a/src/SDK_lwip.hpp +++ b/src/stack_drivers/lwip.hpp @@ -42,7 +42,7 @@ #include "Mutex.hpp" #include "OSUtils.hpp" -#include "SDK_Debug.h" +#include "debug.h" #include #include diff --git a/src/SDK_picoTCP.hpp b/src/stack_drivers/picotcp.hpp similarity index 99% rename from src/SDK_picoTCP.hpp rename to src/stack_drivers/picotcp.hpp index 443e017..8242ffd 100644 --- a/src/SDK_picoTCP.hpp +++ b/src/stack_drivers/picotcp.hpp @@ -43,8 +43,8 @@ #include "Constants.hpp" #include "Phy.hpp" -#include "SDK_Debug.h" -#include "SDK_EthernetTap.hpp" +#include "debug.h" +#include "tap.hpp" #include "pico_stack.h" #include "pico_ipv4.h" diff --git a/src/SDK_EthernetTap.cpp b/src/tap.cpp similarity index 99% rename from src/SDK_EthernetTap.cpp rename to src/tap.cpp index fdf0dae..fb3b8c2 100644 --- a/src/SDK_EthernetTap.cpp +++ b/src/tap.cpp @@ -35,16 +35,16 @@ #include #include -#include "SDK_EthernetTap.hpp" -#include "SDK_Utils.hpp" -#include "SDK.h" -#include "SDK_defs.h" -#include "SDK_Debug.h" +#include "tap.hpp" +#include "utils.hpp" +#include "sdk.h" +#include "defs.h" +#include "debug.h" #if defined(SDK_LWIP) - #include "SDK_lwIP.hpp" + #include "lwip.hpp" #elif defined(SDK_PICOTCP) - #include "SDK_picoTCP.hpp" + #include "picotcp.hpp" #include "pico_stack.h" #include "pico_ipv4.h" #include "pico_icmp4.h" @@ -52,7 +52,7 @@ #include "pico_protocol.h" #include "pico_socket.h" #elif defined(SDK_JIP) - #include "SDK_jip.hpp" + #include "jip.hpp" #endif #include "Utils.hpp" diff --git a/src/SDK_EthernetTap.hpp b/src/tap.hpp similarity index 99% rename from src/SDK_EthernetTap.hpp rename to src/tap.hpp index 57c38fc..bc14436 100644 --- a/src/SDK_EthernetTap.hpp +++ b/src/tap.hpp @@ -46,13 +46,13 @@ #include "netif/etharp.h" -#include "SDK_defs.h" -#include "SDK_RPC.h" -#include "SDK_lwIP.hpp" -#include "SDK_jip.hpp" +#include "defs.h" +#include "rpc.h" +#include "lwip.hpp" +#include "jip.hpp" #if defined(SDK_PICOTCP) - #include "SDK_picoTCP.hpp" + #include "picotcp.hpp" #include "pico_protocol.h" #endif diff --git a/src/SDK_Utils.hpp b/src/utils.hpp similarity index 100% rename from src/SDK_Utils.hpp rename to src/utils.hpp diff --git a/src/wrappers/README.md b/src/wrappers/README.md new file mode 100644 index 0000000..2909c56 --- /dev/null +++ b/src/wrappers/README.md @@ -0,0 +1,3 @@ +Language/Framework Wrappers +==== +These wrappers are designed to abstract the ZeroTierSDK Sockets API (implemented in `src/Sockets.c`) to your native language of choice. Specific examples of how to use these are located in the `integrations` directory.. diff --git a/src/SDK_DotNetWrapper.cs b/src/wrappers/dotnet/DotNetWrapper.cs similarity index 100% rename from src/SDK_DotNetWrapper.cs rename to src/wrappers/dotnet/DotNetWrapper.cs diff --git a/src/SDK_JavaWrapper.java b/src/wrappers/java/JavaWrapper.java similarity index 100% rename from src/SDK_JavaWrapper.java rename to src/wrappers/java/JavaWrapper.java diff --git a/src/SDK_ZTAddress.java b/src/wrappers/java/ZTAddress.java similarity index 100% rename from src/SDK_ZTAddress.java rename to src/wrappers/java/ZTAddress.java diff --git a/src/SDK_Apple-Bridging-Header.h b/src/wrappers/swift/Apple-Bridging-Header.h similarity index 100% rename from src/SDK_Apple-Bridging-Header.h rename to src/wrappers/swift/Apple-Bridging-Header.h diff --git a/src/SDK_XcodeWrapper.cpp b/src/wrappers/swift/XcodeWrapper.cpp similarity index 100% rename from src/SDK_XcodeWrapper.cpp rename to src/wrappers/swift/XcodeWrapper.cpp diff --git a/src/SDK_XcodeWrapper.hpp b/src/wrappers/swift/XcodeWrapper.hpp similarity index 100% rename from src/SDK_XcodeWrapper.hpp rename to src/wrappers/swift/XcodeWrapper.hpp diff --git a/src/ZTSDK.swift b/src/wrappers/swift/ztsdk.swift similarity index 100% rename from src/ZTSDK.swift rename to src/wrappers/swift/ztsdk.swift diff --git a/zerotierone/ext/README.md b/zerotierone/ext/README.md index f296fa5..be9484c 100644 --- a/zerotierone/ext/README.md +++ b/zerotierone/ext/README.md @@ -1 +1,10 @@ -The ext/ folder contains third party code, drivers, installation support files, etc. \ No newline at end of file +Miscellaneous Stuff +====== + +This subfolder contains: + + * Bundled third party libraries that are compiled into the binary on platforms and Linux distributions where they are not available on the system. + + * Pre-compiled binaries for some platforms, such as pre-built and signed drivers for Mac and Windows. + + * Miscellaneous files used by installers and packages on various platform targets. diff --git a/zerotierone/ext/http-parser/AUTHORS b/zerotierone/ext/http-parser/AUTHORS index 29cdbb1..5323b68 100644 --- a/zerotierone/ext/http-parser/AUTHORS +++ b/zerotierone/ext/http-parser/AUTHORS @@ -61,3 +61,8 @@ Marc O'Morain Jeff Pinner Timothy J Fontaine Akagi201 +Romain Giraud +Jay Satiro +Arne Steen +Kjell Schubert +Olivier MenguĂ© diff --git a/zerotierone/ext/http-parser/http_parser.c b/zerotierone/ext/http-parser/http_parser.c index a113c7f..3c896ff 100644 --- a/zerotierone/ext/http-parser/http_parser.c +++ b/zerotierone/ext/http-parser/http_parser.c @@ -123,7 +123,7 @@ do { \ FOR##_mark = NULL; \ } \ } while (0) - + /* Run the data callback FOR and consume the current byte */ #define CALLBACK_DATA(FOR) \ CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1) @@ -440,7 +440,7 @@ enum http_host_state * character or %x80-FF **/ #define IS_HEADER_CHAR(ch) \ - (ch == CR || ch == LF || ch == 9 || (ch > 31 && ch != 127)) + (ch == CR || ch == LF || ch == 9 || ((unsigned char)ch > 31 && ch != 127)) #define start_state (parser->type == HTTP_REQUEST ? s_start_req : s_start_res) @@ -1007,89 +1007,40 @@ reexecute: UPDATE_STATE(s_req_spaces_before_url); } else if (ch == matcher[parser->index]) { ; /* nada */ - } else if (parser->method == HTTP_CONNECT) { - if (parser->index == 1 && ch == 'H') { - parser->method = HTTP_CHECKOUT; - } else if (parser->index == 2 && ch == 'P') { - parser->method = HTTP_COPY; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (parser->method == HTTP_MKCOL) { - if (parser->index == 1 && ch == 'O') { - parser->method = HTTP_MOVE; - } else if (parser->index == 1 && ch == 'E') { - parser->method = HTTP_MERGE; - } else if (parser->index == 1 && ch == '-') { - parser->method = HTTP_MSEARCH; - } else if (parser->index == 2 && ch == 'A') { - parser->method = HTTP_MKACTIVITY; - } else if (parser->index == 3 && ch == 'A') { - parser->method = HTTP_MKCALENDAR; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (parser->method == HTTP_SUBSCRIBE) { - if (parser->index == 1 && ch == 'E') { - parser->method = HTTP_SEARCH; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (parser->method == HTTP_REPORT) { - if (parser->index == 2 && ch == 'B') { - parser->method = HTTP_REBIND; - } else { + } else if (IS_ALPHA(ch)) { + + switch (parser->method << 16 | parser->index << 8 | ch) { +#define XX(meth, pos, ch, new_meth) \ + case (HTTP_##meth << 16 | pos << 8 | ch): \ + parser->method = HTTP_##new_meth; break; + + XX(POST, 1, 'U', PUT) + XX(POST, 1, 'A', PATCH) + XX(CONNECT, 1, 'H', CHECKOUT) + XX(CONNECT, 2, 'P', COPY) + XX(MKCOL, 1, 'O', MOVE) + XX(MKCOL, 1, 'E', MERGE) + XX(MKCOL, 2, 'A', MKACTIVITY) + XX(MKCOL, 3, 'A', MKCALENDAR) + XX(SUBSCRIBE, 1, 'E', SEARCH) + XX(REPORT, 2, 'B', REBIND) + XX(POST, 1, 'R', PROPFIND) + XX(PROPFIND, 4, 'P', PROPPATCH) + XX(PUT, 2, 'R', PURGE) + XX(LOCK, 1, 'I', LINK) + XX(UNLOCK, 2, 'S', UNSUBSCRIBE) + XX(UNLOCK, 2, 'B', UNBIND) + XX(UNLOCK, 3, 'I', UNLINK) +#undef XX + + default: SET_ERRNO(HPE_INVALID_METHOD); goto error; - } - } else if (parser->index == 1) { - if (parser->method == HTTP_POST) { - if (ch == 'R') { - parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */ - } else if (ch == 'U') { - parser->method = HTTP_PUT; /* or HTTP_PURGE */ - } else if (ch == 'A') { - parser->method = HTTP_PATCH; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (parser->method == HTTP_LOCK) { - if (ch == 'I') { - parser->method = HTTP_LINK; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } } - } else if (parser->index == 2) { - if (parser->method == HTTP_PUT) { - if (ch == 'R') { - parser->method = HTTP_PURGE; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (parser->method == HTTP_UNLOCK) { - if (ch == 'S') { - parser->method = HTTP_UNSUBSCRIBE; - } else if(ch == 'B') { - parser->method = HTTP_UNBIND; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') { - parser->method = HTTP_PROPPATCH; - } else if (parser->index == 3 && parser->method == HTTP_UNLOCK && ch == 'I') { - parser->method = HTTP_UNLINK; + } else if (ch == '-' && + parser->index == 1 && + parser->method == HTTP_MKCOL) { + parser->method = HTTP_MSEARCH; } else { SET_ERRNO(HPE_INVALID_METHOD); goto error; @@ -1861,6 +1812,9 @@ reexecute: case 0: break; + case 2: + parser->upgrade = 1; + case 1: parser->flags |= F_SKIPBODY; break; @@ -2299,12 +2253,13 @@ http_parse_host_char(enum http_host_state s, const char ch) { static int http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { - //assert(u->field_set & (1 << UF_HOST)); enum http_host_state s; const char *p; size_t buflen = u->field_data[UF_HOST].off + u->field_data[UF_HOST].len; + assert(u->field_set & (1 << UF_HOST)); + u->field_data[UF_HOST].len = 0; s = found_at ? s_http_userinfo_start : s_http_host_start; diff --git a/zerotierone/ext/http-parser/http_parser.h b/zerotierone/ext/http-parser/http_parser.h index e33c062..105ae51 100644 --- a/zerotierone/ext/http-parser/http_parser.h +++ b/zerotierone/ext/http-parser/http_parser.h @@ -26,8 +26,8 @@ extern "C" { /* Also update SONAME in the Makefile whenever you change these. */ #define HTTP_PARSER_VERSION_MAJOR 2 -#define HTTP_PARSER_VERSION_MINOR 6 -#define HTTP_PARSER_VERSION_PATCH 1 +#define HTTP_PARSER_VERSION_MINOR 7 +#define HTTP_PARSER_VERSION_PATCH 0 #include #if defined(_WIN32) && !defined(__MINGW32__) && \ @@ -77,6 +77,11 @@ typedef struct http_parser_settings http_parser_settings; * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding: * chunked' headers that indicate the presence of a body. * + * Returning `2` from on_headers_complete will tell parser that it should not + * expect neither a body nor any futher responses on this connection. This is + * useful for handling responses to a CONNECT request which may not contain + * `Upgrade` or `Connection: upgrade` headers. + * * http_data_cb does not return data chunks. It will be called arbitrarily * many times for each string. E.G. you might get 10 callbacks for "on_url" * each providing just a few characters more data. diff --git a/zerotierone/ext/installfiles/mac/ZeroTier One.pkgproj b/zerotierone/ext/installfiles/mac/ZeroTier One.pkgproj index c917d82..d973052 100755 --- a/zerotierone/ext/installfiles/mac/ZeroTier One.pkgproj +++ b/zerotierone/ext/installfiles/mac/ZeroTier One.pkgproj @@ -37,7 +37,7 @@ GID 80 PATH - ../../mac-ui-macgap1-wrapper/bin/ZeroTier One.app + mac-ui-macgap1-wrapper/bin/ZeroTier One.app PATH_TYPE 1 PERMISSIONS @@ -130,7 +130,7 @@ GID 0 PATH - ../../../ui/index.html + ui/index.html PATH_TYPE 1 PERMISSIONS @@ -146,7 +146,7 @@ GID 0 PATH - ../../../ui/main.js + ui/main.js PATH_TYPE 1 PERMISSIONS @@ -162,7 +162,7 @@ GID 0 PATH - ../../../ui/react.min.js + ui/react.min.js PATH_TYPE 1 PERMISSIONS @@ -178,7 +178,7 @@ GID 0 PATH - ../../../ui/simpleajax.min.js + ui/simpleajax.min.js PATH_TYPE 1 PERMISSIONS @@ -194,7 +194,7 @@ GID 0 PATH - ../../../ui/zerotier.css + ui/zerotier.css PATH_TYPE 1 PERMISSIONS @@ -210,7 +210,7 @@ GID 0 PATH - ../../../ui/ztui.min.js + ui/ztui.min.js PATH_TYPE 1 PERMISSIONS @@ -759,7 +759,7 @@ OVERWRITE_PERMISSIONS VERSION - 1.0.3 + 1.1.14 PROJECT_COMMENTS @@ -773,26 +773,27 @@ ZW50LVN0eWxlLVR5cGUiIGNvbnRlbnQ9InRleHQvY3NzIj4KPHRp dGxlPjwvdGl0bGU+CjxtZXRhIG5hbWU9IkdlbmVyYXRvciIgY29u dGVudD0iQ29jb2EgSFRNTCBXcml0ZXIiPgo8bWV0YSBuYW1lPSJD - b2NvYVZlcnNpb24iIGNvbnRlbnQ9IjEzNDcuNTciPgo8c3R5bGUg + b2NvYVZlcnNpb24iIGNvbnRlbnQ9IjE0MDQuNDciPgo8c3R5bGUg dHlwZT0idGV4dC9jc3MiPgpwLnAxIHttYXJnaW46IDAuMHB4IDAu - MHB4IDAuMHB4IDAuMHB4OyBmb250OiAxMi4wcHggSGVsdmV0aWNh - OyBjb2xvcjogIzAwMDAwMDsgLXdlYmtpdC10ZXh0LXN0cm9rZTog - IzAwMDAwMH0Kc3Bhbi5zMSB7Zm9udC1rZXJuaW5nOiBub25lfQo8 - L3N0eWxlPgo8L2hlYWQ+Cjxib2R5Pgo8cCBjbGFzcz0icDEiPjxz - cGFuIGNsYXNzPSJzMSI+WmVyb1RpZXIgT25lIC0gTmV0d29yayBW - aXJ0dWFsaXphdGlvbiBFdmVyeXdoZXJlPC9zcGFuPjwvcD4KPHAg - Y2xhc3M9InAxIj48c3BhbiBjbGFzcz0iczEiPihjKTIwMTEtMjAx - NSBaZXJvVGllciwgSW5jLjwvc3Bhbj48L3A+CjxwIGNsYXNzPSJw - MSI+PHNwYW4gY2xhc3M9InMxIj5jb250YWN0QHplcm90aWVyLmNv - bTwvc3Bhbj48L3A+CjxwIGNsYXNzPSJwMSI+PHNwYW4gY2xhc3M9 - InMxIj48YnI+Cjwvc3Bhbj48L3A+CjxwIGNsYXNzPSJwMSI+PHNw - YW4gY2xhc3M9InMxIj5UbyB1bmluc3RhbGwgbWFudWFsbHksIHR5 - cGUgdGhlIGZvbGxvd2luZyBpbiBhIHRlcm1pbmFsIHdpbmRvdzo8 - L3NwYW4+PC9wPgo8cCBjbGFzcz0icDEiPjxzcGFuIGNsYXNzPSJz - MSI+PGJyPgo8L3NwYW4+PC9wPgo8cCBjbGFzcz0icDEiPjxzcGFu - IGNsYXNzPSJzMSI+c3VkbyAiL0xpYnJhcnkvQXBwbGljYXRpb24g - U3VwcG9ydC9aZXJvVGllci9PbmUvdW5pbnN0YWxsLnNoIjwvc3Bh - bj48L3A+CjwvYm9keT4KPC9odG1sPgo= + MHB4IDAuMHB4IDAuMHB4OyBsaW5lLWhlaWdodDogMTQuMHB4OyBm + b250OiAxMi4wcHggSGVsdmV0aWNhOyBjb2xvcjogIzAwMDAwMDsg + LXdlYmtpdC10ZXh0LXN0cm9rZTogIzAwMDAwMH0Kc3Bhbi5zMSB7 + Zm9udC1rZXJuaW5nOiBub25lfQo8L3N0eWxlPgo8L2hlYWQ+Cjxi + b2R5Pgo8cCBjbGFzcz0icDEiPjxzcGFuIGNsYXNzPSJzMSI+WmVy + b1RpZXIgT25lIC0gTmV0d29yayBWaXJ0dWFsaXphdGlvbiBFdmVy + eXdoZXJlPC9zcGFuPjwvcD4KPHAgY2xhc3M9InAxIj48c3BhbiBj + bGFzcz0iczEiPihjKTIwMTEtMjAxNiBaZXJvVGllciwgSW5jLjwv + c3Bhbj48L3A+CjxwIGNsYXNzPSJwMSI+PHNwYW4gY2xhc3M9InMx + Ij5jb250YWN0QHplcm90aWVyLmNvbTwvc3Bhbj48L3A+CjxwIGNs + YXNzPSJwMSI+PHNwYW4gY2xhc3M9InMxIj48YnI+Cjwvc3Bhbj48 + L3A+CjxwIGNsYXNzPSJwMSI+PHNwYW4gY2xhc3M9InMxIj5UbyB1 + bmluc3RhbGwgbWFudWFsbHksIHR5cGUgdGhlIGZvbGxvd2luZyBp + biBhIHRlcm1pbmFsIHdpbmRvdzo8L3NwYW4+PC9wPgo8cCBjbGFz + cz0icDEiPjxzcGFuIGNsYXNzPSJzMSI+PGJyPgo8L3NwYW4+PC9w + Pgo8cCBjbGFzcz0icDEiPjxzcGFuIGNsYXNzPSJzMSI+c3VkbyAi + L0xpYnJhcnkvQXBwbGljYXRpb24gU3VwcG9ydC9aZXJvVGllci9P + bmUvdW5pbnN0YWxsLnNoIjwvc3Bhbj48L3A+CjwvYm9keT4KPC9o + dG1sPgo= PROJECT_SETTINGS diff --git a/zerotierone/ext/installfiles/windows/ZeroTier One.aip b/zerotierone/ext/installfiles/windows/ZeroTier One.aip index d8a99c3..fdbbeea 100644 --- a/zerotierone/ext/installfiles/windows/ZeroTier One.aip +++ b/zerotierone/ext/installfiles/windows/ZeroTier One.aip @@ -1,7 +1,7 @@ - + @@ -26,10 +26,10 @@ - + - + @@ -54,17 +54,15 @@ - - + - @@ -73,26 +71,20 @@ - + - - - - - - + - @@ -114,7 +106,7 @@ - + @@ -138,6 +130,10 @@ + + + + @@ -150,6 +146,7 @@ + @@ -212,6 +209,8 @@ + + @@ -221,6 +220,12 @@ + + + + + + @@ -236,6 +241,9 @@ + + + @@ -246,8 +254,8 @@ - - + + @@ -261,6 +269,9 @@ + + + @@ -331,6 +342,13 @@ + + + + + + + @@ -338,7 +356,7 @@ - + diff --git a/zerotierone/ext/libnatpmp/getgateway.c b/zerotierone/ext/libnatpmp/getgateway.c index dfb9f3e..f743a08 100644 --- a/zerotierone/ext/libnatpmp/getgateway.c +++ b/zerotierone/ext/libnatpmp/getgateway.c @@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #undef USE_PROC_NET_ROUTE #define USE_SOCKET_ROUTE #undef USE_SYSCTL_NET_ROUTE +#include #endif #ifdef __APPLE__ @@ -96,7 +97,6 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef USE_SYSCTL_NET_ROUTE #include -#include #include #include #endif diff --git a/zerotierone/ext/miniupnpc/Changelog.txt b/zerotierone/ext/miniupnpc/Changelog.txt index bef61f5..078bebc 100644 --- a/zerotierone/ext/miniupnpc/Changelog.txt +++ b/zerotierone/ext/miniupnpc/Changelog.txt @@ -1,6 +1,16 @@ -$Id: Changelog.txt,v 1.219 2015/10/26 17:05:06 nanard Exp $ +$Id: Changelog.txt,v 1.223 2016/04/19 21:06:20 nanard Exp $ miniUPnP client Changelog. +VERSION 2.0 : released 2016/04/19 + +2016/01/24: + change miniwget to return HTTP status code + increments API_VERSION to 16 + +2016/01/22: + Improve UPNPIGD_IsConnected() to check if WAN address is not private. + parse HTTP response status line in miniwget.c + 2015/10/26: snprintf() overflow check. check overflow in simpleUPnPcommand2() diff --git a/zerotierone/ext/miniupnpc/README b/zerotierone/ext/miniupnpc/README index ab08de9..91535db 100644 --- a/zerotierone/ext/miniupnpc/README +++ b/zerotierone/ext/miniupnpc/README @@ -3,7 +3,7 @@ Project web page: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ github: https://github.com/miniupnp/miniupnp freecode: http://freecode.com/projects/miniupnp Author: Thomas Bernard -Copyright (c) 2005-2014 Thomas Bernard +Copyright (c) 2005-2016 Thomas Bernard This software is subject to the conditions detailed in the LICENSE file provided within this distribution. @@ -32,6 +32,7 @@ To use the libminiupnpc in your application, link it with libminiupnpc.a (or .so) and use the following functions found in miniupnpc.h, upnpcommands.h and miniwget.h : - upnpDiscover() +- UPNP_GetValidIGD() - miniwget() - parserootdesc() - GetUPNPUrls() @@ -59,3 +60,5 @@ send me an email ! For any question, you can use the web forum : http://miniupnp.tuxfamily.org/forum/ +Bugs should be reported on github : +https://github.com/miniupnp/miniupnp/issues diff --git a/zerotierone/ext/miniupnpc/VERSION b/zerotierone/ext/miniupnpc/VERSION index 2e0e38c..cd5ac03 100644 --- a/zerotierone/ext/miniupnpc/VERSION +++ b/zerotierone/ext/miniupnpc/VERSION @@ -1 +1 @@ -1.9 +2.0 diff --git a/zerotierone/ext/miniupnpc/apiversions.txt b/zerotierone/ext/miniupnpc/apiversions.txt index 3e9ebef..9464a86 100644 --- a/zerotierone/ext/miniupnpc/apiversions.txt +++ b/zerotierone/ext/miniupnpc/apiversions.txt @@ -1,7 +1,12 @@ -$Id: apiversions.txt,v 1.8 2015/10/08 16:15:47 nanard Exp $ +$Id: apiversions.txt,v 1.9 2016/01/24 17:24:36 nanard Exp $ Differences in API between miniUPnPc versions +API version 16 + added "status_code" argument to getHTTPResponse(), miniwget() and miniwget_getaddr() + updated macro : + #define MINIUPNPC_API_VERSION 16 + API version 15 changed "sameport" argument of upnpDiscover() upnpDiscoverAll() upnpDiscoverDevice() to "localport". When 0 or 1, behaviour is not changed, but it can take diff --git a/zerotierone/ext/miniupnpc/minihttptestserver.c b/zerotierone/ext/miniupnpc/minihttptestserver.c index 32e3cb7..6663bc0 100644 --- a/zerotierone/ext/miniupnpc/minihttptestserver.c +++ b/zerotierone/ext/miniupnpc/minihttptestserver.c @@ -1,4 +1,4 @@ -/* $Id: minihttptestserver.c,v 1.18 2015/07/15 12:41:15 nanard Exp $ */ +/* $Id: minihttptestserver.c,v 1.19 2015/11/17 09:07:17 nanard Exp $ */ /* Project : miniUPnP * Author : Thomas Bernard * Copyright (c) 2011-2015 Thomas Bernard @@ -18,6 +18,10 @@ #include #include +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK 0x7f000001 +#endif + #define CRAP_LENGTH (2048) volatile sig_atomic_t quit = 0; diff --git a/zerotierone/ext/miniupnpc/minisoap.c b/zerotierone/ext/miniupnpc/minisoap.c index c685aac..e2efd8f 100644 --- a/zerotierone/ext/miniupnpc/minisoap.c +++ b/zerotierone/ext/miniupnpc/minisoap.c @@ -22,7 +22,7 @@ #include "minisoap.h" #ifdef _WIN32 #define OS_STRING "Win32" -#define MINIUPNPC_VERSION_STRING "1.9" +#define MINIUPNPC_VERSION_STRING "2.0" #define UPNP_VERSION_STRING "UPnP/1.1" #endif diff --git a/zerotierone/ext/miniupnpc/minissdpc.c b/zerotierone/ext/miniupnpc/minissdpc.c index a371d16..0f7271e 100644 --- a/zerotierone/ext/miniupnpc/minissdpc.c +++ b/zerotierone/ext/miniupnpc/minissdpc.c @@ -1,7 +1,8 @@ #define _CRT_SECURE_NO_WARNINGS -/* $Id: minissdpc.c,v 1.30 2015/10/26 17:05:07 nanard Exp $ */ -/* Project : miniupnp +/* $Id: minissdpc.c,v 1.31 2016/01/19 09:56:46 nanard Exp $ */ +/* vim: tabstop=4 shiftwidth=4 noexpandtab + * Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD * copyright (c) 2005-2015 Thomas Bernard @@ -69,6 +70,10 @@ struct sockaddr_un { #define HAS_IP_MREQN #endif +#if !defined(HAS_IP_MREQN) && !defined(_WIN32) +#include +#endif + #if defined(HAS_IP_MREQN) && defined(NEED_STRUCT_IP_MREQN) /* Several versions of glibc don't define this structure, * define it here and compile with CFLAGS NEED_STRUCT_IP_MREQN */ @@ -649,11 +654,25 @@ ssdpDiscoverDevices(const char * const deviceTypes[], { PRINT_SOCKET_ERROR("setsockopt"); } -#else +#elif !defined(_WIN32) + struct ifreq ifr; + int ifrlen = sizeof(ifr); + strncpy(ifr.ifr_name, multicastif, IFNAMSIZ); + ifr.ifr_name[IFNAMSIZ-1] = '\0'; + if(ioctl(sudp, SIOCGIFADDR, &ifr, &ifrlen) < 0) + { + PRINT_SOCKET_ERROR("ioctl(...SIOCGIFADDR...)"); + } + mc_if.s_addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; + if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } +#else /* _WIN32 */ #ifdef DEBUG printf("Setting of multicast interface not supported with interface name.\n"); #endif -#endif +#endif /* #ifdef HAS_IP_MREQN / !defined(_WIN32) */ } } } diff --git a/zerotierone/ext/miniupnpc/miniupnpc.c b/zerotierone/ext/miniupnpc/miniupnpc.c index 5663888..68d562f 100644 --- a/zerotierone/ext/miniupnpc/miniupnpc.c +++ b/zerotierone/ext/miniupnpc/miniupnpc.c @@ -1,10 +1,11 @@ #define _CRT_SECURE_NO_WARNINGS -/* $Id: miniupnpc.c,v 1.141 2015/10/26 17:05:07 nanard Exp $ */ -/* vim: tabstop=4 shiftwidth=4 noexpandtab */ -/* Project : miniupnp + +/* $Id: miniupnpc.c,v 1.149 2016/02/09 09:50:46 nanard Exp $ */ +/* vim: tabstop=4 shiftwidth=4 noexpandtab + * Project : miniupnp * Web : http://miniupnp.free.fr/ * Author : Thomas BERNARD - * copyright (c) 2005-2015 Thomas Bernard + * copyright (c) 2005-2016 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENSE file. */ #include @@ -73,6 +74,25 @@ #define SERVICEPREFIX "u" #define SERVICEPREFIX2 'u' +/* check if an ip address is a private (LAN) address + * see https://tools.ietf.org/html/rfc1918 */ +static int is_rfc1918addr(const char * addr) +{ + /* 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) */ + if(COMPARE(addr, "192.168.")) + return 1; + /* 10.0.0.0 - 10.255.255.255 (10/8 prefix) */ + if(COMPARE(addr, "10.")) + return 1; + /* 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) */ + if(COMPARE(addr, "172.")) { + int i = atoi(addr + 4); + if((16 <= i) && (i <= 31)) + return 1; + } + return 0; +} + /* root description parsing */ MINIUPNP_LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data) { @@ -108,6 +128,7 @@ char * simpleUPnPcommand2(int s, const char * url, const char * service, int soapbodylen; char * buf; int n; + int status_code; *bufsize = 0; snprintf(soapact, sizeof(soapact), "%s#%s", service, action); @@ -211,11 +232,15 @@ char * simpleUPnPcommand2(int s, const char * url, const char * service, return NULL; } - buf = getHTTPResponse(s, bufsize); + buf = getHTTPResponse(s, bufsize, &status_code); #ifdef DEBUG if(*bufsize > 0 && buf) { - printf("SOAP Response :\n%.*s\n", *bufsize, buf); + printf("HTTP %d SOAP Response :\n%.*s\n", status_code, *bufsize, buf); + } + else + { + printf("HTTP %d, empty SOAP response. size=%d\n", status_code, *bufsize); } #endif closesocket(s); @@ -527,7 +552,7 @@ UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) * 3 = an UPnP device has been found but was not recognized as an IGD * * In any positive non zero return case, the urls and data structures - * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to + * passed as parameters are set. Dont forget to call FreeUPNPUrls(urls) to * free allocated memory. */ MINIUPNP_LIBSPEC int @@ -547,6 +572,9 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, int state = -1; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */ int n_igd = 0; char extIpAddr[16]; + char myLanAddr[40]; + int status_code = -1; + if(!devlist) { #ifdef DEBUG @@ -569,8 +597,8 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, /* we should choose an internet gateway device. * with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */ desc[i].xml = miniwget_getaddr(dev->descURL, &(desc[i].size), - lanaddr, lanaddrlen, - dev->scope_id); + myLanAddr, sizeof(myLanAddr), + dev->scope_id, &status_code); #ifdef DEBUG if(!desc[i].xml) { @@ -587,6 +615,8 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, { desc[i].is_igd = 1; n_igd++; + if(lanaddr) + strncpy(lanaddr, myLanAddr, lanaddrlen); } } } @@ -602,20 +632,25 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, parserootdesc(desc[i].xml, desc[i].size, data); if(desc[i].is_igd || state >= 3 ) { + int is_connected; + GetUPNPUrls(urls, data, dev->descURL, dev->scope_id); /* in state 2 and 3 we dont test if device is connected ! */ if(state >= 2) goto free_and_return; + is_connected = UPNPIGD_IsConnected(urls, data); #ifdef DEBUG printf("UPNPIGD_IsConnected(%s) = %d\n", - urls->controlURL, - UPNPIGD_IsConnected(urls, data)); + urls->controlURL, is_connected); #endif /* checks that status is connected AND there is a external IP address assigned */ - if(UPNPIGD_IsConnected(urls, data) - && (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) - goto free_and_return; + if(is_connected && + (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) { + if(!is_rfc1918addr(extIpAddr) && (extIpAddr[0] != '\0') + && (0 != strcmp(extIpAddr, "0.0.0.0"))) + goto free_and_return; + } FreeUPNPUrls(urls); if(data->second.servicetype[0] != '\0') { #ifdef DEBUG @@ -627,14 +662,17 @@ UPNP_GetValidIGD(struct UPNPDev * devlist, memcpy(&data->first, &data->second, sizeof(struct IGDdatas_service)); memcpy(&data->second, &data->tmp, sizeof(struct IGDdatas_service)); GetUPNPUrls(urls, data, dev->descURL, dev->scope_id); + is_connected = UPNPIGD_IsConnected(urls, data); #ifdef DEBUG printf("UPNPIGD_IsConnected(%s) = %d\n", - urls->controlURL, - UPNPIGD_IsConnected(urls, data)); + urls->controlURL, is_connected); #endif - if(UPNPIGD_IsConnected(urls, data) - && (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) - goto free_and_return; + if(is_connected && + (UPNP_GetExternalIPAddress(urls->controlURL, data->first.servicetype, extIpAddr) == 0)) { + if(!is_rfc1918addr(extIpAddr) && (extIpAddr[0] != '\0') + && (0 != strcmp(extIpAddr, "0.0.0.0"))) + goto free_and_return; + } FreeUPNPUrls(urls); } } @@ -668,8 +706,9 @@ UPNP_GetIGDFromUrl(const char * rootdescurl, { char * descXML; int descXMLsize = 0; + descXML = miniwget_getaddr(rootdescurl, &descXMLsize, - lanaddr, lanaddrlen, 0); + lanaddr, lanaddrlen, 0, NULL); if(descXML) { memset(data, 0, sizeof(struct IGDdatas)); memset(urls, 0, sizeof(struct UPNPUrls)); diff --git a/zerotierone/ext/miniupnpc/miniupnpc.h b/zerotierone/ext/miniupnpc/miniupnpc.h index dfbfa01..0b5b473 100644 --- a/zerotierone/ext/miniupnpc/miniupnpc.h +++ b/zerotierone/ext/miniupnpc/miniupnpc.h @@ -1,8 +1,8 @@ -/* $Id: miniupnpc.h,v 1.48 2015/10/08 16:19:40 nanard Exp $ */ +/* $Id: miniupnpc.h,v 1.50 2016/04/19 21:06:21 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ * Author: Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subjects to the conditions detailed * in the LICENCE file provided within this distribution */ #ifndef MINIUPNPC_H_INCLUDED @@ -19,8 +19,8 @@ #define UPNPDISCOVER_MEMORY_ERROR (-102) /* versions : */ -#define MINIUPNPC_VERSION "1.9.20151026" -#define MINIUPNPC_API_VERSION 15 +#define MINIUPNPC_VERSION "2.0" +#define MINIUPNPC_API_VERSION 16 /* Source port: Using "1" as an alias for 1900 for backwards compatability diff --git a/zerotierone/ext/miniupnpc/miniwget.c b/zerotierone/ext/miniupnpc/miniwget.c index 4b11ea9..1af106d 100644 --- a/zerotierone/ext/miniupnpc/miniwget.c +++ b/zerotierone/ext/miniupnpc/miniwget.c @@ -1,9 +1,10 @@ #define _CRT_SECURE_NO_WARNINGS -/* $Id: miniwget.c,v 1.72 2015/10/26 17:05:08 nanard Exp $ */ + +/* $Id: miniwget.c,v 1.75 2016/01/24 17:24:36 nanard Exp $ */ /* Project : miniupnp * Website : http://miniupnp.free.fr/ * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -49,12 +50,12 @@ #define MIN(x,y) (((x)<(y))?(x):(y)) #endif /* MIN */ - #ifdef _WIN32 #define OS_STRING "Win32" -#define MINIUPNPC_VERSION_STRING "1.9" +#define MINIUPNPC_VERSION_STRING "2.0" #define UPNP_VERSION_STRING "UPnP/1.1" #endif + #include "miniwget.h" #include "connecthostport.h" #include "receivedata.h" @@ -70,7 +71,7 @@ * to the length parameter. */ void * -getHTTPResponse(int s, int * size) +getHTTPResponse(int s, int * size, int * status_code) { char buf[2048]; int n; @@ -88,7 +89,10 @@ getHTTPResponse(int s, int * size) unsigned int content_buf_used = 0; char chunksize_buf[32]; unsigned int chunksize_buf_index; + char * reason_phrase = NULL; + int reason_phrase_len = 0; + if(status_code) *status_code = -1; header_buf = malloc(header_buf_len); if(header_buf == NULL) { @@ -160,7 +164,7 @@ getHTTPResponse(int s, int * size) continue; /* parse header lines */ for(i = 0; i < endofheaders - 1; i++) { - if(colon <= linestart && header_buf[i]==':') + if(linestart > 0 && colon <= linestart && header_buf[i]==':') { colon = i; while(i < (endofheaders-1) @@ -171,7 +175,29 @@ getHTTPResponse(int s, int * size) /* detecting end of line */ else if(header_buf[i]=='\r' || header_buf[i]=='\n') { - if(colon > linestart && valuestart > colon) + if(linestart == 0 && status_code) + { + /* Status line + * HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ + int sp; + for(sp = 0; sp < i; sp++) + if(header_buf[sp] == ' ') + { + if(*status_code < 0) + *status_code = atoi(header_buf + sp + 1); + else + { + reason_phrase = header_buf + sp + 1; + reason_phrase_len = i - sp - 1; + break; + } + } +#ifdef DEBUG + printf("HTTP status code = %d, Reason phrase = %.*s\n", + *status_code, reason_phrase_len, reason_phrase); +#endif + } + else if(colon > linestart && valuestart > colon) { #ifdef DEBUG printf("header='%.*s', value='%.*s'\n", @@ -342,7 +368,8 @@ static void * miniwget3(const char * host, unsigned short port, const char * path, int * size, char * addr_str, int addr_str_len, - const char * httpversion, unsigned int scope_id) + const char * httpversion, unsigned int scope_id, + int * status_code) { char buf[2048]; int s; @@ -440,7 +467,7 @@ miniwget3(const char * host, sent += n; } } - content = getHTTPResponse(s, size); + content = getHTTPResponse(s, size, status_code); closesocket(s); return content; } @@ -449,18 +476,20 @@ miniwget3(const char * host, * Call miniwget3(); retry with HTTP/1.1 if 1.0 fails. */ static void * miniwget2(const char * host, - unsigned short port, const char * path, - int * size, char * addr_str, int addr_str_len, - unsigned int scope_id) + unsigned short port, const char * path, + int * size, char * addr_str, int addr_str_len, + unsigned int scope_id, int * status_code) { char * respbuffer; #if 1 respbuffer = miniwget3(host, port, path, size, - addr_str, addr_str_len, "1.1", scope_id); + addr_str, addr_str_len, "1.1", + scope_id, status_code); #else respbuffer = miniwget3(host, port, path, size, - addr_str, addr_str_len, "1.0", scope_id); + addr_str, addr_str_len, "1.0", + scope_id, status_code); if (*size == 0) { #ifdef DEBUG @@ -468,7 +497,8 @@ miniwget2(const char * host, #endif free(respbuffer); respbuffer = miniwget3(host, port, path, size, - addr_str, addr_str_len, "1.1", scope_id); + addr_str, addr_str_len, "1.1", + scope_id, status_code); } #endif return respbuffer; @@ -593,7 +623,8 @@ parseURL(const char * url, } void * -miniwget(const char * url, int * size, unsigned int scope_id) +miniwget(const char * url, int * size, + unsigned int scope_id, int * status_code) { unsigned short port; char * path; @@ -606,12 +637,13 @@ miniwget(const char * url, int * size, unsigned int scope_id) printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n", hostname, port, path, scope_id); #endif - return miniwget2(hostname, port, path, size, 0, 0, scope_id); + return miniwget2(hostname, port, path, size, 0, 0, scope_id, status_code); } void * miniwget_getaddr(const char * url, int * size, - char * addr, int addrlen, unsigned int scope_id) + char * addr, int addrlen, unsigned int scope_id, + int * status_code) { unsigned short port; char * path; @@ -626,5 +658,6 @@ miniwget_getaddr(const char * url, int * size, printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n", hostname, port, path, scope_id); #endif - return miniwget2(hostname, port, path, size, addr, addrlen, scope_id); + return miniwget2(hostname, port, path, size, addr, addrlen, scope_id, status_code); } + diff --git a/zerotierone/ext/miniupnpc/miniwget.h b/zerotierone/ext/miniupnpc/miniwget.h index d6db71a..0701494 100644 --- a/zerotierone/ext/miniupnpc/miniwget.h +++ b/zerotierone/ext/miniupnpc/miniwget.h @@ -1,7 +1,7 @@ -/* $Id: miniwget.h,v 1.10 2015/07/21 13:16:55 nanard Exp $ */ +/* $Id: miniwget.h,v 1.12 2016/01/24 17:24:36 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -14,11 +14,11 @@ extern "C" { #endif -MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size); +MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size, int * status_code); -MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int); +MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int, int *); -MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int); +MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int, int *); int parseURL(const char *, char *, unsigned short *, char * *, unsigned int *); diff --git a/zerotierone/ext/miniupnpc/receivedata.c b/zerotierone/ext/miniupnpc/receivedata.c index fb05e09..ef85a3d 100644 --- a/zerotierone/ext/miniupnpc/receivedata.c +++ b/zerotierone/ext/miniupnpc/receivedata.c @@ -1,4 +1,4 @@ -/* $Id: receivedata.c,v 1.6 2014/11/13 13:51:52 nanard Exp $ */ +/* $Id: receivedata.c,v 1.7 2015/11/09 21:51:41 nanard Exp $ */ /* Project : miniupnp * Website : http://miniupnp.free.fr/ * Author : Thomas Bernard @@ -40,7 +40,7 @@ receivedata(int socket, char * data, int length, int timeout, unsigned int * scope_id) { -#if MINIUPNPC_GET_SRC_ADDR +#ifdef MINIUPNPC_GET_SRC_ADDR struct sockaddr_storage src_addr; socklen_t src_addr_len = sizeof(src_addr); #endif /* MINIUPNPC_GET_SRC_ADDR */ @@ -80,7 +80,7 @@ receivedata(int socket, return 0; } #endif /* !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */ -#if MINIUPNPC_GET_SRC_ADDR +#ifdef MINIUPNPC_GET_SRC_ADDR memset(&src_addr, 0, sizeof(src_addr)); n = recvfrom(socket, data, length, 0, (struct sockaddr *)&src_addr, &src_addr_len); @@ -90,7 +90,7 @@ receivedata(int socket, if(n<0) { PRINT_SOCKET_ERROR("recv"); } -#if MINIUPNPC_GET_SRC_ADDR +#ifdef MINIUPNPC_GET_SRC_ADDR if (src_addr.ss_family == AF_INET6) { const struct sockaddr_in6 * src_addr6 = (struct sockaddr_in6 *)&src_addr; #ifdef DEBUG diff --git a/zerotierone/ext/miniupnpc/testminiwget.c b/zerotierone/ext/miniupnpc/testminiwget.c index 8ae9032..5eb49ec 100644 --- a/zerotierone/ext/miniupnpc/testminiwget.c +++ b/zerotierone/ext/miniupnpc/testminiwget.c @@ -1,7 +1,7 @@ -/* $Id: testminiwget.c,v 1.4 2012/06/23 22:35:59 nanard Exp $ */ +/* $Id: testminiwget.c,v 1.5 2016/01/24 17:24:36 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2012 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -20,15 +20,17 @@ int main(int argc, char * * argv) int size, writtensize; FILE *f; char addr[64]; + int status_code = -1; if(argc < 3) { fprintf(stderr, "Usage:\t%s url file\n", argv[0]); fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]); return 1; } - data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0); - if(!data) { - fprintf(stderr, "Error fetching %s\n", argv[1]); + data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0, &status_code); + if(!data || (status_code != 200)) { + if(data) free(data); + fprintf(stderr, "Error %d fetching %s\n", status_code, argv[1]); return 1; } printf("local address : %s\n", addr); diff --git a/zerotierone/ext/miniupnpc/upnpc.c b/zerotierone/ext/miniupnpc/upnpc.c index 8bc552e..94f131c 100644 --- a/zerotierone/ext/miniupnpc/upnpc.c +++ b/zerotierone/ext/miniupnpc/upnpc.c @@ -1,7 +1,7 @@ -/* $Id: upnpc.c,v 1.112 2015/10/08 16:15:48 nanard Exp $ */ +/* $Id: upnpc.c,v 1.114 2016/01/22 15:04:23 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005-2015 Thomas Bernard + * Copyright (c) 2005-2016 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. */ @@ -66,7 +66,7 @@ static void DisplayInfos(struct UPNPUrls * urls, char connectionType[64]; char status[64]; char lastconnerr[64]; - unsigned int uptime; + unsigned int uptime = 0; unsigned int brUp, brDown; time_t timenow, timestarted; int r; @@ -82,9 +82,11 @@ static void DisplayInfos(struct UPNPUrls * urls, else printf("Status : %s, uptime=%us, LastConnectionError : %s\n", status, uptime, lastconnerr); - timenow = time(NULL); - timestarted = timenow - uptime; - printf(" Time started : %s", ctime(×tarted)); + if(uptime > 0) { + timenow = time(NULL); + timestarted = timenow - uptime; + printf(" Time started : %s", ctime(×tarted)); + } if(UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, data->CIF.servicetype, &brDown, &brUp) != UPNPCOMMAND_SUCCESS) { printf("GetLinkLayerMaxBitRates failed.\n"); @@ -538,7 +540,7 @@ int main(int argc, char ** argv) char ** commandargv = 0; int commandargc = 0; struct UPNPDev * devlist = 0; - char lanaddr[64]; /* my ip address on the LAN */ + char lanaddr[64] = "unset"; /* my ip address on the LAN */ int i; const char * rootdescurl = 0; const char * multicastif = 0; @@ -560,7 +562,7 @@ int main(int argc, char ** argv) } #endif printf("upnpc : miniupnpc library test client, version %s.\n", MINIUPNPC_VERSION_STRING); - printf(" (c) 2005-2015 Thomas Bernard.\n"); + printf(" (c) 2005-2016 Thomas Bernard.\n"); printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n" "for more information.\n"); /* command line processing */ diff --git a/zerotierone/ext/miniupnpc/upnpcommands.c b/zerotierone/ext/miniupnpc/upnpcommands.c index 660b5d9..2b65651 100644 --- a/zerotierone/ext/miniupnpc/upnpcommands.c +++ b/zerotierone/ext/miniupnpc/upnpcommands.c @@ -1,5 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS -/* $Id: upnpcommands.c,v 1.46 2015/07/15 12:19:00 nanard Exp $ */ + +/* $Id: upnpcommands.c,v 1.47 2016/03/07 12:26:48 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2005-2015 Thomas Bernard @@ -617,14 +618,14 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL, protocol[3] = '\0'; } p = GetValueFromNameValueList(&pdata, "NewInternalClient"); - if(p && intClient) + if(p) { strncpy(intClient, p, 16); intClient[15] = '\0'; r = 0; } p = GetValueFromNameValueList(&pdata, "NewInternalPort"); - if(p && intPort) + if(p) { strncpy(intPort, p, 6); intPort[5] = '\0'; diff --git a/zerotierone/one.cpp b/zerotierone/one.cpp index 9e03daa..04716e8 100644 --- a/zerotierone/one.cpp +++ b/zerotierone/one.cpp @@ -91,21 +91,21 @@ static void cliPrintHelp(const char *pn,FILE *out) fprintf(out, COPYRIGHT_NOTICE ZT_EOL_S LICENSE_GRANT ZT_EOL_S); - fprintf(out,"Usage: %s [-switches] []"ZT_EOL_S""ZT_EOL_S,pn); - fprintf(out,"Available switches:"ZT_EOL_S); - fprintf(out," -h - Display this help"ZT_EOL_S); - fprintf(out," -v - Show version"ZT_EOL_S); - fprintf(out," -j - Display full raw JSON output"ZT_EOL_S); - fprintf(out," -D - ZeroTier home path for parameter auto-detect"ZT_EOL_S); - fprintf(out," -p - HTTP port (default: auto)"ZT_EOL_S); - fprintf(out," -T - Authentication token (default: auto)"ZT_EOL_S); - //fprintf(out," -H - HTTP server bind address (default: 127.0.0.1)"ZT_EOL_S); - fprintf(out,ZT_EOL_S"Available commands:"ZT_EOL_S); - fprintf(out," info - Display status info"ZT_EOL_S); - fprintf(out," listpeers - List all peers"ZT_EOL_S); - fprintf(out," listnetworks - List all networks"ZT_EOL_S); - fprintf(out," join - Join a network"ZT_EOL_S); - fprintf(out," leave - Leave a network"ZT_EOL_S); + fprintf(out,"Usage: %s [-switches] []" ZT_EOL_S"" ZT_EOL_S,pn); + fprintf(out,"Available switches:" ZT_EOL_S); + fprintf(out," -h - Display this help" ZT_EOL_S); + fprintf(out," -v - Show version" ZT_EOL_S); + fprintf(out," -j - Display full raw JSON output" ZT_EOL_S); + fprintf(out," -D - ZeroTier home path for parameter auto-detect" ZT_EOL_S); + fprintf(out," -p - HTTP port (default: auto)" ZT_EOL_S); + fprintf(out," -T - Authentication token (default: auto)" ZT_EOL_S); + //fprintf(out," -H - HTTP server bind address (default: 127.0.0.1)" ZT_EOL_S); + fprintf(out,ZT_EOL_S"Available commands:" ZT_EOL_S); + fprintf(out," info - Display status info" ZT_EOL_S); + fprintf(out," listpeers - List all peers" ZT_EOL_S); + fprintf(out," listnetworks - List all networks" ZT_EOL_S); + fprintf(out," join - Join a network" ZT_EOL_S); + fprintf(out," leave - Leave a network" ZT_EOL_S); } static std::string cliFixJsonCRs(const std::string &s) @@ -191,7 +191,7 @@ static int cli(int argc,char **argv) cliPrintHelp(argv[0],stdout); return 1; } - printf("%d.%d.%d"ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); + printf("%d.%d.%d" ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); return 0; case 'h': @@ -211,7 +211,7 @@ static int cli(int argc,char **argv) if ((!port)||(!authToken.length())) { if (!homeDir.length()) { - fprintf(stderr,"%s: missing port or authentication token and no home directory specified to auto-detect"ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: missing port or authentication token and no home directory specified to auto-detect" ZT_EOL_S,argv[0]); return 2; } @@ -220,7 +220,7 @@ static int cli(int argc,char **argv) OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "zerotier-one.port").c_str(),portStr); port = Utils::strToUInt(portStr.c_str()); if ((port == 0)||(port > 0xffff)) { - fprintf(stderr,"%s: missing port and zerotier-one.port not found in %s"ZT_EOL_S,argv[0],homeDir.c_str()); + fprintf(stderr,"%s: missing port and zerotier-one.port not found in %s" ZT_EOL_S,argv[0],homeDir.c_str()); return 2; } } @@ -242,7 +242,7 @@ static int cli(int argc,char **argv) } #endif if (!authToken.length()) { - fprintf(stderr,"%s: missing authentication token and authtoken.secret not found (or readable) in %s"ZT_EOL_S,argv[0],homeDir.c_str()); + fprintf(stderr,"%s: missing authentication token and authtoken.secret not found (or readable) in %s" ZT_EOL_S,argv[0],homeDir.c_str()); return 2; } } @@ -274,7 +274,7 @@ static int cli(int argc,char **argv) printf("%s",cliFixJsonCRs(responseBody).c_str()); return 0; } else { - printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } } else if ((command == "info")||(command == "status")) { @@ -307,7 +307,7 @@ static int cli(int argc,char **argv) online = (j->u.object.values[k].value->u.boolean != 0); } if ((address)&&(version)) { - printf("200 info %s %s %s"ZT_EOL_S,address,(online ? "ONLINE" : "OFFLINE"),version); + printf("200 info %s %s %s" ZT_EOL_S,address,(online ? "ONLINE" : "OFFLINE"),version); good = true; } } @@ -316,12 +316,12 @@ static int cli(int argc,char **argv) if (good) { return 0; } else { - printf("%u %s invalid JSON response"ZT_EOL_S,scode,command.c_str()); + printf("%u %s invalid JSON response" ZT_EOL_S,scode,command.c_str()); return 1; } } } else { - printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } } else if (command == "listpeers") { @@ -338,7 +338,7 @@ static int cli(int argc,char **argv) printf("%s",cliFixJsonCRs(responseBody).c_str()); return 0; } else { - printf("200 listpeers "ZT_EOL_S); + printf("200 listpeers " ZT_EOL_S); json_value *j = json_parse(responseBody.c_str(),responseBody.length()); if (j) { if (j->type == json_array) { @@ -412,7 +412,7 @@ static int cli(int argc,char **argv) verstr[0] = '-'; verstr[1] = (char)0; } - printf("200 listpeers %s %s %lld %s %s"ZT_EOL_S,address,(paths.length()) ? paths.c_str() : "-",(long long)latency,verstr,role); + printf("200 listpeers %s %s %lld %s %s" ZT_EOL_S,address,(paths.length()) ? paths.c_str() : "-",(long long)latency,verstr,role); } } } @@ -422,7 +422,7 @@ static int cli(int argc,char **argv) return 0; } } else { - printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } } else if (command == "listnetworks") { @@ -439,7 +439,7 @@ static int cli(int argc,char **argv) printf("%s",cliFixJsonCRs(responseBody).c_str()); return 0; } else { - printf("200 listnetworks "ZT_EOL_S); + printf("200 listnetworks " ZT_EOL_S); json_value *j = json_parse(responseBody.c_str(),responseBody.length()); if (j) { if (j->type == json_array) { @@ -478,7 +478,7 @@ static int cli(int argc,char **argv) } } if ((nwid)&&(mac)&&(status)&&(type)) { - printf("200 listnetworks %s %s %s %s %s %s %s"ZT_EOL_S, + printf("200 listnetworks %s %s %s %s %s %s %s" ZT_EOL_S, nwid, (((name)&&(name[0])) ? name : "-"), mac, @@ -494,7 +494,7 @@ static int cli(int argc,char **argv) } } } else { - printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } } else if (command == "join") { @@ -518,11 +518,11 @@ static int cli(int argc,char **argv) if (json) { printf("%s",cliFixJsonCRs(responseBody).c_str()); } else { - printf("200 join OK"ZT_EOL_S); + printf("200 join OK" ZT_EOL_S); } return 0; } else { - printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } } else if (command == "leave") { @@ -542,11 +542,11 @@ static int cli(int argc,char **argv) if (json) { printf("%s",cliFixJsonCRs(responseBody).c_str()); } else { - printf("200 leave OK"ZT_EOL_S); + printf("200 leave OK" ZT_EOL_S); } return 0; } else { - printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } } else { @@ -570,13 +570,13 @@ static void idtoolPrintHelp(FILE *out,const char *pn) fprintf(out, COPYRIGHT_NOTICE ZT_EOL_S LICENSE_GRANT ZT_EOL_S); - fprintf(out,"Usage: %s []"ZT_EOL_S""ZT_EOL_S"Commands:"ZT_EOL_S,pn); - fprintf(out," generate [] [] []"ZT_EOL_S); - fprintf(out," validate "ZT_EOL_S); - fprintf(out," getpublic "ZT_EOL_S); - fprintf(out," sign "ZT_EOL_S); - fprintf(out," verify "ZT_EOL_S); - fprintf(out," mkcom [ ...] (hexadecimal integers)"ZT_EOL_S); + fprintf(out,"Usage: %s []" ZT_EOL_S"" ZT_EOL_S"Commands:" ZT_EOL_S,pn); + fprintf(out," generate [] [] []" ZT_EOL_S); + fprintf(out," validate " ZT_EOL_S); + fprintf(out," getpublic " ZT_EOL_S); + fprintf(out," sign " ZT_EOL_S); + fprintf(out," verify " ZT_EOL_S); + fprintf(out," mkcom [ ...] (hexadecimal integers)" ZT_EOL_S); } static Identity getIdFromArg(char *arg) @@ -632,15 +632,15 @@ static int idtool(int argc,char **argv) std::string idser = id.toString(true); if (argc >= 3) { if (!OSUtils::writeFile(argv[2],idser)) { - fprintf(stderr,"Error writing to %s"ZT_EOL_S,argv[2]); + fprintf(stderr,"Error writing to %s" ZT_EOL_S,argv[2]); return 1; - } else printf("%s written"ZT_EOL_S,argv[2]); + } else printf("%s written" ZT_EOL_S,argv[2]); if (argc >= 4) { idser = id.toString(false); if (!OSUtils::writeFile(argv[3],idser)) { - fprintf(stderr,"Error writing to %s"ZT_EOL_S,argv[3]); + fprintf(stderr,"Error writing to %s" ZT_EOL_S,argv[3]); return 1; - } else printf("%s written"ZT_EOL_S,argv[3]); + } else printf("%s written" ZT_EOL_S,argv[3]); } } else printf("%s",idser.c_str()); } else if (!strcmp(argv[1],"validate")) { @@ -651,14 +651,14 @@ static int idtool(int argc,char **argv) Identity id = getIdFromArg(argv[2]); if (!id) { - fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]); + fprintf(stderr,"Identity argument invalid or file unreadable: %s" ZT_EOL_S,argv[2]); return 1; } if (!id.locallyValidate()) { - fprintf(stderr,"%s FAILED validation."ZT_EOL_S,argv[2]); + fprintf(stderr,"%s FAILED validation." ZT_EOL_S,argv[2]); return 1; - } else printf("%s is a valid identity"ZT_EOL_S,argv[2]); + } else printf("%s is a valid identity" ZT_EOL_S,argv[2]); } else if (!strcmp(argv[1],"getpublic")) { if (argc < 3) { idtoolPrintHelp(stdout,argv[0]); @@ -667,7 +667,7 @@ static int idtool(int argc,char **argv) Identity id = getIdFromArg(argv[2]); if (!id) { - fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]); + fprintf(stderr,"Identity argument invalid or file unreadable: %s" ZT_EOL_S,argv[2]); return 1; } @@ -680,18 +680,18 @@ static int idtool(int argc,char **argv) Identity id = getIdFromArg(argv[2]); if (!id) { - fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]); + fprintf(stderr,"Identity argument invalid or file unreadable: %s" ZT_EOL_S,argv[2]); return 1; } if (!id.hasPrivate()) { - fprintf(stderr,"%s does not contain a private key (must use private to sign)"ZT_EOL_S,argv[2]); + fprintf(stderr,"%s does not contain a private key (must use private to sign)" ZT_EOL_S,argv[2]); return 1; } std::string inf; if (!OSUtils::readFile(argv[3],inf)) { - fprintf(stderr,"%s is not readable"ZT_EOL_S,argv[3]); + fprintf(stderr,"%s is not readable" ZT_EOL_S,argv[3]); return 1; } C25519::Signature signature = id.sign(inf.data(),(unsigned int)inf.length()); @@ -704,21 +704,21 @@ static int idtool(int argc,char **argv) Identity id = getIdFromArg(argv[2]); if (!id) { - fprintf(stderr,"Identity argument invalid or file unreadable: %s"ZT_EOL_S,argv[2]); + fprintf(stderr,"Identity argument invalid or file unreadable: %s" ZT_EOL_S,argv[2]); return 1; } std::string inf; if (!OSUtils::readFile(argv[3],inf)) { - fprintf(stderr,"%s is not readable"ZT_EOL_S,argv[3]); + fprintf(stderr,"%s is not readable" ZT_EOL_S,argv[3]); return 1; } std::string signature(Utils::unhex(argv[4])); if ((signature.length() > ZT_ADDRESS_LENGTH)&&(id.verify(inf.data(),(unsigned int)inf.length(),signature.data(),(unsigned int)signature.length()))) { - printf("%s signature valid"ZT_EOL_S,argv[3]); + printf("%s signature valid" ZT_EOL_S,argv[3]); } else { - fprintf(stderr,"%s signature check FAILED"ZT_EOL_S,argv[3]); + fprintf(stderr,"%s signature check FAILED" ZT_EOL_S,argv[3]); return 1; } } else if (!strcmp(argv[1],"mkcom")) { @@ -729,7 +729,7 @@ static int idtool(int argc,char **argv) Identity id = getIdFromArg(argv[2]); if ((!id)||(!id.hasPrivate())) { - fprintf(stderr,"Identity argument invalid, does not include private key, or file unreadable: %s"ZT_EOL_S,argv[2]); + fprintf(stderr,"Identity argument invalid, does not include private key, or file unreadable: %s" ZT_EOL_S,argv[2]); return 1; } @@ -744,7 +744,7 @@ static int idtool(int argc,char **argv) } } if (!com.sign(id)) { - fprintf(stderr,"Signature of certificate of membership failed."ZT_EOL_S); + fprintf(stderr,"Signature of certificate of membership failed." ZT_EOL_S); return 1; } @@ -938,27 +938,27 @@ static void printHelp(const char *cn,FILE *out) LICENSE_GRANT ZT_EOL_S); std::string updateUrl(OneService::autoUpdateUrl()); if (updateUrl.length()) - fprintf(out,"Automatic updates enabled:"ZT_EOL_S" %s"ZT_EOL_S" (all updates are securely authenticated by 256-bit ECDSA signature)"ZT_EOL_S""ZT_EOL_S,updateUrl.c_str()); - fprintf(out,"Usage: %s [-switches] [home directory]"ZT_EOL_S""ZT_EOL_S,cn); - fprintf(out,"Available switches:"ZT_EOL_S); - fprintf(out," -h - Display this help"ZT_EOL_S); - fprintf(out," -v - Show version"ZT_EOL_S); - fprintf(out," -U - Run as unprivileged user (skip privilege check)"ZT_EOL_S); - fprintf(out," -p - Port for UDP and TCP/HTTP (default: 9993, 0 for random)"ZT_EOL_S); + fprintf(out,"Automatic updates enabled:" ZT_EOL_S" %s" ZT_EOL_S" (all updates are securely authenticated by 256-bit ECDSA signature)" ZT_EOL_S"" ZT_EOL_S,updateUrl.c_str()); + fprintf(out,"Usage: %s [-switches] [home directory]" ZT_EOL_S"" ZT_EOL_S,cn); + fprintf(out,"Available switches:" ZT_EOL_S); + fprintf(out," -h - Display this help" ZT_EOL_S); + fprintf(out," -v - Show version" ZT_EOL_S); + fprintf(out," -U - Run as unprivileged user (skip privilege check)" ZT_EOL_S); + fprintf(out," -p - Port for UDP and TCP/HTTP (default: 9993, 0 for random)" ZT_EOL_S); #ifdef __UNIX_LIKE__ - fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)"ZT_EOL_S); + fprintf(out," -d - Fork and run as daemon (Unix-ish OSes)" ZT_EOL_S); #endif // __UNIX_LIKE__ #ifdef __WINDOWS__ - fprintf(out," -C - Run from command line instead of as service (Windows)"ZT_EOL_S); - fprintf(out," -I - Install Windows service (Windows)"ZT_EOL_S); - fprintf(out," -R - Uninstall Windows service (Windows)"ZT_EOL_S); - fprintf(out," -D - Remove all instances of Windows tap device (Windows)"ZT_EOL_S); + fprintf(out," -C - Run from command line instead of as service (Windows)" ZT_EOL_S); + fprintf(out," -I - Install Windows service (Windows)" ZT_EOL_S); + fprintf(out," -R - Uninstall Windows service (Windows)" ZT_EOL_S); + fprintf(out," -D - Remove all instances of Windows tap device (Windows)" ZT_EOL_S); #endif // __WINDOWS__ - fprintf(out," -i - Generate and manage identities (zerotier-idtool)"ZT_EOL_S); - fprintf(out," -q - Query API (zerotier-cli)"ZT_EOL_S); + fprintf(out," -i - Generate and manage identities (zerotier-idtool)" ZT_EOL_S); + fprintf(out," -q - Query API (zerotier-cli)" ZT_EOL_S); } #ifdef __WINDOWS__ @@ -1036,7 +1036,7 @@ int main(int argc,char **argv) break; case 'v': // Display version - printf("%d.%d.%d"ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); + printf("%d.%d.%d" ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION); return 0; case 'i': // Invoke idtool personality @@ -1058,12 +1058,12 @@ int main(int argc,char **argv) case 'I': { // Install this binary as a Windows service if (IsCurrentUserLocalAdministrator() != TRUE) { - fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: must be run as a local administrator." ZT_EOL_S,argv[0]); return 1; } std::string ret(InstallService(ZT_SERVICE_NAME,ZT_SERVICE_DISPLAY_NAME,ZT_SERVICE_START_TYPE,ZT_SERVICE_DEPENDENCIES,ZT_SERVICE_ACCOUNT,ZT_SERVICE_PASSWORD)); if (ret.length()) { - fprintf(stderr,"%s: unable to install service: %s"ZT_EOL_S,argv[0],ret.c_str()); + fprintf(stderr,"%s: unable to install service: %s" ZT_EOL_S,argv[0],ret.c_str()); return 3; } return 0; @@ -1071,12 +1071,12 @@ int main(int argc,char **argv) case 'R': { // Uninstall this binary as Windows service if (IsCurrentUserLocalAdministrator() != TRUE) { - fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: must be run as a local administrator." ZT_EOL_S,argv[0]); return 1; } std::string ret(UninstallService(ZT_SERVICE_NAME)); if (ret.length()) { - fprintf(stderr,"%s: unable to uninstall service: %s"ZT_EOL_S,argv[0],ret.c_str()); + fprintf(stderr,"%s: unable to uninstall service: %s" ZT_EOL_S,argv[0],ret.c_str()); return 3; } return 0; @@ -1085,7 +1085,7 @@ int main(int argc,char **argv) case 'D': { std::string err = WindowsEthernetTap::destroyAllPersistentTapDevices(); if (err.length() > 0) { - fprintf(stderr,"%s: unable to uninstall one or more persistent tap devices: %s"ZT_EOL_S,argv[0],err.c_str()); + fprintf(stderr,"%s: unable to uninstall one or more persistent tap devices: %s" ZT_EOL_S,argv[0],err.c_str()); return 3; } return 0; @@ -1111,7 +1111,7 @@ int main(int argc,char **argv) if (!homeDir.length()) homeDir = OneService::platformDefaultHomePath(); if (!homeDir.length()) { - fprintf(stderr,"%s: no home path specified and no platform default available"ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: no home path specified and no platform default available" ZT_EOL_S,argv[0]); return 1; } else { std::vector hpsp(Utils::split(homeDir.c_str(),ZT_PATH_SEPARATOR_S,"","")); @@ -1132,14 +1132,14 @@ int main(int argc,char **argv) #ifdef __UNIX_LIKE__ #ifndef ZT_ONE_NO_ROOT_CHECK if ((!skipRootCheck)&&(getuid() != 0)) { - fprintf(stderr,"%s: must be run as root (uid 0)"ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: must be run as root (uid 0)" ZT_EOL_S,argv[0]); return 1; } #endif // !ZT_ONE_NO_ROOT_CHECK if (runAsDaemon) { long p = (long)fork(); if (p < 0) { - fprintf(stderr,"%s: could not fork"ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: could not fork" ZT_EOL_S,argv[0]); return 1; } else if (p > 0) return 0; // forked @@ -1156,7 +1156,7 @@ int main(int argc,char **argv) // Running in "interactive" mode (mostly for debugging) if (IsCurrentUserLocalAdministrator() != TRUE) { if (!skipRootCheck) { - fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: must be run as a local administrator." ZT_EOL_S,argv[0]); return 1; } } else { @@ -1171,7 +1171,7 @@ int main(int argc,char **argv) if (CServiceBase::Run(zt1Service) == TRUE) { return 0; } else { - fprintf(stderr,"%s: unable to start service (try -h for help)"ZT_EOL_S,argv[0]); + fprintf(stderr,"%s: unable to start service (try -h for help)" ZT_EOL_S,argv[0]); return 1; } } @@ -1198,7 +1198,7 @@ int main(int argc,char **argv) case OneService::ONE_NORMAL_TERMINATION: break; case OneService::ONE_UNRECOVERABLE_ERROR: - fprintf(stderr,"%s: fatal error: %s"ZT_EOL_S,argv[0],zt1Service->fatalErrorMessage().c_str()); + fprintf(stderr,"%s: fatal error: %s" ZT_EOL_S,argv[0],zt1Service->fatalErrorMessage().c_str()); returnValue = 1; break; case OneService::ONE_IDENTITY_COLLISION: { diff --git a/zerotierone/service/OneService.cpp b/zerotierone/service/OneService.cpp index d6ad592..cea11f7 100755 --- a/zerotierone/service/OneService.cpp +++ b/zerotierone/service/OneService.cpp @@ -89,7 +89,7 @@ class SqliteNetworkController; #ifdef SDK // In network containers builds, use the virtual netcon endpoint instead of a tun/tap port driver -#include "../src/SDK_EthernetTap.hpp" +#include "../src/tap.hpp" namespace ZeroTier { typedef NetconEthernetTap EthernetTap; } #else // not ZT_SDK so pick a tap driver diff --git a/zerotierone/service/OneService.hpp b/zerotierone/service/OneService.hpp index 56dec8a..e2aa8ce 100755 --- a/zerotierone/service/OneService.hpp +++ b/zerotierone/service/OneService.hpp @@ -27,9 +27,9 @@ // Include the right tap device driver for this platform -- add new platforms here #ifdef SDK // In network containers builds, use the virtual netcon endpoint instead of a tun/tap port driver - #include "../src/SDK_EthernetTap.hpp" + #include "../src/tap.hpp" namespace ZeroTier { typedef NetconEthernetTap EthernetTap; } -#endif // not ZT_SDK so pick a tap driver +#endif namespace ZeroTier {