updated shared_lib for linux
This commit is contained in:
@@ -91,12 +91,14 @@ pthread_key_t thr_id_key;
|
||||
extern void load_symbols()
|
||||
{
|
||||
DEBUG_EXTRA("");
|
||||
|
||||
#if defined(__linux__)
|
||||
realaccept4 = dlsym(RTLD_NEXT, "accept4");
|
||||
#if !defined(__ANDROID__)
|
||||
realsyscall = dlsym(RTLD_NEXT, "syscall");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
realsetsockopt = (int(*)(SETSOCKOPT_SIG))dlsym(RTLD_NEXT, "setsockopt");
|
||||
realgetsockopt = (int(*)(GETSOCKOPT_SIG))dlsym(RTLD_NEXT, "getsockopt");
|
||||
realsocket = (int(*)(SOCKET_SIG))dlsym(RTLD_NEXT, "socket");
|
||||
|
||||
@@ -107,7 +107,7 @@ int get_retval(int rpc_sock)
|
||||
|
||||
int load_symbols_rpc()
|
||||
{
|
||||
#if defined(SDK_BUNDLED) || defined(__IOS__) || defined(__UNITY_3D__)
|
||||
#if defined(__IOS__) || defined(__UNITY_3D__)
|
||||
realsocket = dlsym(RTLD_NEXT, "socket");
|
||||
realconnect = dlsym(RTLD_NOW, "connect");
|
||||
if(!realconnect || !realsocket)
|
||||
@@ -144,7 +144,7 @@ int rpc_join(char * sockname)
|
||||
#else
|
||||
if((conn_err = connect(sock, (struct sockaddr*)&addr, sizeof(addr))) != 0) {
|
||||
#endif
|
||||
DEBUG_ERROR("error connecting to RPC socket. Re-attempting...");
|
||||
DEBUG_ERROR("error connecting to RPC socket (%s). Re-attempting...", sockname);
|
||||
usleep(100000);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -248,15 +248,10 @@ char *zts_get_homepath() {
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// ------------------------------ --------------------------
|
||||
// ----------------------------------- Other ------------------------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
// For use when symbols are used in Swift
|
||||
|
||||
// If we're using a bridging header for an Xcode project...
|
||||
// This matters because the header/wrapper needs to define symbols
|
||||
// for usage in Swift, but in order to maintain API naming consistency
|
||||
// between build environments whilst also preventing duplicate symbols
|
||||
// we need to check for this case
|
||||
|
||||
void zts_start_service(const char *path)
|
||||
{
|
||||
@@ -426,6 +421,11 @@ void zts_start_service(const char *path)
|
||||
|
||||
// Starts a ZeroTier service in the background
|
||||
void *zts_start_core_service(void *thread_id) {
|
||||
|
||||
#if defined(SDK_BUNDLED)
|
||||
homeDir = std::string((char*)thread_id);
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
DEBUG_INFO("ZTSDK_BUILD_VERSION = %d", ZTSDK_BUILD_VERSION);
|
||||
#endif
|
||||
@@ -493,14 +493,13 @@ void *zts_start_core_service(void *thread_id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
||||
#if defined(__UNITY_3D__)
|
||||
DEBUG_INFO("starting service...");
|
||||
#endif
|
||||
|
||||
|
||||
// Initialize RPC
|
||||
// TODO: remove?
|
||||
if(rpcEnabled) {
|
||||
zts_init_rpc(localHomeDir.c_str(), rpcNWID.c_str());
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <linux/errno.h>
|
||||
#include <sys/syscall.h>
|
||||
@@ -62,7 +64,7 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
#define SOCK_MAX (SOCK_PACKET + 1)
|
||||
#endif
|
||||
@@ -84,7 +86,9 @@ int (*realclose)(CLOSE_SIG);
|
||||
// ------------------------------------------------------------------------------
|
||||
// ---------------------------------- zt_init_rpc -------------------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int service_initialized = 0;
|
||||
|
||||
// Assembles (and/or) sets the RPC path for communication with the ZeroTier service
|
||||
void zts_init_rpc(const char *path, const char *nwid)
|
||||
{
|
||||
@@ -100,7 +104,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
#if defined(SDK_BUNDLED)
|
||||
// Get the path/nwid from the user application
|
||||
// netpath = [path + "/nc_" + nwid]
|
||||
char *fullpath = malloc(strlen(path)+strlen(nwid)+1+4);
|
||||
char *fullpath = (char *)malloc(strlen(path)+strlen(nwid)+1+4);
|
||||
if(fullpath) {
|
||||
strcpy(fullpath, path);
|
||||
strcat(fullpath, "/nc_");
|
||||
@@ -115,6 +119,20 @@ int (*realclose)(CLOSE_SIG);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// start the SDK service if this is bundled
|
||||
#if defined(SDK_BUNDLED)
|
||||
if(!service_initialized) {
|
||||
//api_netpath = "/root/dev/ztest5/nc_565799d8f612388c";
|
||||
DEBUG_ATTN("api_netpath = %s", api_netpath);
|
||||
pthread_t intercept_thread;
|
||||
pthread_create(&intercept_thread, NULL, zts_start_core_service, (void *)(path));
|
||||
service_initialized = 1;
|
||||
DEBUG_ATTN("waiting for service to come online");
|
||||
//while(!zts_service_is_running()) { }
|
||||
sleep(10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void get_api_netpath() { zts_init_rpc("",""); }
|
||||
@@ -226,7 +244,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
errno = EMSGSIZE; // Message too large to send atomically via underlying protocol, don't send
|
||||
return -1;
|
||||
}
|
||||
buf = malloc(tot_len);
|
||||
buf = (char *)malloc(tot_len);
|
||||
if(tot_len != 0 && buf == NULL) {
|
||||
errno = ENOMEM; // Unable to allocate space for message
|
||||
return -1;
|
||||
@@ -236,7 +254,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
memcpy(p, iov[i].iov_base, iov[i].iov_len);
|
||||
p += iov[i].iov_len;
|
||||
}
|
||||
err = sendto(fd, buf, tot_len, flags, msg->msg_name, msg->msg_namelen);
|
||||
//err = sendto(fd, buf, tot_len, flags, msg->msg_name, msg->msg_namelen);
|
||||
free(buf);
|
||||
return err;
|
||||
}
|
||||
@@ -315,12 +333,12 @@ int (*realclose)(CLOSE_SIG);
|
||||
|
||||
for(int i = 0; i < msg->msg_iovlen; ++i)
|
||||
tot_len += iov[i].iov_len;
|
||||
buf = malloc(tot_len);
|
||||
buf = (char *)malloc(tot_len);
|
||||
if(tot_len != 0 && buf == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
n = err = recvfrom(fd, buf, tot_len, flags, msg->msg_name, &msg->msg_namelen);
|
||||
//n = err = recvfrom(fd, buf, tot_len, flags, msg->msg_name, &msg->msg_namelen);
|
||||
p = buf;
|
||||
|
||||
// According to: http://pubs.opengroup.org/onlinepubs/009695399/functions/recvmsg.html
|
||||
@@ -446,7 +464,7 @@ int (*realclose)(CLOSE_SIG);
|
||||
#endif
|
||||
|
||||
#ifdef DYNAMIC_LIB
|
||||
int zts_socket(SOCKET_SIG)
|
||||
int zt_socket(SOCKET_SIG)
|
||||
#else
|
||||
int zts_socket(SOCKET_SIG)
|
||||
#endif
|
||||
@@ -612,7 +630,6 @@ int (*realclose)(CLOSE_SIG);
|
||||
{
|
||||
get_api_netpath();
|
||||
DEBUG_INFO("fd=%d", fd);
|
||||
// FIXME: Find a better solution for this before production
|
||||
#if !defined(__UNITY_3D__)
|
||||
if(addr)
|
||||
addr->sa_family = AF_INET;
|
||||
|
||||
@@ -174,10 +174,13 @@ namespace ZeroTier {
|
||||
{
|
||||
#if defined(__ANDROID__) || defined(__UNITY_3D__)
|
||||
#define __STATIC_STACK__
|
||||
#elif defined(__linux__)
|
||||
#elif defined(__linux__) && !defined(SDK_BUNDLED)
|
||||
#define __DYNAMIC_STACK__
|
||||
// Dynamically load stack library
|
||||
_libref = dlmopen(LM_ID_NEWLM, path, RTLD_NOW);
|
||||
#elif defined(__linux__) && defined(SDK_BUNDLED) // TODO: Determine why __STATIC_STACK__ won't work in SDK_BUNDLED mode
|
||||
#define __DYNAMIC_STACK__
|
||||
_libref = dlmopen(LM_ID_NEWLM, path, RTLD_NOW);
|
||||
#elif defined(__APPLE__)
|
||||
#include "TargetConditionals.h"
|
||||
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
|
||||
|
||||
@@ -145,9 +145,10 @@ NetconEthernetTap::NetconEthernetTap(
|
||||
|
||||
chmod(sockPath, 0777); // To make the RPC socket available to all users
|
||||
|
||||
DEBUG_INFO("tap initialized on: path=%s", sockPath);
|
||||
if (!_unixListenSocket)
|
||||
DEBUG_ERROR("unable to bind to: path=%s", sockPath);
|
||||
else
|
||||
DEBUG_INFO("tap initialized on: path=%s", sockPath);
|
||||
_thread = Thread::start(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user