diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-12-19 15:18:20 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-12-19 15:18:20 -0800 |
commit | f60dfe496325bfe5d58b3db75e86387799b72c25 (patch) | |
tree | a9e2cb53d5accbca0f7e61efa35a5c53e9fbd9cf /osnet | |
parent | 536bcf6505e19dc16cad025b32a385325410fb30 (diff) | |
download | infinitytier-f60dfe496325bfe5d58b3db75e86387799b72c25.tar.gz infinitytier-f60dfe496325bfe5d58b3db75e86387799b72c25.zip |
FreeBSD works, and some documentation fixes.
Diffstat (limited to 'osnet')
-rw-r--r-- | osnet/BSDEthernetTap.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/osnet/BSDEthernetTap.cpp b/osnet/BSDEthernetTap.cpp index 8b28510d..100fb171 100644 --- a/osnet/BSDEthernetTap.cpp +++ b/osnet/BSDEthernetTap.cpp @@ -117,10 +117,11 @@ BSDEthernetTap::BSDEthernetTap( // On BSD we create taps and they can have high numbers, so use ones starting // at 9993 to not conflict with other stuff. Then we rename it to zt<base32 of nwid> - for(int i=9993;i<500;++i) { + std::map<std::string,bool> devFiles(Utils::listDirectory("/dev")); + for(int i=9993;i<(9993+128);++i) { Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i); Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname); - if (stat(devpath,&stattmp)) { + if (devFiles.count(std::string(tmpdevname)) == 0) { long cpid = (long)vfork(); if (cpid == 0) { ::execl("/sbin/ifconfig","/sbin/ifconfig",tmpdevname,"create",(const char *)0); @@ -146,6 +147,8 @@ BSDEthernetTap::BSDEthernetTap( if (_fd > 0) break; else throw std::runtime_error("unable to open created tap device"); + } else { + throw std::runtime_error("cannot find /dev node for newly created tap device"); } } } @@ -190,6 +193,15 @@ BSDEthernetTap::~BSDEthernetTap() ::close(_fd); ::close(_shutdownSignalPipe[0]); ::close(_shutdownSignalPipe[1]); + + long cpid = (long)vfork(); + if (cpid == 0) { + ::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0); + ::_exit(-1); + } else if (cpid > 0) { + int exitcode = -1; + ::waitpid(cpid,&exitcode,0); + } } void BSDEthernetTap::setEnabled(bool en) |