From 150a53eb17b18e0a20d85d56437a94aaf745ce2b Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 14 Aug 2013 11:19:21 -0400 Subject: [PATCH] Self test almost builds, now need skeleton EthernetTap implementation for Windows. --- .gitignore | 3 +++ ext/kissdb/kissdb.c | 13 +++++++++++- node/Demarc.cpp | 4 ++-- node/Demarc.hpp | 4 ++-- node/Node.cpp | 2 +- node/Utils.cpp | 6 +++--- node/Utils.hpp | 2 +- selftest.cpp | 10 +++++++++- vsprojects/SelfTest/SelfTest.cpp | 11 ---------- vsprojects/SelfTest/SelfTest.vcxproj | 13 ++++++------ vsprojects/SelfTest/SelfTest.vcxproj.filters | 21 +++++++++++--------- vsprojects/SelfTest/stdafx.cpp | 8 -------- vsprojects/SelfTest/stdafx.h | 15 -------------- 13 files changed, 51 insertions(+), 61 deletions(-) delete mode 100644 vsprojects/SelfTest/SelfTest.cpp delete mode 100644 vsprojects/SelfTest/stdafx.cpp delete mode 100644 vsprojects/SelfTest/stdafx.h diff --git a/.gitignore b/.gitignore index c27c197b7..78bab478e 100755 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ mac-tap/tuntap/tap.kext /ipch /ZeroTierOne.v11.suo /ZeroTierOne.opensdf +/vsprojects/SelfTest/Debug +/vsprojects/SelfTest/SelfTest.vcxproj.user +/Debug diff --git a/ext/kissdb/kissdb.c b/ext/kissdb/kissdb.c index ab33a5b36..28346a474 100644 --- a/ext/kissdb/kissdb.c +++ b/ext/kissdb/kissdb.c @@ -47,10 +47,21 @@ int KISSDB_open( uint64_t *httmp; uint64_t *hash_tables_rea; +#ifdef _WIN32 + db->f = (FILE *)0; + fopen_s(&db->f,path,((mode == KISSDB_OPEN_MODE_RWREPLACE) ? "w+b" : (((mode == KISSDB_OPEN_MODE_RDWR)||(mode == KISSDB_OPEN_MODE_RWCREAT)) ? "r+b" : "rb"))); +#else db->f = fopen(path,((mode == KISSDB_OPEN_MODE_RWREPLACE) ? "w+b" : (((mode == KISSDB_OPEN_MODE_RDWR)||(mode == KISSDB_OPEN_MODE_RWCREAT)) ? "r+b" : "rb"))); +#endif if (!db->f) { - if (mode == KISSDB_OPEN_MODE_RWCREAT) + if (mode == KISSDB_OPEN_MODE_RWCREAT) { +#ifdef _WIN32 + db->f = (FILE *)0; + fopen_s(&db->f,path,"w+b"); +#else db->f = fopen(path,"w+b"); +#endif + } if (!db->f) return KISSDB_ERROR_IO; } diff --git a/node/Demarc.cpp b/node/Demarc.cpp index 9c78fb655..0bb1646d4 100644 --- a/node/Demarc.cpp +++ b/node/Demarc.cpp @@ -44,8 +44,8 @@ namespace ZeroTier { -const Demarc::Port Demarc::ANY_PORT; -const Demarc::Port Demarc::NULL_PORT; +const Demarc::Port Demarc::ANY_PORT = (Port)0xffffffffffffffffULL; +const Demarc::Port Demarc::NULL_PORT = (Port)0; Demarc::Demarc(const RuntimeEnvironment *renv) : _r(renv) diff --git a/node/Demarc.hpp b/node/Demarc.hpp index 721dc0c8c..670e5b0a8 100644 --- a/node/Demarc.hpp +++ b/node/Demarc.hpp @@ -64,12 +64,12 @@ public: /** * Port identifier used to refer to any port */ - static const Port ANY_PORT = (Port)0xffffffffffffffffULL; + static const Port ANY_PORT; /** * Port identifier used to refer to null port / port not found */ - static const Port NULL_PORT = (Port)0; + static const Port NULL_PORT; Demarc(const RuntimeEnvironment *renv); ~Demarc(); diff --git a/node/Node.cpp b/node/Node.cpp index e6910a567..bb68cdaf3 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -351,7 +351,7 @@ Node::ReasonForTermination Node::run() // Make sure networks.d exists #ifdef __WINDOWS__ - CreateDirectory((_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str(),NULL); + CreateDirectoryA((_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str(),NULL); #else mkdir((_r->homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str(),0700); #endif diff --git a/node/Utils.cpp b/node/Utils.cpp index 4f04fb0c7..32cfe2d16 100644 --- a/node/Utils.cpp +++ b/node/Utils.cpp @@ -220,11 +220,11 @@ std::map Utils::listDirectory(const char *path) #ifdef __WINDOWS__ HANDLE hFind; - WIN32_FIND_DATA ffd; - if ((hFind = FindFirstFile((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) { + WIN32_FIND_DATAA ffd; + if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) { do { r[std::string(ffd.cFileName)] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); - } while (FindNextFile(hFind,&ffd)); + } while (FindNextFileA(hFind,&ffd)); FindClose(hFind); } #else diff --git a/node/Utils.hpp b/node/Utils.hpp index 9d5656360..764482946 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -75,7 +75,7 @@ public: throw() { #ifdef __WINDOWS__ - return (DeleteFile(path) != FALSE); + return (DeleteFileA(path) != FALSE); #else return (unlink(path) == 0); #endif diff --git a/selftest.cpp b/selftest.cpp index 0792c1eea..305b9fadd 100644 --- a/selftest.cpp +++ b/selftest.cpp @@ -51,6 +51,10 @@ #include +#ifdef __WINDOWS__ +#include +#endif + using namespace ZeroTier; // --------------------------------------------------------------------------- @@ -394,12 +398,16 @@ static int testRateLimiter() return 0; } +#ifdef __WINDOWS__ +int _tmain(int argc, _TCHAR* argv[]) +#else int main(int argc,char **argv) +#endif { int r = 0; _initLibCrypto(); - srand(time(0)); + srand((unsigned int)time(0)); r |= testCrypto(); r |= testPacket(); diff --git a/vsprojects/SelfTest/SelfTest.cpp b/vsprojects/SelfTest/SelfTest.cpp deleted file mode 100644 index 60a736c5b..000000000 --- a/vsprojects/SelfTest/SelfTest.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// SelfTest.cpp : Defines the entry point for the console application. -// - -#include "stdafx.h" - - -int _tmain(int argc, _TCHAR* argv[]) -{ - return 0; -} - diff --git a/vsprojects/SelfTest/SelfTest.vcxproj b/vsprojects/SelfTest/SelfTest.vcxproj index b8e231414..0be2d7397 100644 --- a/vsprojects/SelfTest/SelfTest.vcxproj +++ b/vsprojects/SelfTest/SelfTest.vcxproj @@ -47,7 +47,7 @@ - Use + NotUsing Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) @@ -57,6 +57,7 @@ Console true + $(SolutionDir)\ext\bin\libcrypto\win32-vs2012\libeay32.lib;wsock32.lib;%(AdditionalDependencies) @@ -119,10 +120,12 @@ - + + + @@ -145,11 +148,7 @@ - - - Create - Create - + diff --git a/vsprojects/SelfTest/SelfTest.vcxproj.filters b/vsprojects/SelfTest/SelfTest.vcxproj.filters index f84bfebb2..3704863eb 100644 --- a/vsprojects/SelfTest/SelfTest.vcxproj.filters +++ b/vsprojects/SelfTest/SelfTest.vcxproj.filters @@ -15,9 +15,6 @@ - - Header Files - Header Files @@ -149,12 +146,6 @@ - - Source Files - - - Source Files - Source Files @@ -221,5 +212,17 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/vsprojects/SelfTest/stdafx.cpp b/vsprojects/SelfTest/stdafx.cpp deleted file mode 100644 index c502d9feb..000000000 --- a/vsprojects/SelfTest/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : source file that includes just the standard includes -// SelfTest.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/vsprojects/SelfTest/stdafx.h b/vsprojects/SelfTest/stdafx.h deleted file mode 100644 index b005a839d..000000000 --- a/vsprojects/SelfTest/stdafx.h +++ /dev/null @@ -1,15 +0,0 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#include "targetver.h" - -#include -#include - - - -// TODO: reference additional headers your program requires here