ETHInterface.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <https://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. struct ETHInterface_Header
  28. {
  29. /** ETHInterface_CURRENT_VERSION, no communication is possible with different versions. */
  30. uint8_t version;
  31. /** padding and for future use. */
  32. uint8_t zero;
  33. /** Length of the content (excluding header) */
  34. uint16_t length_be;
  35. /** Pad to align boundry, also magic. */
  36. uint16_t fc00_be;
  37. } Gcc_PACKED;
  38. #define ETHInterface_Header_SIZE 6
  39. Assert_compileTime(sizeof(struct ETHInterface_Header) == ETHInterface_Header_SIZE);
  40. /** The content of a Sockaddr emitted from ETHInterface. */
  41. struct ETHInterface_Sockaddr
  42. {
  43. struct Sockaddr generic;
  44. /*
  45. * We need to make the first byte following the Sockaddr be 0 because
  46. * Sockaddr_normalizeNative will zero it.
  47. */
  48. uint16_t zero;
  49. uint8_t mac[6];
  50. };
  51. #define ETHInterface_Sockaddr_SIZE 16
  52. Assert_compileTime(sizeof(struct ETHInterface_Sockaddr) == ETHInterface_Sockaddr_SIZE);
  53. #define ETHInterface_CURRENT_VERSION 0
  54. struct ETHInterface
  55. {
  56. AddrIface_t generic;
  57. };
  58. Er_DEFUN(struct ETHInterface* ETHInterface_new(struct EventBase* eventBase,
  59. const char* bindDevice,
  60. struct Allocator* alloc,
  61. struct Log* logger));
  62. Er_DEFUN(List* ETHInterface_listDevices(struct Allocator* alloc));
  63. #endif