From 7475c4047e81cf83f16eed4449ad8408eeaacaec Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 23 Jul 2014 09:14:53 -0700 Subject: A bunch more osdep/ work... --- node/osdep/LinuxEthernetTapFactory.cpp | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 node/osdep/LinuxEthernetTapFactory.cpp (limited to 'node/osdep/LinuxEthernetTapFactory.cpp') diff --git a/node/osdep/LinuxEthernetTapFactory.cpp b/node/osdep/LinuxEthernetTapFactory.cpp new file mode 100644 index 00000000..fccb6bd5 --- /dev/null +++ b/node/osdep/LinuxEthernetTapFactory.cpp @@ -0,0 +1,83 @@ +/* + * ZeroTier One - Global Peer to Peer Ethernet + * Copyright (C) 2011-2014 ZeroTier Networks LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * -- + * + * ZeroTier may be used and distributed under the terms of the GPLv3, which + * are available at: http://www.gnu.org/licenses/gpl-3.0.html + * + * If you would like to embed ZeroTier into a commercial application or + * redistribute it in a modified binary form, please contact ZeroTier Networks + * LLC. Start here: http://www.zerotier.com/ + */ + +#include "LinuxEthernetTapFactory.hpp" +#include "LinuxEthernetTap.hpp" + +namespace ZeroTier { + +LinuxEthernetTapFactory::LinuxEthernetTapFactory() +{ +} + +LinuxEthernetTapFactory::~LinuxEthernetTapFactory() +{ + Mutex::Lock _l(_devices_m); + for(std::vector::iterator d(_devices.begin());d!=_devices.end();++d) + delete *d; +} + +EthernetTap *LinuxEthernetTapFactory::open( + const MAC &mac, + unsigned int mtu, + unsigned int metric, + uint64_t nwid, + const char *desiredDevice, + const char *friendlyName, + void (*handler)(void *,const MAC &,const MAC &,unsigned int,const Buffer<4096> &), + void *arg) +{ + Mutex::Lock _l(_devices_m); + EthernetTap *t = new LinuxEthernetTap(mac,mtu,metric,nwid,desiredDevice,friendlyName,handler,arg); + _devices.push_back(t); + return t; +} + +void LinuxEthernetTapFactory::close(EthernetTap *tap) +{ + { + Mutex::Lock _l(_devices_m); + for(std::vector::iterator d(_devices.begin());d!=_devices.end();++d) { + if (*d == tap) { + _devices.erase(d); + break; + } + } + } + delete tap; +} + +std::vector allTapDeviceNames() const +{ + std::vector dn; + Mutex::Lock _l(_devices_m); + for(std::vector::const_iterator d(_devices.begin());d!=_devices.end();++d) + dn.push_back(d->deviceName()); + return dn; +} + +} // namespace ZeroTier -- cgit v1.2.3