MacEthernetTap.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_OSXETHERNETTAP_HPP
  14. #define ZT_OSXETHERNETTAP_HPP
  15. #include "../node/Constants.hpp"
  16. #include "../node/MAC.hpp"
  17. #include "../node/InetAddress.hpp"
  18. #include "../node/MulticastGroup.hpp"
  19. #include "../node/Mutex.hpp"
  20. #include "Thread.hpp"
  21. #include "EthernetTap.hpp"
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <stdexcept>
  25. #include <string>
  26. #include <vector>
  27. namespace ZeroTier {
  28. class MacEthernetTap : public EthernetTap
  29. {
  30. public:
  31. MacEthernetTap(
  32. const char *homePath,
  33. const MAC &mac,
  34. unsigned int mtu,
  35. unsigned int metric,
  36. uint64_t nwid,
  37. const char *friendlyName,
  38. void (*handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
  39. void *arg);
  40. virtual ~MacEthernetTap();
  41. virtual void setEnabled(bool en);
  42. virtual bool enabled() const;
  43. virtual bool addIp(const InetAddress &ip);
  44. virtual bool removeIp(const InetAddress &ip);
  45. virtual std::vector<InetAddress> ips() const;
  46. virtual void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
  47. virtual std::string deviceName() const;
  48. virtual void setFriendlyName(const char *friendlyName);
  49. virtual void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
  50. virtual void setMtu(unsigned int mtu);
  51. virtual void setDns(const char *domain, const std::vector<InetAddress> &servers);
  52. void threadMain()
  53. throw();
  54. private:
  55. void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
  56. void *_arg;
  57. uint64_t _nwid;
  58. Thread _thread;
  59. std::string _homePath;
  60. std::string _dev;
  61. std::vector<MulticastGroup> _multicastGroups;
  62. Mutex _putLock;
  63. unsigned int _mtu;
  64. unsigned int _metric;
  65. unsigned int _devNo;
  66. int _shutdownSignalPipe[2];
  67. int _agentStdin,_agentStdout,_agentStderr,_agentStdin2,_agentStdout2,_agentStderr2;
  68. long _agentPid;
  69. volatile bool _enabled;
  70. };
  71. } // namespace ZeroTier
  72. #endif