summaryrefslogtreecommitdiff
path: root/one.cpp
diff options
context:
space:
mode:
authorGrant Limberg <[email protected]>2020-09-11 16:43:30 -0700
committerGrant Limberg <[email protected]>2020-09-11 16:43:30 -0700
commit36d867c3faf6604b027a9c35e69c2352c81beb0c (patch)
treec014d8d02217dada91f23d06b46549da3f7d4134 /one.cpp
parent62f23e0cfd5b97dbaeccdd892a1babed7d7942c4 (diff)
more config dump for macOS
Diffstat (limited to 'one.cpp')
-rw-r--r--one.cpp72
1 files changed, 69 insertions, 3 deletions
diff --git a/one.cpp b/one.cpp
index 4b05ef58..6ce37f9a 100644
--- a/one.cpp
+++ b/one.cpp
@@ -78,6 +78,13 @@
#include "ext/json/json.hpp"
+#ifdef __APPLE__
+#include <SystemConfiguration/SystemConfiguration.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <ifaddrs.h>
+#endif
+
#define ZT_PID_PATH "zerotier-one.pid"
using namespace ZeroTier;
@@ -860,10 +867,17 @@ static int cli(int argc,char **argv)
}
} else if (command == "dump") {
std::stringstream dump;
-
+ dump << "platform: ";
+#ifdef __APPLE__
+ dump << "macOS" << ZT_EOL_S;
+#elif defined(_WIN32)
+ dump << "Windows" << ZT_EOL_S;
+#else
+ dump << "other unix based OS" << ZT_EOL_S;
+#endif
dump << "zerotier version: " << ZEROTIER_ONE_VERSION_MAJOR << "."
<< ZEROTIER_ONE_VERSION_MINOR << "." << ZEROTIER_ONE_VERSION_REVISION << ZT_EOL_S << ZT_EOL_S;
-
+
// grab status
dump << "status" << ZT_EOL_S << "------" << ZT_EOL_S;
unsigned int scode = Http::GET(1024 * 1024 * 16,60000,(const struct sockaddr *)&addr,"/status",requestHeaders,responseHeaders,responseBody);
@@ -909,7 +923,59 @@ static int cli(int argc,char **argv)
responseHeaders.clear();
responseBody = "";
- fprintf(stderr, "%s", dump.str().c_str());
+ dump << ZT_EOL_S << "local.conf" << ZT_EOL_S << "----------" << ZT_EOL_S;
+ // TODO: Dump local.conf
+ dump << "TODO" << ZT_EOL_S;
+
+ dump << ZT_EOL_S << "Network Interfaces" << ZT_EOL_S << "------------------" << ZT_EOL_S << ZT_EOL_S;
+#ifdef __APPLE__
+ CFArrayRef interfaces = SCNetworkInterfaceCopyAll();
+ CFIndex size = CFArrayGetCount(interfaces);
+ for(CFIndex i = 0; i < size; ++i) {
+ SCNetworkInterfaceRef iface = (SCNetworkInterfaceRef)CFArrayGetValueAtIndex(interfaces, i);
+
+ dump << "Interface " << i << ZT_EOL_S << "-----------" << ZT_EOL_S;
+ CFStringRef tmp = SCNetworkInterfaceGetBSDName(iface);
+ char stringBuffer[512] = {};
+ CFStringGetCString(tmp,stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
+ dump << "Name: " << stringBuffer << ZT_EOL_S;
+ std::string ifName(stringBuffer);
+ int mtuCur, mtuMin, mtuMax;
+ SCNetworkInterfaceCopyMTU(iface, &mtuCur, &mtuMin, &mtuMax);
+ dump << "MTU: " << mtuCur << ZT_EOL_S;
+ tmp = SCNetworkInterfaceGetHardwareAddressString(iface);
+ CFStringGetCString(tmp, stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
+ dump << "MAC: " << stringBuffer << ZT_EOL_S;
+ tmp = SCNetworkInterfaceGetInterfaceType(iface);
+ CFStringGetCString(tmp, stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
+ dump << "Type: " << stringBuffer << ZT_EOL_S;
+ dump << "Addresses:" << ZT_EOL_S;
+
+ struct ifaddrs *ifap, *ifa;
+ void *addr;
+ getifaddrs(&ifap);
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if (strcmp(ifName.c_str(), ifa->ifa_name) == 0) {
+ if (ifa->ifa_addr->sa_family == AF_INET) {
+ struct sockaddr_in *ipv4 = (struct sockaddr_in*)ifa->ifa_addr;
+ addr = &ipv4->sin_addr;
+ } else if (ifa->ifa_addr->sa_family == AF_INET6) {
+ struct sockaddr_in6 *ipv6 = (struct sockaddr_in6*)ifa->ifa_addr;
+ addr = &ipv6->sin6_addr;
+ } else {
+ continue;
+ }
+ inet_ntop(ifa->ifa_addr->sa_family, addr, stringBuffer, sizeof(stringBuffer));
+ dump << stringBuffer << ZT_EOL_S;
+ }
+ }
+
+ dump << ZT_EOL_S;
+ }
+#endif
+
+ fprintf(stderr, "%s", dump.str().c_str());
+
} else {
cliPrintHelp(argv[0],stderr);
return 0;