From cff315298595f9ef3c3e5975a21e8c45090969c3 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 16 Sep 2020 10:03:03 -0700 Subject: [PATCH] windows create dump file on desktop --- one.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/one.cpp b/one.cpp index 500553a8d..9005596ff 100644 --- a/one.cpp +++ b/one.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "osdep/WindowsEthernetTap.hpp" #include "windows/ZeroTierOne/ServiceInstaller.h" #include "windows/ZeroTierOne/ServiceBase.h" @@ -1076,6 +1077,41 @@ static int cli(int argc,char **argv) free(addresses); addresses = NULL; } + + char path[MAX_PATH + 1] = {}; + if (SHGetFolderPathA(NULL, CSIDL_DESKTOP, NULL, 0, path) == S_OK) { + sprintf(path, "%s%szerotier_dump.txt", path, ZT_PATH_SEPARATOR_S); + fprintf(stdout, "Writing dump to: %s\n", path); + HANDLE file = CreateFileA( + path, + GENERIC_WRITE, + 0, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + if (file == INVALID_HANDLE_VALUE) { + fprintf(stdout, "%s", dump.str().c_str()); + return 0; + } + + BOOL err = WriteFile( + file, + dump.str().c_str(), + dump.str().size(), + NULL, + NULL + ); + if (err = FALSE) { + fprintf(stderr, "Error writing file"); + return 1; + } + CloseHandle(file); + } + else { + fprintf(stdout, "%s", dump.str().c_str()); + } #elif defined(__LINUX__) struct ifreq ifr; struct ifconf ifc;