ether.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*====================================================================*
  2. *
  3. * ether.h - Ethernet definitions and declarations;
  4. *
  5. * include or exclude various ethernet related definitions based
  6. * platform and environment;
  7. *
  8. *. Qualcomm Atheros HomePlug AV Powerline Toolkit
  9. *: Copyright (c) 2009-2013 by Qualcomm Atheros Inc. ALL RIGHTS RESERVED;
  10. *; For demonstration and evaluation only; Not for production use.
  11. *
  12. *--------------------------------------------------------------------*/
  13. #ifndef ETHER_HEADER
  14. #define ETHER_HEADER
  15. /*====================================================================*
  16. * system header files;
  17. *--------------------------------------------------------------------*/
  18. #include <stdint.h>
  19. #if defined (__linux__)
  20. # include <net/if.h>
  21. # include <net/ethernet.h>
  22. # include <arpa/inet.h>
  23. #elif defined (__APPLE__)
  24. # include <sys/types.h>
  25. # include <sys/socket.h>
  26. # include <net/if.h>
  27. # include <net/ethernet.h>
  28. # include <arpa/inet.h>
  29. # include <net/bpf.h>
  30. #elif defined (__OpenBSD__) || defined (__NetBSD__)
  31. # include <sys/ioctl.h>
  32. # include <sys/types.h>
  33. # include <sys/socket.h>
  34. # include <net/if.h>
  35. # include <netinet/in.h>
  36. # include <netinet/if_ether.h>
  37. # include <net/bpf.h>
  38. # include <fcntl.h>
  39. #elif defined (__FreeBSD__)
  40. # include <sys/ioctl.h>
  41. # include <sys/types.h>
  42. # include <sys/socket.h>
  43. # include <net/if.h>
  44. # include <net/ethernet.h>
  45. # include <netinet/in.h>
  46. # include <sys/time.h>
  47. # include <net/bpf.h>
  48. #elif defined (WIN32)
  49. # if defined (WINPCAP)
  50. # include <pcap.h>
  51. # include <Packet32.h>
  52. # endif
  53. # include <net/ethernet.h>
  54. # include <net/if.h>
  55. #elif defined (__CYGWIN__)
  56. # error "Cygwin in unsupported!"
  57. #else
  58. # error "Unknown environment!"
  59. #endif
  60. /*====================================================================*
  61. * custom header files;
  62. *--------------------------------------------------------------------*/
  63. #include "../tools/types.h"
  64. /*====================================================================*
  65. * variables;
  66. *--------------------------------------------------------------------*/
  67. typedef struct nic
  68. {
  69. unsigned ifindex;
  70. byte ethernet [ETHER_ADDR_LEN];
  71. byte internet [4];
  72. char ifname [IF_NAMESIZE];
  73. char ifdesc [255];
  74. }
  75. NIC;
  76. /*====================================================================*
  77. * ethertypes;
  78. *--------------------------------------------------------------------*/
  79. #define ETH_P_HP10 0x887B
  80. #define ETH_P_HCP 0x88B7
  81. #define ETH_P_LLDP 0x88CC
  82. #define ETH_P_HPAV 0x88E1
  83. #define ETH_P_1905 0x893A
  84. /*====================================================================*
  85. * basic 802.2 Ethernet frame structure;
  86. *--------------------------------------------------------------------*/
  87. #ifndef __GNUC__
  88. #pragma pack (push, 1)
  89. #endif
  90. typedef struct ethernet_frame
  91. {
  92. byte frame_dhost [ETHER_ADDR_LEN];
  93. byte frame_shost [ETHER_ADDR_LEN];
  94. uint16_t frame_type;
  95. byte frame_data [ETHERMTU];
  96. }
  97. FRAME;
  98. #ifndef __GNUC__
  99. #pragma pack (pop)
  100. #endif
  101. /*====================================================================*
  102. * functions;
  103. *--------------------------------------------------------------------*/
  104. char * getifname (signed number);
  105. signed gethwaddr (void * memory, char const * device);
  106. signed anynic (char buffer [], unsigned length);
  107. unsigned hostnics (struct nic list [], unsigned size);
  108. /*====================================================================*
  109. *
  110. *--------------------------------------------------------------------*/
  111. #endif