tweaks for Windows cmake build

This commit is contained in:
joseph.henry
2018-01-30 17:27:40 -08:00
parent cc52c3c59c
commit 2c5634343a
15 changed files with 336 additions and 267 deletions

View File

@@ -25,21 +25,19 @@
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include <inttypes.h>
#if defined(__linux__) || defined(__APPLE__)
#if defined(_WIN32)
#include <WinSock2.h>
#include <stdint.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#include <WinSock2.h>
#include <stdint.h>
#include <unistd.h>
#endif
#include "libzt.h"
@@ -75,13 +73,13 @@ int main(int argc, char **argv)
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", nodeId);
sleep(5);
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0)
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
}
if ((err = zts_connect(sockfd, (const struct sockaddr *)&in6, sizeof(in6))) < 0)
if ((err = zts_connect(sockfd, (const struct sockaddr *)&in6, sizeof(in6))) < 0) {
DEBUG_ERROR("error connecting to remote host (%d)", err);
}
DEBUG_TEST("sending to server...");
w = zts_write(sockfd, msg, strlen(msg));

View File

@@ -25,20 +25,19 @@
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include <inttypes.h>
#if defined(__linux__) || defined(__APPLE__)
#if defined(_WIN32)
#include <WinSock2.h>
#include <stdint.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#include <WinSock2.h>
#include <stdint.h>
#include <unistd.h>
#endif
#include "libzt.h"
@@ -71,18 +70,22 @@ int main(int argc, char **argv)
uint64_t nodeId = zts_get_node_id();
DEBUG_TEST("I am %llx", nodeId);
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0)
if ((sockfd = zts_socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
DEBUG_ERROR("error creating ZeroTier socket");
}
if ((err = zts_bind(sockfd, (struct sockaddr *)&in6, sizeof(struct sockaddr_in6)) < 0))
if ((err = zts_bind(sockfd, (struct sockaddr *)&in6, sizeof(struct sockaddr_in6)) < 0)) {
DEBUG_ERROR("error binding to interface (%d)", err);
}
if ((err = zts_listen(sockfd, 100)) < 0)
if ((err = zts_listen(sockfd, 100)) < 0) {
DEBUG_ERROR("error placing socket in LISTENING state (%d)", err);
}
socklen_t client_addrlen = sizeof(sockaddr_in6);
if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in6, &client_addrlen)) < 0)
if ((accfd = zts_accept(sockfd, (struct sockaddr *)&acc_in6, &client_addrlen)) < 0) {
DEBUG_ERROR("error accepting connection (%d)", err);
}
socklen_t peer_addrlen = sizeof(struct sockaddr_storage);
zts_getpeername(accfd, (struct sockaddr*)&acc_in6, &peer_addrlen);