Windows Support

This commit is contained in:
Joseph Henry
2017-10-09 17:56:40 -07:00
parent 06a09edd6d
commit 2900f1f995
28 changed files with 486 additions and 241 deletions

View File

@@ -26,12 +26,17 @@
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#if defined(__linux__) || defined(__APPLE__)
#include <netdb.h>
#endif
//#include "Winsock2.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <fcntl.h>
#include <regex.h>
#include <vector>
#include <algorithm>
@@ -39,6 +44,7 @@
#include "RingBuffer.hpp"
#include "ztproxy.hpp"
#include "Utilities.h"
#include "libzt.h"
namespace ZeroTier {
@@ -69,7 +75,11 @@ namespace ZeroTier {
in4.sin_addr.s_addr = Utils::hton((uint32_t)(0x7f000001)); // listen for TCP @127.0.0.1
in4.sin_port = Utils::hton((uint16_t)proxy_listen_port);
_tcpListenSocket = _phy.tcpListen((const struct sockaddr *)&in4,this);
if (!_tcpListenSocket) {
DEBUG_ERROR("Error binding on port %d for IPv4 HTTP listen socket", proxy_listen_port);
}
// IPv6
/*
struct sockaddr_in6 in6;
memset((void *)&in6,0,sizeof(in6));
in6.sin6_family = AF_INET6;
@@ -77,13 +87,12 @@ namespace ZeroTier {
in6.sin6_addr.s6_addr[15] = 1; // IPv6 localhost == ::1
in6.sin6_port = Utils::hton((uint16_t)proxy_listen_port);
_tcpListenSocket6 = _phy.tcpListen((const struct sockaddr *)&in6,this);
if (!_tcpListenSocket) {
DEBUG_ERROR("Error binding on port %d for IPv4 HTTP listen socket", proxy_listen_port);
}
*/
/*
if (!_tcpListenSocket6) {
DEBUG_ERROR("Error binding on port %d for IPv6 HTTP listen socket", proxy_listen_port);
}
*/
_thread = Thread::start(this);
}
@@ -117,7 +126,7 @@ namespace ZeroTier {
// Moves data between client application socket and libzt VirtualSocket
while(_run) {
_phy.poll(5);
_phy.poll(1);
conn_m.lock();
// build fd_sets to select upon
@@ -212,7 +221,6 @@ namespace ZeroTier {
exit(0);
}
if (conn->zfd < 0) { // no connection yet
DEBUG_INFO("no connection yet, will establish...");
if (host == "") {
DEBUG_ERROR("invalid hostname or address (empty)");
return;
@@ -256,6 +264,7 @@ namespace ZeroTier {
}
if (ipv == 6) {
//DEBUG_INFO("attempting to proxy [0.0.0.0:%d -> %s:%d]", _proxy_listen_port, host.c_str(), dest_port);
/*
struct sockaddr_in6 in6;
memset(&in6,0,sizeof(in6));
in6.sin6_family = AF_INET;
@@ -265,6 +274,7 @@ namespace ZeroTier {
in6.sin6_port = Utils::hton(dest_port);
zfd = zts_socket(AF_INET, SOCK_STREAM, 0);
err = zts_connect(zfd, (const struct sockaddr *)&in6, sizeof(in6));
*/
}
if (zfd < 0 || err < 0) {
// now release TX buffer contents we previously saved, since we can't connect
@@ -287,9 +297,6 @@ namespace ZeroTier {
zmap[zfd] = conn;
conn_m.unlock();
}
else {
DEBUG_INFO("connection already established, reusing...");
}
// Write data coming from client TCP connection to its TX buffer, later emptied into libzt by threadMain I/O loop
conn->tx_m.lock();
if ((wr = conn->TXbuf->write((const unsigned char *)data, len)) < 0) {
@@ -371,7 +378,7 @@ int main(int argc, char **argv)
std::string nwid = argv[3];
std::string internal_addr = argv[4];
int internal_port = atoi(argv[5]);
std::string dns_nameserver= argv[6];
std::string dns_nameserver= "";//argv[6];
ZeroTier::ZTProxy *proxy = new ZeroTier::ZTProxy(proxy_listen_port, nwid, path, internal_addr, internal_port, dns_nameserver);