diff --git a/integrations/Apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate b/integrations/Apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate index 64301bd..6f99ced 100644 Binary files a/integrations/Apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate and b/integrations/Apple/ZeroTierSDK_Apple/ZeroTierSDK_Apple.xcodeproj/project.xcworkspace/xcuserdata/Joseph.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/integrations/Unity3D/Assets/MainScene.unity b/integrations/Unity3D/Assets/MainScene.unity index ec9e829..d7412ab 100644 Binary files a/integrations/Unity3D/Assets/MainScene.unity and b/integrations/Unity3D/Assets/MainScene.unity differ diff --git a/integrations/Unity3D/Assets/WorldMain.cs b/integrations/Unity3D/Assets/WorldMain.cs index f32e06f..14bf416 100755 --- a/integrations/Unity3D/Assets/WorldMain.cs +++ b/integrations/Unity3D/Assets/WorldMain.cs @@ -30,6 +30,8 @@ using System.Collections; using UnityEngine.UI; using System; + +// Handles the switching of APIs public class WorldMain : MonoBehaviour { void Start() { } @@ -40,6 +42,4 @@ public class WorldMain : MonoBehaviour { Dropdown dd = go.GetComponents () [0]; Debug.Log("API selected: " + dd.captionText.text); } - - } diff --git a/integrations/Unity3D/Assets/ZeroTierSockets.cs b/integrations/Unity3D/Assets/ZeroTierSockets.cs index cbc9a41..b8dae2b 100755 --- a/integrations/Unity3D/Assets/ZeroTierSockets.cs +++ b/integrations/Unity3D/Assets/ZeroTierSockets.cs @@ -113,7 +113,7 @@ public class ZeroTierNetworkInterface { // RX / TX [DllImport (DLL_PATH)] - unsafe protected static extern int zt_recv(int sockfd, IntPtr buf, int len); + unsafe protected static extern int zt_recv(int sockfd, [In, Out] IntPtr buf, int len); [DllImport (DLL_PATH)] unsafe protected static extern int zt_send(int sockfd, IntPtr buf, int len); [DllImport (DLL_PATH)] @@ -243,36 +243,14 @@ public class ZeroTierNetworkInterface { return zt_connect (fd, pSockAddr, addrlen); } - - /* - unsafe { - byte *ptr = (byte *)buffer.ToPointer(); - - int offset = 0; - for (int i=0; i { // Socket() - int sockfd = zt.Socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified); - Debug.Log ("sockfd = " + sockfd); + connection_socket = zt.Socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified); + Debug.Log ("sockfd = " + connection_socket); // Bind() int port_num; @@ -123,6 +123,17 @@ public class ZeroTierSockets_Demo : MonoBehaviour Debug.Log ("accept_res = " + accept_res); } + + char[] msg = new char[1024]; + int bytes_read = 0; + while(bytes_read >= 0) + { + //Debug.Log("reading from socket"); + bytes_read = zt.Read(accept_res, ref msg, 80); + + string msgstr = new string(msg); + Debug.Log("MSG (" + bytes_read + "):" + msgstr); + } }); connectThread.IsBackground = true; connectThread.Start(); @@ -169,7 +180,7 @@ public class ZeroTierSockets_Demo : MonoBehaviour input.text = "172.22.211.245"; go = GameObject.Find ("inputServerPort"); input = go.GetComponents () [0]; - input.text = "8887"; + input.text = "5555"; go = GameObject.Find ("inputMessage"); input = go.GetComponents () [0]; input.text = "Welcome to the machine"; diff --git a/src/SDK.h b/src/SDK.h index 78c2ff5..ff7eb31 100644 --- a/src/SDK.h +++ b/src/SDK.h @@ -83,7 +83,7 @@ int zt_socket(SOCKET_SIG); int zt_connect(CONNECT_SIG); int zt_bind(BIND_SIG); #if defined(__linux__) - int zt_accept(ACCEPT_SIG); + int zt_accept4(ACCEPT_SIG); #endif int zt_accept(ACCEPT_SIG); int zt_listen(LISTEN_SIG); diff --git a/src/SDK_RPC.c b/src/SDK_RPC.c index 49dee86..0f54b78 100644 --- a/src/SDK_RPC.c +++ b/src/SDK_RPC.c @@ -53,6 +53,9 @@ extern "C" { #define SERVICE_CONNECT_ATTEMPTS 30 +ssize_t sock_fd_write(int sock, int fd); +ssize_t sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd); + static int rpc_count; static pthread_mutex_t lock; @@ -111,10 +114,6 @@ int load_symbols_rpc() int rpc_join(char * sockname) { - - FILE *f = fopen("/Users/Joseph/utest2/_log.txt","a"); - fprintf(f, sockname); - if(sockname == NULL) { printf("Warning, rpc netpath is NULL\n"); } @@ -277,39 +276,65 @@ ssize_t sock_fd_write(int sock, int fd) */ ssize_t sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd) { + FILE *file = fopen("/Users/Joseph/code/__log","a"); + + ssize_t size; if (fd) { + + fprintf(file, "A"); + struct msghdr msg; struct iovec iov; union { struct cmsghdr cmsghdr; char control[CMSG_SPACE(sizeof (int))]; } cmsgu; + + fprintf(file, "B"); + struct cmsghdr *cmsg; iov.iov_base = buf; iov.iov_len = bufsize; msg.msg_name = NULL; msg.msg_namelen = 0; + + fprintf(file, "C"); + + msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = cmsgu.control; msg.msg_controllen = sizeof(cmsgu.control); size = recvmsg (sock, &msg, 0); + + fprintf(file, "D"); + if (size < 0) return -1; cmsg = CMSG_FIRSTHDR(&msg); if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) { + fprintf(file, "E"); + if (cmsg->cmsg_level != SOL_SOCKET) { + fprintf(file, "F"); + fprintf (stderr, "invalid cmsg_level %d\n",cmsg->cmsg_level); return -1; } if (cmsg->cmsg_type != SCM_RIGHTS) { + fprintf(file, "G"); + fprintf (stderr, "invalid cmsg_type %d\n",cmsg->cmsg_type); return -1; } *fd = *((int *) CMSG_DATA(cmsg)); - } else *fd = -1; + } else { + fprintf(file, "H"); +*fd = -1;} } else { + fprintf(file, "I"); + size = read (sock, buf, bufsize); if (size < 0) { fprintf(stderr, "sock_fd_read(): read: Error\n"); diff --git a/src/SDK_Sockets.c b/src/SDK_Sockets.c index cbe8ce6..a6c9857 100644 --- a/src/SDK_Sockets.c +++ b/src/SDK_Sockets.c @@ -312,7 +312,14 @@ const char *get_netpath() { ssize_t zt_recv(int fd, void *buf, int len) { - return read(fd, buf, len); + dwr("zt_recv(%d): \n", fd); + + int bytes_read = read(fd, buf, len); + if(bytes_read >= 0) + { + dwr("zt_recv(): MSG(%d): %s\n", bytes_read, buf); + } + return bytes_read; } int zt_set_nonblock(int fd) @@ -470,11 +477,15 @@ const char *get_netpath() { int zt_accept(ACCEPT_SIG) { - //dwr(MSG_DEBUG,"zt_accept(%d):\n", sockfd); + dwr(MSG_DEBUG,"zt_accept(%d):\n", sockfd); +// FIXME: Find a better solution for this before production +#if !defined(__UNITY_3D__) if(addr) addr->sa_family = AF_INET; - +#endif int new_fd = get_new_fd(sockfd); + dwr(MSG_DEBUG,"newfd = %d\n", new_fd); + if(new_fd > 0) { errno = ERR_OK; return new_fd; diff --git a/tests/client.c b/tests/client.c index e79a829..c445a6a 100644 --- a/tests/client.c +++ b/tests/client.c @@ -13,7 +13,7 @@ int main(int argc , char *argv[]) return 1; } - int sock, port = atoi(argv[1]); + int sock, port = atoi(argv[2]); struct sockaddr_in server; char message[1000] , server_reply[2000]; @@ -40,11 +40,15 @@ int main(int argc , char *argv[]) scanf("%s" , message); //Send some data - if(send(sock , message , strlen(message) , 0) < 0) + if(send(sock , "welcome to the machine!" ,24 , 0) < 0) { puts("Send failed"); return 1; } + else + { + printf("len = %d\n", strlen(message)); + } //Receive a reply from the server if(recv(sock , server_reply , 2000 , 0) < 0)