ETHInterface.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. uint16_t zero;
  50. uint8_t mac[6];
  51. };
  52. #define ETHInterface_Sockaddr_SIZE 16
  53. Assert_compileTime(sizeof(struct ETHInterface_Sockaddr) == ETHInterface_Sockaddr_SIZE);
  54. #define ETHInterface_CURRENT_VERSION 0
  55. struct ETHInterface
  56. {
  57. struct AddrIface generic;
  58. };
  59. struct ETHInterface* ETHInterface_new(struct EventBase* eventBase,
  60. const char* bindDevice,
  61. struct Allocator* alloc,
  62. struct Except* exHandler,
  63. struct Log* logger);
  64. List* ETHInterface_listDevices(struct Allocator* alloc, struct Except* eh);
  65. #endif