TUNInterface.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef TUNInterface_H
  16. #define TUNInterface_H
  17. #include "util/events/EventBase.h"
  18. #include "util/log/Log.h"
  19. #include "exception/Except.h"
  20. #include "memory/Allocator.h"
  21. #include "interface/Interface.h"
  22. /**
  23. * This is the maximum size that will be accepted as an interface name.
  24. * If this runs on a system where IFNAMSIZ is less then this, names larger
  25. * than that will also be rejected.
  26. */
  27. #ifdef Windows
  28. #define TUNInterface_IFNAMSIZ 256
  29. #else
  30. #define TUNInterface_IFNAMSIZ 16
  31. #endif
  32. /**
  33. * Create a new TUNInterface.
  34. *
  35. * @param interfaceName the interface name you *want* to use or NULL to let the kernel decide.
  36. * @param assignedInterfaceName an empty buffer which will be filled in with the interface
  37. * name that is assigned.
  38. * @param base the libevent event base to use for listening for incoming packet events.
  39. * @param logger for logging messages about the tun device.
  40. * @param eh if this function fails, it will raise one of the following.
  41. * TUNInterface_new_BAD_TUNNEL interfaceName was an invalid tun device name.
  42. * TUNInterface_new_INTERNAL Something went wrong internally.
  43. * TUNInterface_new_PERMISSION The user running this process doesn't have
  44. * permission to open a tun device.
  45. * @param allocator a means of getting memory.
  46. * @return a Interface.
  47. */
  48. #define TUNInterface_new_INTERNAL -3
  49. #define TUNInterface_new_BAD_TUNNEL -2
  50. #define TUNInterface_new_PERMISSION -1
  51. struct Interface* TUNInterface_new(const char* interfaceName,
  52. char assignedInterfaceName[TUNInterface_IFNAMSIZ],
  53. struct EventBase* base,
  54. struct Log* logger,
  55. struct Except* eh,
  56. struct Allocator* alloc);
  57. #endif