ether.h 3.6 KB

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