mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-21 09:48:07 +00:00
Mac build fix.
This commit is contained in:
parent
aaf597f020
commit
bd63a840c7
@ -352,20 +352,32 @@ OSXEthernetTap::OSXEthernetTap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to reopen the last device we had, if we had one and it's still unused.
|
// Try to reopen the last device we had, if we had one and it's still unused.
|
||||||
|
std::map<std::string,std::string> globalDeviceMap;
|
||||||
|
FILE *devmapf = fopen((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),"r");
|
||||||
|
if (devmapf) {
|
||||||
|
char buf[256];
|
||||||
|
while (fgets(buf,sizeof(buf),devmapf)) {
|
||||||
|
char *x = (char *)0;
|
||||||
|
char *y = (char *)0;
|
||||||
|
char *saveptr = (char *)0;
|
||||||
|
for(char *f=Utils::stok(buf,"\r\n=",&saveptr);(f);f=Utils::stok((char *)0,"\r\n=",&saveptr)) {
|
||||||
|
if (!x) x = f;
|
||||||
|
else if (!y) y = f;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
if ((x)&&(y)&&(x[0])&&(y[0]))
|
||||||
|
globalDeviceMap[x] = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
bool recalledDevice = false;
|
bool recalledDevice = false;
|
||||||
std::string devmapbuf;
|
std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
|
||||||
Dictionary<8194> devmap;
|
if (gdmEntry != globalDeviceMap.end()) {
|
||||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
std::string devpath("/dev/"); devpath.append(gdmEntry->second);
|
||||||
devmap.load(devmapbuf.c_str());
|
if (stat(devpath.c_str(),&stattmp) == 0) {
|
||||||
char desiredDevice[128];
|
_fd = ::open(devpath.c_str(),O_RDWR);
|
||||||
if (devmap.get(nwids,desiredDevice,sizeof(desiredDevice)) > 0) {
|
if (_fd > 0) {
|
||||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice);
|
_dev = gdmEntry->second;
|
||||||
if (stat(devpath,&stattmp) == 0) {
|
recalledDevice = true;
|
||||||
_fd = ::open(devpath,O_RDWR);
|
|
||||||
if (_fd > 0) {
|
|
||||||
_dev = desiredDevice;
|
|
||||||
recalledDevice = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -420,9 +432,16 @@ OSXEthernetTap::OSXEthernetTap(
|
|||||||
|
|
||||||
++globalTapsRunning;
|
++globalTapsRunning;
|
||||||
|
|
||||||
devmap.erase(nwids);
|
globalDeviceMap[nwids] = _dev;
|
||||||
devmap.add(nwids,_dev.c_str());
|
devmapf = fopen((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),"w");
|
||||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),(const void *)devmap.data(),devmap.sizeBytes());
|
if (devmapf) {
|
||||||
|
gdmEntry = globalDeviceMap.begin();
|
||||||
|
while (gdmEntry != globalDeviceMap.end()) {
|
||||||
|
fprintf(devmapf,"%s=%s\n",gdmEntry->first.c_str(),gdmEntry->second.c_str());
|
||||||
|
++gdmEntry;
|
||||||
|
}
|
||||||
|
fclose(devmapf);
|
||||||
|
}
|
||||||
|
|
||||||
_thread = Thread::start(this);
|
_thread = Thread::start(this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user