more config dump for macOS

This commit is contained in:
Grant Limberg 2020-09-11 16:43:30 -07:00
parent 62f23e0cfd
commit 36d867c3fa
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A

68
one.cpp
View File

@ -78,6 +78,13 @@
#include "ext/json/json.hpp" #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" #define ZT_PID_PATH "zerotier-one.pid"
using namespace ZeroTier; using namespace ZeroTier;
@ -860,7 +867,14 @@ static int cli(int argc,char **argv)
} }
} else if (command == "dump") { } else if (command == "dump") {
std::stringstream 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 << "." dump << "zerotier version: " << ZEROTIER_ONE_VERSION_MAJOR << "."
<< ZEROTIER_ONE_VERSION_MINOR << "." << ZEROTIER_ONE_VERSION_REVISION << ZT_EOL_S << ZT_EOL_S; << ZEROTIER_ONE_VERSION_MINOR << "." << ZEROTIER_ONE_VERSION_REVISION << ZT_EOL_S << ZT_EOL_S;
@ -909,7 +923,59 @@ static int cli(int argc,char **argv)
responseHeaders.clear(); responseHeaders.clear();
responseBody = ""; responseBody = "";
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()); fprintf(stderr, "%s", dump.str().c_str());
} else { } else {
cliPrintHelp(argv[0],stderr); cliPrintHelp(argv[0],stderr);
return 0; return 0;