mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
More build fixes.
This commit is contained in:
parent
bd63a840c7
commit
48cadcd2fc
2 changed files with 34 additions and 14 deletions
|
@ -93,19 +93,31 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
memset(&ifr,0,sizeof(ifr));
|
memset(&ifr,0,sizeof(ifr));
|
||||||
|
|
||||||
// Try to recall our last device name, or pick an unused one if that fails.
|
// Try to recall our last device name, or pick an unused one if that fails.
|
||||||
bool recalledDevice = false;
|
std::map<std::string,std::string> globalDeviceMap;
|
||||||
std::string devmapbuf;
|
FILE *devmapf = fopen((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),"r");
|
||||||
Dictionary<8194> devmap;
|
if (devmapf) {
|
||||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
char buf[256];
|
||||||
devmap.load(devmapbuf.c_str());
|
while (fgets(buf,sizeof(buf),devmapf)) {
|
||||||
char desiredDevice[128];
|
char *x = (char *)0;
|
||||||
if (devmap.get(nwids,desiredDevice,sizeof(desiredDevice)) > 0) {
|
char *y = (char *)0;
|
||||||
Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),desiredDevice);
|
char *saveptr = (char *)0;
|
||||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
for(char *f=Utils::stok(buf,"\r\n=",&saveptr);(f);f=Utils::stok((char *)0,"\r\n=",&saveptr)) {
|
||||||
recalledDevice = (stat(procpath,&sbuf) != 0);
|
if (!x) x = f;
|
||||||
|
else if (!y) y = f;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
if ((x)&&(y)&&(x[0])&&(y[0]))
|
||||||
|
globalDeviceMap[x] = y;
|
||||||
}
|
}
|
||||||
|
fclose(devmapf);
|
||||||
|
}
|
||||||
|
bool recalledDevice = false;
|
||||||
|
std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
|
||||||
|
if (gdmEntry != globalDeviceMap.end()) {
|
||||||
|
Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),gdmEntry->second.c_str());
|
||||||
|
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||||
|
recalledDevice = (stat(procpath,&sbuf) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!recalledDevice) {
|
if (!recalledDevice) {
|
||||||
int devno = 0;
|
int devno = 0;
|
||||||
do {
|
do {
|
||||||
|
@ -179,9 +191,16 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
|
|
||||||
(void)::pipe(_shutdownSignalPipe);
|
(void)::pipe(_shutdownSignalPipe);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,6 +368,7 @@ OSXEthernetTap::OSXEthernetTap(
|
||||||
if ((x)&&(y)&&(x[0])&&(y[0]))
|
if ((x)&&(y)&&(x[0])&&(y[0]))
|
||||||
globalDeviceMap[x] = y;
|
globalDeviceMap[x] = y;
|
||||||
}
|
}
|
||||||
|
fclose(devmapf);
|
||||||
}
|
}
|
||||||
bool recalledDevice = false;
|
bool recalledDevice = false;
|
||||||
std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
|
std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
|
||||||
|
|
Loading…
Add table
Reference in a new issue