summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-18 12:44:27 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-18 12:44:27 -0700
commitbd63a840c79c9960dc47e9edf7b86cbaea45ca94 (patch)
treeb406dbc46b67f093609b55ba9221a642940d76a3 /osdep
parentaaf597f0205b79c0f1d8523f15c8d8aaecb63f43 (diff)
downloadinfinitytier-bd63a840c79c9960dc47e9edf7b86cbaea45ca94.tar.gz
infinitytier-bd63a840c79c9960dc47e9edf7b86cbaea45ca94.zip
Mac build fix.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/OSXEthernetTap.cpp51
1 files changed, 35 insertions, 16 deletions
diff --git a/osdep/OSXEthernetTap.cpp b/osdep/OSXEthernetTap.cpp
index 35eac05a..e8b85964 100644
--- a/osdep/OSXEthernetTap.cpp
+++ b/osdep/OSXEthernetTap.cpp
@@ -352,20 +352,32 @@ OSXEthernetTap::OSXEthernetTap(
}
// 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;
- std::string devmapbuf;
- Dictionary<8194> devmap;
- if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
- devmap.load(devmapbuf.c_str());
- char desiredDevice[128];
- if (devmap.get(nwids,desiredDevice,sizeof(desiredDevice)) > 0) {
- Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice);
- if (stat(devpath,&stattmp) == 0) {
- _fd = ::open(devpath,O_RDWR);
- if (_fd > 0) {
- _dev = desiredDevice;
- recalledDevice = true;
- }
+ std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
+ if (gdmEntry != globalDeviceMap.end()) {
+ std::string devpath("/dev/"); devpath.append(gdmEntry->second);
+ if (stat(devpath.c_str(),&stattmp) == 0) {
+ _fd = ::open(devpath.c_str(),O_RDWR);
+ if (_fd > 0) {
+ _dev = gdmEntry->second;
+ recalledDevice = true;
}
}
}
@@ -420,9 +432,16 @@ OSXEthernetTap::OSXEthernetTap(
++globalTapsRunning;
- devmap.erase(nwids);
- devmap.add(nwids,_dev.c_str());
- OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),(const void *)devmap.data(),devmap.sizeBytes());
+ globalDeviceMap[nwids] = _dev;
+ devmapf = fopen((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),"w");
+ 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);
}