summaryrefslogtreecommitdiff
path: root/osdep/LinuxEthernetTap.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-18 12:48:56 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-18 12:48:56 -0700
commit48cadcd2fcd95d39db28b15ceb0c79e6dbc80611 (patch)
tree444d2b3140cb9427af998496f2326425fd38ae5c /osdep/LinuxEthernetTap.cpp
parentbd63a840c79c9960dc47e9edf7b86cbaea45ca94 (diff)
downloadinfinitytier-48cadcd2fcd95d39db28b15ceb0c79e6dbc80611.tar.gz
infinitytier-48cadcd2fcd95d39db28b15ceb0c79e6dbc80611.zip
More build fixes.
Diffstat (limited to 'osdep/LinuxEthernetTap.cpp')
-rw-r--r--osdep/LinuxEthernetTap.cpp47
1 files changed, 33 insertions, 14 deletions
diff --git a/osdep/LinuxEthernetTap.cpp b/osdep/LinuxEthernetTap.cpp
index c4b978e7..f74efc0a 100644
--- a/osdep/LinuxEthernetTap.cpp
+++ b/osdep/LinuxEthernetTap.cpp
@@ -93,19 +93,31 @@ LinuxEthernetTap::LinuxEthernetTap(
memset(&ifr,0,sizeof(ifr));
// Try to recall our last device name, or pick an unused one if that fails.
- 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::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),desiredDevice);
- Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
- recalledDevice = (stat(procpath,&sbuf) != 0);
+ 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;
}
+ 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) {
int devno = 0;
do {
@@ -179,9 +191,16 @@ LinuxEthernetTap::LinuxEthernetTap(
(void)::pipe(_shutdownSignalPipe);
- 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);
}