MacEthernetTap.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2019 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifndef ZT_OSXETHERNETTAP_HPP
  27. #define ZT_OSXETHERNETTAP_HPP
  28. #include "../node/Constants.hpp"
  29. #include "../node/MAC.hpp"
  30. #include "../node/InetAddress.hpp"
  31. #include "../node/MulticastGroup.hpp"
  32. #include "../node/Mutex.hpp"
  33. #include "Thread.hpp"
  34. #include "EthernetTap.hpp"
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <stdexcept>
  38. #include <string>
  39. #include <vector>
  40. namespace ZeroTier {
  41. class MacEthernetTap : public EthernetTap
  42. {
  43. public:
  44. MacEthernetTap(
  45. const char *homePath,
  46. const MAC &mac,
  47. unsigned int mtu,
  48. unsigned int metric,
  49. uint64_t nwid,
  50. const char *friendlyName,
  51. void (*handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
  52. void *arg);
  53. virtual ~MacEthernetTap();
  54. virtual void setEnabled(bool en);
  55. virtual bool enabled() const;
  56. virtual bool addIp(const InetAddress &ip);
  57. virtual bool removeIp(const InetAddress &ip);
  58. virtual std::vector<InetAddress> ips() const;
  59. virtual void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
  60. virtual std::string deviceName() const;
  61. virtual void setFriendlyName(const char *friendlyName);
  62. virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
  63. virtual void setMtu(unsigned int mtu);
  64. void threadMain()
  65. throw();
  66. private:
  67. void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
  68. void *_arg;
  69. uint64_t _nwid;
  70. Thread _thread;
  71. std::string _homePath;
  72. std::string _dev;
  73. std::vector<MulticastGroup> _multicastGroups;
  74. Mutex _putLock;
  75. unsigned int _mtu;
  76. unsigned int _metric;
  77. int _shutdownSignalPipe[2];
  78. int _agentStdin,_agentStdout,_agentStderr,_agentStdin2,_agentStdout2,_agentStderr2;
  79. long _agentPid;
  80. volatile bool _enabled;
  81. };
  82. } // namespace ZeroTier
  83. #endif