From 306278bdf7e04307add0faa5943556aa3e711bdd Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Fri, 16 Dec 2016 13:04:01 -0800 Subject: [PATCH] updated unit tests, makefile targets --- make-linux.mk | 213 +++++++++++++++-------------- make-mac.mk | 188 ++++++++++++------------- tests/shared_test/zts.tcpclient4.c | 7 +- tests/shared_test/zts.tcpclient6.c | 77 +++++++++++ tests/shared_test/zts.tcpserver4.c | 10 +- tests/shared_test/zts.tcpserver6.c | 84 ++++++++++++ tests/shared_test/zts.udpclient4.c | 89 ++++++++++++ tests/shared_test/zts.udpclient6.c | 48 +++++++ tests/shared_test/zts.udpserver4.c | 91 ++++++++++++ tests/shared_test/zts.udpserver6.c | 55 ++++++++ 10 files changed, 656 insertions(+), 206 deletions(-) create mode 100644 tests/shared_test/zts.tcpclient6.c create mode 100644 tests/shared_test/zts.tcpserver6.c create mode 100755 tests/shared_test/zts.udpclient4.c create mode 100755 tests/shared_test/zts.udpclient6.c create mode 100755 tests/shared_test/zts.udpserver4.c create mode 100755 tests/shared_test/zts.udpserver6.c diff --git a/make-linux.mk b/make-linux.mk index ef7ef14..5920cb3 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -7,6 +7,30 @@ # tests: build only test applications for host system # clean: removes all built files, objects, other trash +# Build everything +all: one linux android lwip pico check + +# ------------------------------------------------------------------------------ +# ----------------------------------- Config ----------------------------------- +# ------------------------------------------------------------------------------ + +# Automagically pick clang or gcc, with preference for clang +# This is only done if we have not overridden these with an environment or CLI variable +ifeq ($(origin CC),default) + CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi) +endif +ifeq ($(origin CXX),default) + CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi) +endif + +INCLUDES= +DEFS= +ARCH_FLAGS=-arch x86_64 +CFLAGS= +CXXFLAGS=$(CFLAGS) -fno-rtti + +include objects.mk + # Target output filenames SHARED_LIB_NAME = libztlinux.so SDK_INTERCEPT_NAME = libztintercept.so @@ -41,27 +65,30 @@ SDK_INTERCEPT_C_FILES:=src/sockets.c \ src/intercept.c \ src/rpc.c -ZTFLAGS:=-DZT_ONE_NO_ROOT_CHECK -DSDK +INCLUDES+= -Iext \ + -I$(ZT1)/osdep \ + -I$(ZT1)/node \ + -I$(ZT1)/service \ + -I../$(ZT1)/osdep \ + -I../$(ZT1)/node \ + -I../$(ZT1)/service \ + -I. \ + -Isrc \ + -Isrc/stack_drivers +# ------------------------------------------------------------------------------ +# --------------------------------- ZT Config ---------------------------------- +# ------------------------------------------------------------------------------ -# Automagically pick clang or gcc, with preference for clang -# This is only done if we have not overridden these with an environment or CLI variable -ifeq ($(origin CC),default) - CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi) -endif -ifeq ($(origin CXX),default) - CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi) -endif +ZTFLAGS:=-DSDK -DZT_ONE_NO_ROOT_CHECK -#UNAME_M=$(shell $(CC) -dumpmachine | cut -d '-' -f 1) - -INCLUDES?= -DEFS?= -LDLIBS?= -CFLAGS= - -include objects.mk +# Disable codesign since open source users will not have ZeroTier's certs +CODESIGN=echo +PRODUCTSIGN=echo +CODESIGN_APP_CERT= +CODESIGN_INSTALLER_CERT= +# Debug output for ZeroTier service ifeq ($(ZT_DEBUG),1) DEFS+=-DZT_TRACE CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) @@ -81,65 +108,48 @@ else STRIP+=--strip-all endif -# Debug output for ZeroTier service -ifeq ($(ZT_TRACE),1) - DEFS+=-DZT_TRACE +# ------------------------------------------------------------------------------ +# -------------------------------- SDK Config ---------------------------------- +# ------------------------------------------------------------------------------ + +# Debug output for the SDK +# Specific levels can be controlled in src/debug.h +ifeq ($(SDK_DEBUG),1) + DEFS+=-DSDK_DEBUG -g endif -CXXFLAGS+=-std=c++11 - -INCLUDES+= -Iext \ - -I$(ZT1)/osdep \ - -I$(ZT1)/node \ - -I$(ZT1)/service \ - -I../$(ZT1)/osdep \ - -I../$(ZT1)/node \ - -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 \ - -I$(PICOTCP_DIR)/include \ - -I$(PICOTCP_DIR)/build/include \ - -Isrc/stack_drivers/lwip \ - -Isrc/stack_drivers/picotcp \ - -Isrc/stack_drivers/jip - - - -# Stack selection / parameters - -# lwIP debug -ifeq ($(SDK_LWIP_DEBUG),1) - LWIP_FLAGS+=SDK_LWIP_DEBUG=1 -endif - -# picoTCP debug -ifeq ($(SDK_PICOTCP_DEBUG),1) - PICOTCP_FLAGS+=DEBUG=1 -else - PICOTCP_FLAGS+=DEBUG=0 -endif +# ------------------------------------------------------------------------------ +# ------------------------ Network Stack Configuration ------------------------- +# ------------------------------------------------------------------------------ # lwIP ifeq ($(SDK_LWIP),1) STACK_FLAGS+=-DSDK_LWIP + INCLUDES+= -I$(LWIP_DIR)/src/include \ + -I$(LWIP_DIR)/src/include/ipv4 \ + -I$(LWIP_DIR)/src/include/ipv6 \ + -Isrc/stack_drivers/lwip + + ifeq ($(SDK_LWIP_DEBUG),1) + LWIP_FLAGS+=SDK_LWIP_DEBUG=1 + endif endif # picoTCP ifeq ($(SDK_PICOTCP),1) STACK_FLAGS+=-DSDK_PICOTCP + INCLUDES+= -I$(PICOTCP_DIR)/include \ + -I$(PICOTCP_DIR)/build/include \ + -Isrc/stack_drivers/picotcp endif # jip ifeq ($(SDK_JIP),1) STACK_FLAGS+=-DSDK_JIP + INCLUDES+= -Isrc/stack_drivers/jip endif - # TCP protocol version ifeq ($(SDK_IPV4),1) LWIP_FLAGS+=SDK_IPV4=1 @@ -151,89 +161,86 @@ ifeq ($(SDK_IPV6),1) STACK_FLAGS+=-DSDK_IPV6 endif - - -# Debug output for the SDK -# Specific levels can be controlled in src/debug.h -ifeq ($(SDK_DEBUG),1) - DEFS+=-DSDK_DEBUG -g -endif -# Log debug chatter to file, path is determined by environment variable ZT_SDK_LOGFILE -ifeq ($(SDK_DEBUG_LOG_TO_FILE),1) - DEFS+=-DSDK_DEBUG_LOG_TO_FILE -endif - - -# ------ MISC TARGETS ------ - -all: remove_only_intermediates linux_shared_lib check - -remove_only_intermediates: - -find . -type f \( -name '*.o' -o -name '*.so' \) -delete - - -# --- EXTERNAL LIBRARIES --- lwip: - mkdir -p build -make -f make-liblwip.mk $(LWIP_FLAGS) pico: mkdir -p build - cd ext/picotcp; make lib $(SDK_PICOTCP_FLAGS) PICO_SUPPORT_UDP=1 ARCH=shared IPV4=1 IPV6=1 + cd ext/picotcp; make lib ARCH=shared IPV4=1 IPV6=1 $(CC) -g -nostartfiles -shared -o ext/picotcp/build/lib/libpicotcp.so ext/picotcp/build/lib/*.o ext/picotcp/build/modules/*.o cp ext/picotcp/build/lib/libpicotcp.so build/libpicotcp.so jip: -make -f make-jip.mk $(JIP_FLAGS) +# ------------------------------------------------------------------------------ +# ---------------------------------- Linux ------------------------------------- +# ------------------------------------------------------------------------------ -# --------- LINUX ---------- # Build everything linux: one linux_service_and_intercept linux_shared_lib # Build vanilla ZeroTier One binary one: $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/LinuxEthernetTap.o mkdir -p $(BUILD) - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD)/zerotier-one $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/LinuxEthernetTap.o $(LDLIBS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD)/zerotier-one $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/LinuxEthernetTap.o $(STRIP) $(ONE_SERVICE) cp $(ONE_SERVICE) $(INT)/docker/docker_demo/$(ONE_SERVICE_NAME) + # --------------------------------------- + # --------------- Intercept ------------- + # --------------------------------------- + # 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 gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o $(SDK_INTERCEPT) $(SDK_INTERCEPT_C_FILES) -ldl + # --------------------------------------- + # ----- Service Library Combinations ---- + # --------------------------------------- + # Build only the SDK service ifeq ($(SDK_LWIP),1) linux_sdk_service: lwip $(OBJS) mkdir -p build - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(LWIP_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(LWIP_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) -ldl else linux_sdk_service: pico $(OBJS) mkdir -p build - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(PICO_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(PICO_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) -ldl endif ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-cli ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-idtool - # Build both intercept library and SDK service (separate) linux_service_and_intercept: linux_intercept linux_sdk_service # Builds a single shared library which contains everything -linux_shared_lib: pico $(OBJS) +linux_static_lib: pico $(OBJS) $(CXX) $(CXXFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED $(PICO_DRIVER_FILES) $(SDK_INTERCEPT_C_FILES) $(SDK_SERVICE_CPP_FILES) src/service.cpp -c ar -rcs build/libzt.a picotcp.o proxy.o tap.o one.o OneService.o service.o sockets.o rpc.o intercept.o OneService.o $(OBJS) # Builds zts_* library tests -linux_shared_lib_tests: +linux_static_lib_tests: mkdir -p $(TEST_OBJDIR) $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpserver4.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.tcpserver4.out -Lbuild -lzt -ldl $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpclient4.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.tcpclient4.out -Lbuild -lzt -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpserver6.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.tcpserver6.out -Lbuild -lzt -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpclient6.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.tcpclient6.out -Lbuild -lzt -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.udpserver4.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.udpserver4.out -Lbuild -lzt -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.udpclient4.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.udpclient4.out -Lbuild -lzt -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.udpserver6.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.udpserver6.out -Lbuild -lzt -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.udpclient6.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.udpclient6.out -Lbuild -lzt -ldl +# ------------------------------------------------------------------------------ +# --------------------------------- Android ------------------------------------ +# ------------------------------------------------------------------------------ +# Build all Android targets +# Chip architectures can be specified in integrations/android/android_jni_lib/java/jni/Application.mk +android: android_jni_lib -# -------- ANDROID --------- # TODO: CHECK if ANDROID/GRADLE TOOLS are installed # Build library for Android Unity integrations # Build JNI library for Android app integration @@ -244,10 +251,9 @@ android_jni_lib: mv -f $(INT)/android/android_jni_lib/java/libs/* $(BUILD)/android_jni_lib cp -R $(BUILD)/android_jni_lib/* $(INT)/android/example_app/app/src/main/jniLibs - - - -# -------- TESTING --------- +# ------------------------------------------------------------------------------ +# ---------------------------------- Testing ----------------------------------- +# ------------------------------------------------------------------------------ unit_test: one linux_service_and_intercept mkdir -p $(BUILD) @@ -317,28 +323,27 @@ TEST_OBJDIR := $(BUILD)/tests TEST_SOURCES := $(wildcard tests/api_test/*.c) TEST_TARGETS := $(addprefix $(BUILD)/tests/$(OSTYPE).,$(notdir $(TEST_SOURCES:.c=.out))) +LIB_TEST_SOURCES := $(wildcard tests/shared_test/*.c) +LIB_TEST_TARGETS := $(addprefix $(BUILD)/tests/$(OSTYPE).,$(notdir $(LIB_TEST_SOURCES:.c=.out))) + $(BUILD)/tests/$(OSTYPE).%.out: tests/api_test/%.c -$(CC) $(CC_FLAGS) -o $@ $< +$(BUILD)/tests/$(OSTYPE).%.out: tests/shared_test/%.c + #-$(CC) $(CC_FLAGS) -o $@ $< + -$(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpserver4.c -Lbuild -lzt -ldl -o $@ $< + $(TEST_OBJDIR): mkdir -p $(TEST_OBJDIR) tests: $(TEST_OBJDIR) $(TEST_TARGETS) mkdir -p $(BUILD)/tests; - mkdir -p build/tests/zerotier test_suite: tests lwip linux_service_and_intercept - cp tests/api_test/test.sh $(BUILD)/tests/test.sh - cp tests/api_test/servers.sh $(BUILD)/tests/servers.sh - cp tests/api_test/clients.sh $(BUILD)/tests/clients.sh - cp tests/cleanup.sh $(BUILD)/tests/cleanup.sh - cp $(LWIP_LIB) $(BUILD)/tests/zerotier/$(LWIP_LIB_NAME) -shared_lib_tests: - mkdir -p $(BUILD)/tests; - -$(CC) $(CC_FLAGS) -Isrc tests/api_test/zt_tcpserver4.c -o $(BUILD)/tests/zt_tcpserver4.out $(BUILD)/libztlinux.so - -# ----- ADMINISTRATIVE ----- +# ------------------------------------------------------------------------------ +# ------------------------------ Administrative -------------------------------- +# ------------------------------------------------------------------------------ clean_android: # android JNI lib project diff --git a/make-mac.mk b/make-mac.mk index 423cc49..8147e33 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -1,5 +1,5 @@ # -# Makefile for ZeroTier SDK on OSX +# Makefile for ZeroTier SDK on macOS # # Targets # all: build every target possible on host system, plus tests @@ -7,6 +7,30 @@ # tests: build only test applications for host system # clean: removes all built files, objects, other trash +# Build everything +all: one osx ios android lwip pico check + +# ------------------------------------------------------------------------------ +# ----------------------------------- Config ----------------------------------- +# ------------------------------------------------------------------------------ + +# Automagically pick clang or gcc, with preference for clang +# This is only done if we have not overridden these with an environment or CLI variable +ifeq ($(origin CC),default) + CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi) +endif +ifeq ($(origin CXX),default) + CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi) +endif + +INCLUDES= +DEFS= +ARCH_FLAGS=-arch x86_64 +CFLAGS= +CXXFLAGS=$(CFLAGS) -fno-rtti + +include objects.mk + # Target output filenames SHARED_LIB_NAME = libztosx.so INTERCEPT_NAME = libztintercept.so @@ -18,7 +42,7 @@ LWIP_LIB_NAME = liblwip.so PICO_LIB_NAME = libpicotcp.so # SHARED_LIB = $(BUILD)/$(SHARED_LIB_NAME) -INTERCEPT = $(BUILD)/$(INTERCEPT_NAME) +SDK_INTERCEPT = $(BUILD)/$(INTERCEPT_NAME) SDK_SERVICE = $(BUILD)/$(SDK_SERVICE_NAME) ONE_SERVICE = $(BUILD)/$(ONE_SERVICE_NAME) ONE_CLI = $(BUILD)/$(ONE_CLI_NAME) @@ -41,25 +65,23 @@ SDK_INTERCEPT_C_FILES:=src/sockets.c \ src/intercept.c \ src/rpc.c +INCLUDES+= -Iext \ + -I$(ZT1)/osdep \ + -I$(ZT1)/node \ + -I$(ZT1)/service \ + -I../$(ZT1)/osdep \ + -I../$(ZT1)/node \ + -I../$(ZT1)/service \ + -I. \ + -Isrc \ + -Isrc/stack_drivers + +# ------------------------------------------------------------------------------ +# --------------------------------- ZT Config ---------------------------------- +# ------------------------------------------------------------------------------ + ZTFLAGS:=-DSDK -DZT_ONE_NO_ROOT_CHECK -# Automagically pick clang or gcc, with preference for clang -# This is only done if we have not overridden these with an environment or CLI variable -ifeq ($(origin CC),default) - CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi) -endif -ifeq ($(origin CXX),default) - CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi) -endif - -INCLUDES= -DEFS= -LIBS= -ARCH_FLAGS=-arch x86_64 -CFLAGS= - -include objects.mk - # Disable codesign since open source users will not have ZeroTier's certs CODESIGN=echo PRODUCTSIGN=echo @@ -80,58 +102,48 @@ else STRIP=strip endif +# ------------------------------------------------------------------------------ +# -------------------------------- SDK Config ---------------------------------- +# ------------------------------------------------------------------------------ + # Debug output for the SDK # Specific levels can be controlled in src/debug.h ifeq ($(SDK_DEBUG),1) DEFS+=-DSDK_DEBUG -g endif -CXXFLAGS=$(CFLAGS) -fno-rtti - -INCLUDES+= -Iext \ - -I$(ZT1)/osdep \ - -I$(ZT1)/node \ - -I$(ZT1)/service \ - -I../$(ZT1)/osdep \ - -I../$(ZT1)/node \ - -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 \ - -I$(PICOTCP_DIR)/include \ - -I$(PICOTCP_DIR)/build/include \ - -Isrc/stack_drivers/lwip \ - -Isrc/stack_drivers/picotcp \ - -Isrc/stack_drivers/jip - - -# Stack selection / parameters - -# lwIP debug -ifeq ($(SDK_LWIP_DEBUG),1) - LWIP_FLAGS+=SDK_LWIP_DEBUG=1 -endif +# ------------------------------------------------------------------------------ +# ------------------------ Network Stack Configuration ------------------------- +# ------------------------------------------------------------------------------ # lwIP ifeq ($(SDK_LWIP),1) STACK_FLAGS+=-DSDK_LWIP + INCLUDES+= -I$(LWIP_DIR)/src/include \ + -I$(LWIP_DIR)/src/include/ipv4 \ + -I$(LWIP_DIR)/src/include/ipv6 \ + -Isrc/stack_drivers/lwip + + ifeq ($(SDK_LWIP_DEBUG),1) + LWIP_FLAGS+=SDK_LWIP_DEBUG=1 + endif endif # picoTCP ifeq ($(SDK_PICOTCP),1) STACK_FLAGS+=-DSDK_PICOTCP + INCLUDES+= -I$(PICOTCP_DIR)/include \ + -I$(PICOTCP_DIR)/build/include \ + -Isrc/stack_drivers/picotcp endif # jip ifeq ($(SDK_JIP),1) STACK_FLAGS+=-DSDK_JIP + INCLUDES+= -Isrc/stack_drivers/jip endif - # TCP protocol version ifeq ($(SDK_IPV4),1) LWIP_FLAGS+=SDK_IPV4=1 @@ -143,14 +155,6 @@ ifeq ($(SDK_IPV6),1) STACK_FLAGS+=-DSDK_IPV6 endif - -# ------ MISC TARGETS ------ -# Build everything -all: one osx ios android lwip check - - - -# --- EXTERNAL LIBRARIES --- lwip: -make -f make-liblwip.mk $(LWIP_FLAGS) @@ -163,25 +167,28 @@ pico: jip: -make -f make-jip.mk $(JIP_FLAGS) -# ------- IOS / OSX -------- +# ------------------------------------------------------------------------------ +# -------------------------------- IOS / macOS --------------------------------- +# ------------------------------------------------------------------------------ # Build all Apple targets apple: one osx ios - # Build vanilla ZeroTier One binary one: $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/OSXEthernetTap.o mkdir -p $(BUILD) - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD)/zerotier-one $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/OSXEthernetTap.o $(LDLIBS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD)/zerotier-one $(OBJS) $(ZT1)/service/OneService.o $(ZT1)/one.o $(ZT1)/osdep/OSXEthernetTap.o $(STRIP) $(ONE_SERVICE) cp $(ONE_SERVICE) $(INT)/docker/docker_demo/$(ONE_SERVICE_NAME) # Build all iOS targets ios: ios_app_framework ios_unity3d_bundle - # Build all OSX targets osx: osx_app_framework osx_unity3d_bundle osx_shared_lib osx_sdk_service osx_intercept + # --------------------------------------- + # ----------- App Frameworks ------------ + # --------------------------------------- # TODO: CHECK if XCODE TOOLS are installed # Build frameworks for application development @@ -189,11 +196,15 @@ osx_app_framework: cd $(INT)/apple/ZeroTierSDK_Apple; xcodebuild -configuration Release -scheme ZeroTierSDK_OSX build SYMROOT="../../../$(BUILD)/osx_app_framework" cd $(INT)/apple/ZeroTierSDK_Apple; xcodebuild -configuration Debug -scheme ZeroTierSDK_OSX build SYMROOT="../../../$(BUILD)/osx_app_framework" cp docs/osx.md $(BUILD)/osx_app_framework/README.md + ios_app_framework: cd $(INT)/apple/ZeroTierSDK_Apple; xcodebuild -configuration Release -scheme ZeroTierSDK_iOS build SYMROOT="../../../$(BUILD)/ios_app_framework" cd $(INT)/apple/ZeroTierSDK_Apple; xcodebuild -configuration Debug -scheme ZeroTierSDK_iOS build SYMROOT="../../../$(BUILD)/ios_app_framework" cp docs/ios.md $(BUILD)/ios_app_framework/README.md + # --------------------------------------- + # ------------ Unity Bundles ------------ + # --------------------------------------- # Build bundles for Unity integrations osx_unity3d_bundle: @@ -203,59 +214,55 @@ osx_unity3d_bundle: chmod 755 $(BUILD)/osx_unity3d_bundle/Debug/ZeroTierSDK_Unity3D_OSX.bundle cp -p -R $(BUILD)/osx_unity3d_bundle/Debug/ZeroTierSDK_Unity3D_OSX.bundle $(INT)/Unity3D/Assets/Plugins - ios_unity3d_bundle: cd $(INT)/apple/ZeroTierSDK_Apple; xcodebuild -configuration Release -scheme ZeroTierSDK_Unity3D_iOS build SYMROOT="../../../$(BUILD)/ios_unity3d_bundle" cd $(INT)/apple/ZeroTierSDK_Apple; xcodebuild -configuration Debug -scheme ZeroTierSDK_Unity3D_iOS build SYMROOT="../../../$(BUILD)/ios_unity3d_bundle" cp docs/ios_unity3d.md $(BUILD)/ios_unity3d_bundle/README.md -# -simple_app: tests osx_service_and_intercept - mkdir -p build/simple_app - mkdir -p build/tests/zerotier - $(CXX) -Isrc $(SHARED_LIB) integrations/simple_app/app.cpp -o $(BUILD)/simple_app/app - cp $(LWIP_LIB) $(BUILD)/tests/zerotier/$(LWIP_LIB_NAME) - - -remove_only_intermediates: - -find . -type f \( -name '*.o' -o -name '*.so' \) -delete - + # --------------------------------------- + # --------------- Intercept ------------- + # --------------------------------------- osx_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 - gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o $(INTERCEPT) $(SDK_INTERCEPT_C_FILES) -ldl + gcc $(DEFS) $(INCLUDES) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -nostdlib -nostdlib -shared -o $(SDK_INTERCEPT) $(SDK_INTERCEPT_C_FILES) -ldl + # --------------------------------------- + # ----- Service Library Combinations ---- + # --------------------------------------- # Build only the SDK service ifeq ($(SDK_LWIP),1) osx_sdk_service: lwip $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(LWIP_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(LWIP_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) -ldl else osx_sdk_service: pico $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(PICO_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) $(LDLIBS) -ldl + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -o $(SDK_SERVICE) $(OBJS) $(PICO_DRIVER_FILES) $(SDK_SERVICE_CPP_FILES) $(SDK_SERVICE_C_FILES) -ldl endif ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-cli ln -sf $(SDK_SERVICE_NAME) $(BUILD)/zerotier-idtool - # Build both intercept library and SDK service (separate) osx_service_and_intercept: osx_intercept osx_sdk_service -# Builds a single shared library which contains everything -osx_shared_lib: pico $(OBJS) +osx_static_lib: pico $(OBJS) $(CXX) $(CXXFLAGS) $(STACK_FLAGS) $(DEFS) $(INCLUDES) $(ZTFLAGS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED $(PICO_DRIVER_FILES) $(SDK_INTERCEPT_C_FILES) $(SDK_SERVICE_CPP_FILES) src/service.cpp -c - libtool -static -o build/libzt.a zerotierone/node/IncomingPacket.o picotcp.o proxy.o tap.o one.o OneService.o service.o sockets.o rpc.o intercept.o OneService.o $(OBJS) + libtool -static -o build/libzt.a picotcp.o proxy.o tap.o one.o OneService.o service.o sockets.o rpc.o intercept.o OneService.o $(OBJS) # Builds zts_* library tests -osx_shared_lib_tests: +osx_static_lib_tests: mkdir -p $(TEST_OBJDIR) $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpserver4.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.tcpserver4.out -Lbuild -lzt -ldl $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $(STACK_FLAGS) $(DEFS) -DSDK_SERVICE -DSDK -DSDK_BUNDLED -Isrc tests/shared_test/zts.tcpclient4.c -o $(TEST_OBJDIR)/$(OSTYPE).zts.tcpclient4.out -Lbuild -lzt -ldl +osx_dynamic_lib: +osx_dynamic_lib_tests: +# ------------------------------------------------------------------------------ +# ---------------------------------- Android ----------------------------------- +# ------------------------------------------------------------------------------ -# -------- ANDROID --------- # Build all Android targets # Chip architectures can be specified in integrations/android/android_jni_lib/java/jni/Application.mk android: android_jni_lib @@ -271,15 +278,15 @@ android_jni_lib: mv -f $(INT)/android/android_jni_lib/java/libs/* $(BUILD)/android_jni_lib cp -R $(BUILD)/android_jni_lib/* $(INT)/android/example_app/app/src/main/jniLibs +# ------------------------------------------------------------------------------ +# ---------------------------------- Testing ----------------------------------- +# ------------------------------------------------------------------------------ - - -# -------- TESTING --------- # Check for the presence of built frameworks/bundles/libaries check: -./check.sh $(LWIP_LIB) -./check.sh $(PICO_LIB) - -./check.sh $(INTERCEPT) + -./check.sh $(SDK_INTERCEPT) -./check.sh $(ONE_SERVICE) -./check.sh $(SDK_SERVICE) -./check.sh $(SHARED_LIB) @@ -312,17 +319,12 @@ tests: $(TEST_OBJDIR) $(TEST_TARGETS) mkdir -p build/tests/zerotier test_suite: tests lwip osx_service_and_intercept - cp tests/api_test/test.sh $(BUILD)/tests/test.sh - cp tests/api_test/servers.sh $(BUILD)/tests/servers.sh - cp tests/api_test/clients.sh $(BUILD)/tests/clients.sh - cp tests/cleanup.sh $(BUILD)/tests/cleanup.sh - cp $(LWIP_LIB) $(BUILD)/tests/zerotier/$(LWIP_LIB_NAME) +# ------------------------------------------------------------------------------ +# ------------------------------ Administrative -------------------------------- +# ------------------------------------------------------------------------------ -# ----- ADMINISTRATIVE ----- JAVAC := $(shell which javac) - -clean_unity: clean_android: # android JNI lib project diff --git a/tests/shared_test/zts.tcpclient4.c b/tests/shared_test/zts.tcpclient4.c index d1e566e..eac783b 100644 --- a/tests/shared_test/zts.tcpclient4.c +++ b/tests/shared_test/zts.tcpclient4.c @@ -1,4 +1,4 @@ -// TCP Client test program +// TCP Client test program (IPV4) #include #include @@ -15,12 +15,11 @@ int close(int filedes); int main(int argc , char *argv[]) { - zts_init_rpc("/root/dev/ztest5","565799d8f612388c"); - if(argc < 3) { - printf("usage: client \n"); + printf("usage: client \n"); return 1; } + zts_init_rpc(argv[3],argv[4]); int sock, port = atoi(argv[2]); struct sockaddr_in server; diff --git a/tests/shared_test/zts.tcpclient6.c b/tests/shared_test/zts.tcpclient6.c new file mode 100644 index 0000000..b39f48a --- /dev/null +++ b/tests/shared_test/zts.tcpclient6.c @@ -0,0 +1,77 @@ +// TCP Client test program (IPV6) + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include "sdk.h" + +void error(char *msg) { + perror(msg); + exit(0); +} + +int main(int argc, char *argv[]) { + int sockfd, portno, n; + struct sockaddr_in6 serv_addr; + struct hostent *server; + char buffer[256] = "This is a string from client!"; + + if (argc < 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(0); + } + portno = atoi(argv[2]); + + printf("\nIPv6 TCP Client Started...\n"); + + //Sockets Layer Call: socket() + sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0); + if (sockfd < 0) + error("ERROR opening socket"); + + //Sockets Layer Call: gethostbyname2() + server = gethostbyname2(argv[1],AF_INET6); + if (server == NULL) { + fprintf(stderr, "ERROR, no such host\n"); + exit(0); + } + + memset((char *) &serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin6_flowinfo = 0; + serv_addr.sin6_family = AF_INET6; + memmove((char *) &serv_addr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length); + serv_addr.sin6_port = htons(portno); + + //Sockets Layer Call: connect() + if (zts_connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) + error("ERROR connecting"); + + + //Sockets Layer Call: send() + n = send(sockfd,buffer, strlen(buffer)+1, 0); + if (n < 0) + error("ERROR writing to socket"); + + printf("sent %d bytes\n", n); + memset(buffer, 0, 256); + + //Sockets Layer Call: recv() + printf("reading...\n"); + n = recv(sockfd, buffer, 255, 0); + if (n < 0) + error("ERROR reading from socket"); + printf("Message from server: %s\n", buffer); + + //Sockets Layer Call: close() + close(sockfd); + + return 0; +} \ No newline at end of file diff --git a/tests/shared_test/zts.tcpserver4.c b/tests/shared_test/zts.tcpserver4.c index aa45cbf..9fe94d3 100644 --- a/tests/shared_test/zts.tcpserver4.c +++ b/tests/shared_test/zts.tcpserver4.c @@ -1,4 +1,4 @@ -// TCP Server test program +// TCP Server test program (IPV4) #include #include @@ -12,11 +12,11 @@ int atoi(const char *str); int main(int argc , char *argv[]) { - zts_init_rpc("/root/dev/ztest5","565799d8f612388c"); - if(argc < 2) { - printf("usage: tcp_server \n"); - return 0; + if(argc < 3) { + printf("usage: client \n"); + return 1; } + zts_init_rpc(argv[2],argv[3]); int sock, client_sock, c, read_size, port = atoi(argv[1]); char client_message[2000]; diff --git a/tests/shared_test/zts.tcpserver6.c b/tests/shared_test/zts.tcpserver6.c new file mode 100644 index 0000000..1d20b78 --- /dev/null +++ b/tests/shared_test/zts.tcpserver6.c @@ -0,0 +1,84 @@ +// TCP Server test program (IPV6) + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include "sdk.h" + +void error(char *msg) { + perror(msg); + exit(1); +} + +int main(int argc, char *argv[]) { + int sockfd, newsockfd, portno; + socklen_t clilen; + char buffer[256]; + struct sockaddr_in6 serv_addr, cli_addr; + int n; + char client_addr_ipv6[100]; + + if(argc < 3) { + printf("usage: client \n"); + return 1; + } + zts_init_rpc(argv[2],argv[3]); + + printf("\nIPv6 TCP Server Started...\n"); + + sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0); + if (sockfd < 0) + error("ERROR opening socket"); + + bzero((char *) &serv_addr, sizeof(serv_addr)); + portno = atoi(argv[1]); + serv_addr.sin6_flowinfo = 0; + serv_addr.sin6_family = AF_INET6; + serv_addr.sin6_addr = in6addr_any; + serv_addr.sin6_port = htons(portno); + + // bind + if (zts_bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) + error("ERROR on binding"); + + // listen + zts_listen(sockfd, 5); + clilen = sizeof(cli_addr); + + // accept + newsockfd = zts_accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); + if (newsockfd < 0) + error("ERROR on accept"); + + inet_ntop(AF_INET6, &(cli_addr.sin6_addr),client_addr_ipv6, 100); + printf("Incoming connection from client having IPv6 address: %s\n",client_addr_ipv6); + + memset(buffer,0, 256); + + // recv + n = recv(newsockfd, buffer, 255, 0); + if (n < 0) + error("ERROR reading from socket"); + + printf("Message from client: %s\n", buffer); + + // send + printf("sending...\n"); + n = send(newsockfd, "Server got your message", 23+1, 0); + if (n < 0) + error("ERROR writing to socket"); + + close(sockfd); + close(newsockfd); + return 0; +} diff --git a/tests/shared_test/zts.udpclient4.c b/tests/shared_test/zts.udpclient4.c new file mode 100755 index 0000000..6423ded --- /dev/null +++ b/tests/shared_test/zts.udpclient4.c @@ -0,0 +1,89 @@ +// UDP Client test program (IPV4) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sdk.h" + +#define BUFSIZE 1024 + +/* + * error - wrapper for perror + */ +void error(char *msg) { + perror(msg); + exit(0); +} + +int main(int argc, char **argv) { + int sock, portno, n; + int serverlen; + struct sockaddr_in serveraddr; + struct hostent *server; + char *hostname; + char buf[BUFSIZE]; + + /* check command line arguments */ + if (argc != 3) { + fprintf(stderr,"usage: %s \n", argv[0]); + exit(0); + } + hostname = argv[1]; + portno = atoi(argv[2]); + + /* socket: create the socket */ + sock = zts_socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) + error("ERROR opening socket"); + + /* gethostbyname: get the server's DNS entry */ + server = gethostbyname(hostname); + if (server == NULL) { + fprintf(stderr,"ERROR, no such host as %s\n", hostname); + exit(0); + } + + /* build the server's Internet address */ + bzero((char *) &serveraddr, sizeof(serveraddr)); + serveraddr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (char *)&serveraddr.sin_addr.s_addr, server->h_length); + serveraddr.sin_port = htons(portno); + + /* get a message from the user */ + char *msg = "A message to the server!\0"; + fcntl(sock, F_SETFL, O_NONBLOCK); + long count = 0; + while(1) + { + count++; + printf("\n\n\nTX(%lu)...\n", count); + sleep(1); + //usleep(10000); + //bzero(buf, BUFSIZE); + //printf("\nPlease enter msg: "); + //fgets(buf, BUFSIZE, stdin); + + /* send the message to the server */ + serverlen = sizeof(serveraddr); + n = sendto(sock, msg, strlen(msg), 0, (struct sockaddr *)&serveraddr, serverlen); + //if (n < 0) + // error("ERROR in sendto"); + + /* print the server's reply */ + memset(buf, 0, sizeof(buf)); + n = recvfrom(sock, buf, BUFSIZE, 0, (struct sockaddr *)&serveraddr, (socklen_t *)&serverlen); + //if (n < 0) + // printf("ERROR in recvfrom: %d", n); + printf("Echo from server: %s", buf); + } + return 0; +} diff --git a/tests/shared_test/zts.udpclient6.c b/tests/shared_test/zts.udpclient6.c new file mode 100755 index 0000000..a500fb9 --- /dev/null +++ b/tests/shared_test/zts.udpclient6.c @@ -0,0 +1,48 @@ +// UDP Client test program (IPV6) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sdk.h" + +#define MAXBUF 65536 + +int main(int argc, char* argv[]) +{ + int status; + struct addrinfo sainfo, *psinfo; + struct hostent *server; + char buffer[MAXBUF]; + + int sock, portno, n; + struct sockaddr_in6 serv_addr; + + if(argc < 2) + printf("Specify a port number\n"), exit(1); + + sock = socket(PF_INET6, SOCK_DGRAM,0); + + portno = atoi(argv[2]); + server = gethostbyname2(argv[1],AF_INET6); + memset((char *) &serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin6_flowinfo = 0; + serv_addr.sin6_family = AF_INET6; + memmove((char *) &serv_addr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length); + serv_addr.sin6_port = htons(portno); + + sprintf(buffer,"Ciao"); + + status = sendto(sock, buffer, strlen(buffer), 0, (const struct sockaddr *)&serv_addr, sizeof(serv_addr)); + printf("buffer : %s \t%d\n", buffer, status); + + close(sock); + return 0; +} \ No newline at end of file diff --git a/tests/shared_test/zts.udpserver4.c b/tests/shared_test/zts.udpserver4.c new file mode 100755 index 0000000..7fa8c87 --- /dev/null +++ b/tests/shared_test/zts.udpserver4.c @@ -0,0 +1,91 @@ +// UDP Server test program (IPV4) + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sdk.h" + +#define MAXBUF 1024*1024 + +void echo(int sock) { + char bufin[MAXBUF]; + struct sockaddr_in remote; + int n; + socklen_t len = sizeof(remote); + long count = 0; + + while (1) { + sleep(1); + //usleep(50); + count++; + // read a datagram from the socket (put result in bufin) + n=recvfrom(sock,bufin,MAXBUF,0,(struct sockaddr *)&remote,&len); + // print out the address of the sender + printf("DGRAM from %s:%d\n", inet_ntoa(remote.sin_addr), ntohs(remote.sin_port)); + + if (n<0) { + perror("Error receiving data"); + } else { + printf("GOT %d BYTES (count = %ld)\n", n, count); + // Got something, just send it back + // sendto(sock,bufin,n,0,(struct sockaddr *)&remote,len); + printf("RX = %s\n", bufin); + } + } +} + +int main(int argc, char *argv[]) { + + if(argc < 3) { + printf("usage: client \n"); + return 1; + } + zts_init_rpc(argv[2],argv[3]); + + int sock, port = atoi(argv[1]); + socklen_t len; + struct sockaddr_in skaddr; + struct sockaddr_in skaddr2; + + // Create socket + if ((sock = socket( PF_INET, SOCK_DGRAM, 0)) < 0) { + printf("error creating socket\n"); + return 0; + } + // Create address + skaddr.sin_family = AF_INET; + skaddr.sin_addr.s_addr = htonl(INADDR_ANY); + skaddr.sin_port = htons(port); + // Bind to address + if (bind(sock, (struct sockaddr *) &skaddr, sizeof(skaddr))<0) { + printf("error binding\n"); + return 0; + } + // find out what port we were assigned + len = sizeof( skaddr2 ); + //if (getsockname(sock, (struct sockaddr *) &skaddr2, &len)<0) { + // printf("error getsockname\n"); + // return 0; + //} + // Display address:port to verify it was sent over RPC correctly + /* + port = ntohs(skaddr2.sin_port); + int ip = skaddr2.sin_addr.s_addr; + unsigned char d[4]; + d[0] = ip & 0xFF; + d[1] = (ip >> 8) & 0xFF; + d[2] = (ip >> 16) & 0xFF; + d[3] = (ip >> 24) & 0xFF; + printf("bound to address: %d.%d.%d.%d : %d\n", d[0],d[1],d[2],d[3], port); + */ + // RX + echo(sock); + return(0); +} diff --git a/tests/shared_test/zts.udpserver6.c b/tests/shared_test/zts.udpserver6.c new file mode 100755 index 0000000..7c58144 --- /dev/null +++ b/tests/shared_test/zts.udpserver6.c @@ -0,0 +1,55 @@ +// UDP Server test program (IPV6) + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sdk.h" + +#define MAXBUF 65536 + +int main(int argc, char *argv[]) +{ + if(argc < 3) { + printf("usage: client \n"); + return 1; + } + zts_init_rpc(argv[2],argv[3]); + + int sock; + int n; + struct sockaddr_in6 sin6; + socklen_t sin6len; + char buffer[MAXBUF]; + + sock = socket(PF_INET6, SOCK_DGRAM,0); + sin6len = sizeof(struct sockaddr_in6); + memset(&sin6, 0, sin6len); + + sin6.sin6_port = htons(atoi(argv[1])); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = in6addr_any; + + n = bind(sock, (struct sockaddr *)&sin6, sin6len); + if(-1 == n) + perror("bind"), exit(1); + + //n = getsockname(sock, (struct sockaddr *)&sin6, &sin6len); + //printf("%d\n", ntohs(sin6.sin6_port)); + + while (1) { + sleep(1); + n = recvfrom(sock, buffer, MAXBUF, 0, (struct sockaddr *)&sin6, &sin6len); + printf("n = %d, buffer : %s\n", n, buffer); + } + + shutdown(sock, 2); + close(sock); + return 0; +} \ No newline at end of file