Browse Source

macos output dump to file if possible

if not, write to stdout
Grant Limberg 4 years ago
parent
commit
927aeb15f6
1 changed files with 28 additions and 0 deletions
  1. 28 0
      one.cpp

+ 28 - 0
one.cpp

@@ -87,6 +87,7 @@
 
 
 #ifdef __APPLE__
 #ifdef __APPLE__
 #include <SystemConfiguration/SystemConfiguration.h>
 #include <SystemConfiguration/SystemConfiguration.h>
+#include <CoreServices/CoreServices.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <ifaddrs.h>
 #include <ifaddrs.h>
@@ -879,6 +880,8 @@ static int cli(int argc,char **argv)
 		dump << "macOS" << ZT_EOL_S;
 		dump << "macOS" << ZT_EOL_S;
 #elif defined(_WIN32)
 #elif defined(_WIN32)
 		dump << "Windows" << ZT_EOL_S;
 		dump << "Windows" << ZT_EOL_S;
+#elif defined(__LINUX__)
+		dump << "Linux" << ZT_EOL_S;
 #else
 #else
 		dump << "other unix based OS" << ZT_EOL_S;
 		dump << "other unix based OS" << ZT_EOL_S;
 #endif
 #endif
@@ -985,6 +988,30 @@ static int cli(int argc,char **argv)
 
 
 			dump << ZT_EOL_S;
 			dump << ZT_EOL_S;
 		}
 		}
+
+
+		FSRef fsref;
+		UInt8 path[PATH_MAX];
+		if (FSFindFolder(kUserDomain, kDesktopFolderType, kDontCreateFolder, &fsref) == noErr &&
+				FSRefMakePath(&fsref, path, sizeof(path)) == noErr) {
+			
+		} else if (getenv("SUDO_USER")) {
+			sprintf((char*)path, "/Users/%s/Desktop/", getenv("SUDO_USER"));
+		} else {
+			fprintf(stdout, "%s", dump.str().c_str());
+			return 0;
+		}
+
+		sprintf((char*)path, "%s%szerotier_dump.txt", (char*)path, ZT_PATH_SEPARATOR_S);
+
+		fprintf(stdout, "Writing dump to: %s\n", path);
+		int fd = open((char*)path, O_CREAT|O_RDWR,0664);
+		if (fd == -1) {
+			fprintf(stderr, "Error creating file.\n");
+			return 1;
+		}
+		write(fd, dump.str().c_str(), dump.str().size());	
+		close(fd);
 #elif defined(_WIN32)
 #elif defined(_WIN32)
 		ULONG buffLen = 16384;
 		ULONG buffLen = 16384;
 		PIP_ADAPTER_ADDRESSES addresses;
 		PIP_ADAPTER_ADDRESSES addresses;
@@ -1118,6 +1145,7 @@ static int cli(int argc,char **argv)
 		int fd = open(cwd, O_CREAT|O_RDWR,0664);
 		int fd = open(cwd, O_CREAT|O_RDWR,0664);
 		if (fd == -1) {
 		if (fd == -1) {
 			fprintf(stderr, "Error creating file.\n");
 			fprintf(stderr, "Error creating file.\n");
+			return 1;
 		}
 		}
 		write(fd, dump.str().c_str(), dump.str().size());	
 		write(fd, dump.str().c_str(), dump.str().size());	
 		close(fd);
 		close(fd);