diff --git a/tests/shared_test/zts.udpclient6.c b/tests/shared_test/zts.udpclient6.c deleted file mode 100755 index a500fb9..0000000 --- a/tests/shared_test/zts.udpclient6.c +++ /dev/null @@ -1,48 +0,0 @@ -// 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.tcpclient4.c b/tests/zts/zts.tcpclient4.c similarity index 80% rename from tests/shared_test/zts.tcpclient4.c rename to tests/zts/zts.tcpclient4.c index eac783b..e6557f0 100644 --- a/tests/shared_test/zts.tcpclient4.c +++ b/tests/zts/zts.tcpclient4.c @@ -4,8 +4,8 @@ #include #include #include - #include + #include "sdk.h" int atoi(const char *str); @@ -19,8 +19,14 @@ int main(int argc , char *argv[]) printf("usage: client \n"); return 1; } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ zts_init_rpc(argv[3],argv[4]); - + int sock, port = atoi(argv[2]); struct sockaddr_in server; char server_reply[MSG_SZ]; diff --git a/tests/shared_test/zts.tcpclient6.c b/tests/zts/zts.tcpclient6.c similarity index 77% rename from tests/shared_test/zts.tcpclient6.c rename to tests/zts/zts.tcpclient6.c index b39f48a..98fb198 100644 --- a/tests/shared_test/zts.tcpclient6.c +++ b/tests/zts/zts.tcpclient6.c @@ -4,13 +4,12 @@ #include #include #include - #include #include #include #include - #include + #include "sdk.h" void error(char *msg) { @@ -24,10 +23,18 @@ int main(int argc, char *argv[]) { struct hostent *server; char buffer[256] = "This is a string from client!"; - if (argc < 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(0); + if(argc < 3) { + printf("usage: client \n"); + return 1; } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ + zts_init_rpc(argv[3],argv[4]); + portno = atoi(argv[2]); printf("\nIPv6 TCP Client Started...\n"); diff --git a/tests/shared_test/zts.tcpserver4.c b/tests/zts/zts.tcpserver4.c similarity index 78% rename from tests/shared_test/zts.tcpserver4.c rename to tests/zts/zts.tcpserver4.c index 9fe94d3..9241874 100644 --- a/tests/shared_test/zts.tcpserver4.c +++ b/tests/zts/zts.tcpserver4.c @@ -4,8 +4,8 @@ #include #include #include - #include + #include "sdk.h" int atoi(const char *str); @@ -13,9 +13,15 @@ int atoi(const char *str); int main(int argc , char *argv[]) { if(argc < 3) { - printf("usage: client \n"); + printf("usage: server \n"); return 1; } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ zts_init_rpc(argv[2],argv[3]); int sock, client_sock, c, read_size, port = atoi(argv[1]); diff --git a/tests/shared_test/zts.tcpserver6.c b/tests/zts/zts.tcpserver6.c similarity index 81% rename from tests/shared_test/zts.tcpserver6.c rename to tests/zts/zts.tcpserver6.c index 1d20b78..973f7e4 100644 --- a/tests/shared_test/zts.tcpserver6.c +++ b/tests/zts/zts.tcpserver6.c @@ -29,9 +29,15 @@ int main(int argc, char *argv[]) { char client_addr_ipv6[100]; if(argc < 3) { - printf("usage: client \n"); + printf("usage: server \n"); return 1; } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ zts_init_rpc(argv[2],argv[3]); printf("\nIPv6 TCP Server Started...\n"); diff --git a/tests/shared_test/zts.udpclient4.c b/tests/zts/zts.udpclient4.c similarity index 84% rename from tests/shared_test/zts.udpclient4.c rename to tests/zts/zts.udpclient4.c index 7e73206..ecbc200 100755 --- a/tests/shared_test/zts.udpclient4.c +++ b/tests/zts/zts.udpclient4.c @@ -9,15 +9,12 @@ #include #include #include - #include + #include "sdk.h" #define BUFSIZE 1024 -/* - * error - wrapper for perror - */ void error(char *msg) { perror(msg); exit(0); @@ -36,6 +33,14 @@ int main(int argc, char **argv) { fprintf(stderr,"usage: %s \n", argv[0]); exit(0); } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ + zts_init_rpc(argv[3],argv[4]); + hostname = argv[1]; portno = atoi(argv[2]); diff --git a/tests/zts/zts.udpclient6.c b/tests/zts/zts.udpclient6.c new file mode 100755 index 0000000..447dd09 --- /dev/null +++ b/tests/zts/zts.udpclient6.c @@ -0,0 +1,60 @@ +// UDP Client test program (IPV6) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sdk.h" + +#define MAXBUF 65536 + +int main(int argc, char* argv[]) +{ + int status, sock, portno, n; + struct addrinfo sainfo, *psinfo; + struct hostent *server; + char buffer[MAXBUF]; + struct sockaddr_in6 serv_addr; + + if(argc < 3) { + printf("usage: client \n"); + return 1; + } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ + zts_init_rpc(argv[3],argv[4]); + + sock = zts_socket(AF_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"); + + fcntl(sock, F_SETFL, O_NONBLOCK); + while(1) + { + sleep(1); + status = zts_sendto(sock, buffer, strlen(buffer), 0, (const struct sockaddr *)&serv_addr, sizeof(serv_addr)); + printf("Sent : %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/zts/zts.udpserver4.c similarity index 68% rename from tests/shared_test/zts.udpserver4.c rename to tests/zts/zts.udpserver4.c index 9e60538..a5cab73 100755 --- a/tests/shared_test/zts.udpserver4.c +++ b/tests/zts/zts.udpserver4.c @@ -8,8 +8,8 @@ #include #include #include - #include + #include "sdk.h" #define MAXBUF 1024*1024 @@ -21,11 +21,10 @@ void echo(int sock) { socklen_t len = sizeof(remote); long count = 0; - while (1) { + while(1) { sleep(1); - //usleep(50); count++; - // read a datagram from the socket (put result in bufin) + // read a datagram from the socket n=zts_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)); @@ -33,20 +32,23 @@ void echo(int sock) { 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); + printf("RX (%d bytes) = %s\n", n, bufin); } } } int main(int argc, char *argv[]) { - if(argc < 3) { printf("usage: client \n"); return 1; } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ zts_init_rpc(argv[2],argv[3]); int sock, port = atoi(argv[1]); @@ -70,22 +72,8 @@ int main(int argc, char *argv[]) { } // 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); + return 0; } diff --git a/tests/shared_test/zts.udpserver6.c b/tests/zts/zts.udpserver6.c similarity index 54% rename from tests/shared_test/zts.udpserver6.c rename to tests/zts/zts.udpserver6.c index 7c58144..b4786cc 100755 --- a/tests/shared_test/zts.udpserver6.c +++ b/tests/zts/zts.udpserver6.c @@ -8,27 +8,36 @@ #include #include #include - #include +#include +#include + #include "sdk.h" -#define MAXBUF 65536 +#define MAXBUF 128 int main(int argc, char *argv[]) { if(argc < 3) { - printf("usage: client \n"); + printf("usage: server \n"); return 1; } + + /* Starts ZeroTier core service in separate thread, loads user-space TCP/IP stack + and sets up a private AF_UNIX socket between ZeroTier library and your app. Any + subsequent zts_* socket API calls (shown below) are mediated over this hidden AF_UNIX + socket and are spoofed to appear as AF_INET sockets. The implementation of this API + is in src/sockets.c */ zts_init_rpc(argv[2],argv[3]); - int sock; - int n; + int sock, n; struct sockaddr_in6 sin6; socklen_t sin6len; - char buffer[MAXBUF]; - sock = socket(PF_INET6, SOCK_DGRAM,0); + char buffer[MAXBUF]; + memset(buffer, 0, MAXBUF); + + sock = zts_socket(PF_INET6, SOCK_DGRAM,0); sin6len = sizeof(struct sockaddr_in6); memset(&sin6, 0, sin6len); @@ -36,16 +45,17 @@ int main(int argc, char *argv[]) sin6.sin6_family = AF_INET6; sin6.sin6_addr = in6addr_any; - n = bind(sock, (struct sockaddr *)&sin6, sin6len); + n = zts_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)); + fcntl(sock, F_SETFL, O_NONBLOCK); while (1) { sleep(1); - n = recvfrom(sock, buffer, MAXBUF, 0, (struct sockaddr *)&sin6, &sin6len); + n = zts_recvfrom(sock, buffer, MAXBUF, 0, (struct sockaddr *)&sin6, &sin6len); printf("n = %d, buffer : %s\n", n, buffer); }