ETHInterface.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 ETHInterface_H
  16. #define ETHInterface_H
  17. #include "interface/addressable/AddrIface.h"
  18. #include "benc/List.h"
  19. #include "util/events/EventBase.h"
  20. #include "net/InterfaceController.h"
  21. #include "util/Gcc.h"
  22. #include "util/Assert.h"
  23. #include "util/log/Log.h"
  24. #include "memory/Allocator.h"
  25. #include "util/Linker.h"
  26. Linker_require("interface/ETHInterface_" + builder.config.systemName + ".c")
  27. Gcc_PACKED
  28. struct ETHInterface_Header
  29. {
  30. /** ETHInterface_CURRENT_VERSION, no communication is possible with different versions. */
  31. uint8_t version;
  32. /** padding and for future use. */
  33. uint8_t zero;
  34. /** Length of the content (excluding header) */
  35. uint16_t length_be;
  36. /** Pad to align boundry, also magic. */
  37. uint16_t fc00_be;
  38. };
  39. #define ETHInterface_Header_SIZE 6
  40. Assert_compileTime(sizeof(struct ETHInterface_Header) == ETHInterface_Header_SIZE);
  41. /** The content of a Sockaddr emitted from ETHInterface. */
  42. struct ETHInterface_Sockaddr
  43. {
  44. struct Sockaddr generic;
  45. /*
  46. * We need to make the first byte following the Sockaddr be 0 because
  47. * Sockaddr_normalizeNative will zero it.
  48. */
  49. uint8_t zero;
  50. /**
  51. * If we have multiple interfaces represented by the same ETHInterface,
  52. * this is the number of the interface to send to.
  53. */
  54. uint8_t ifNum;
  55. uint8_t mac[6];
  56. };
  57. #define ETHInterface_Sockaddr_SIZE 16
  58. Assert_compileTime(sizeof(struct ETHInterface_Sockaddr) == ETHInterface_Sockaddr_SIZE);
  59. #define ETHInterface_CURRENT_VERSION 0
  60. struct ETHInterface
  61. {
  62. struct AddrIface generic;
  63. };
  64. struct ETHInterface* ETHInterface_new(struct EventBase* eventBase,
  65. const char* bindDevice,
  66. struct Allocator* alloc,
  67. struct Except* exHandler,
  68. struct Log* logger);
  69. List* ETHInterface_listDevices(struct Allocator* alloc, struct Except* eh);
  70. #endif