ointerface.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * ointerface.hpp - interface for the ointerface class
  11. *
  12. * host interface information;
  13. *
  14. * Contributor(s):
  15. * Charles Maier <charles.maier@intellon.com>
  16. *
  17. *--------------------------------------------------------------------*/
  18. #ifndef oINTERFACE_HEADER
  19. #define oINTERFACE_HEADER
  20. /*====================================================================*
  21. * system header files;
  22. *--------------------------------------------------------------------*/
  23. #if defined (__linux__)
  24. # include <stdint.h>
  25. # include <net/ethernet.h>
  26. # include <net/if.h>
  27. #elif defined (__APPLE__)
  28. # include <sys/socket.h>
  29. # include <net/if.h>
  30. # include <netinet/in.h>
  31. # include <netinet/if_ether.h>
  32. #elif defined (__OpenBSD__)
  33. # include <sys/socket.h>
  34. # include <net/if.h>
  35. # include <netinet/in.h>
  36. // #include <arpa/inet.h>
  37. # include <netinet/if_ether.h>
  38. #elif defined (WINPCAP)
  39. # include <net/ethernet.h>
  40. # include <net/if.h>
  41. #else
  42. #error "Unknown environment"
  43. #endif
  44. /*====================================================================*
  45. * custom header files;
  46. *--------------------------------------------------------------------*/
  47. #include "../classes/stdafx.hpp"
  48. /*====================================================================*
  49. * class datatypes;
  50. *--------------------------------------------------------------------*/
  51. typedef unsigned char byte;
  52. /*====================================================================*
  53. * class declaration;
  54. *--------------------------------------------------------------------*/
  55. class __declspec (dllexport) ointerface
  56. {
  57. friend class ointerfaces;
  58. public:
  59. explicit ointerface (unsigned ifindex);
  60. explicit ointerface (char const * ifname);
  61. virtual ~ ointerface ();
  62. unsigned Index (void) const;
  63. char const * Name (void) const;
  64. char const * Description (void) const;
  65. byte const * HardwareAddress (void) const;
  66. byte const * InternetAddress (void) const;
  67. char const * HardwareAddressString (void) const;
  68. char const * InternetAddressString (void) const;
  69. ointerface & Description (char const *);
  70. ointerface & ExportHardwareAddress (void *);
  71. ointerface & ExportInternetAddress (void *);
  72. ointerface & Print ();
  73. bool Disabled () const;
  74. protected:
  75. private:
  76. ointerface & lookup ();
  77. unsigned pcap_nametoindex (char const * ifname) const;
  78. char * pcap_indextoname (unsigned ifindex, char * ifname) const;
  79. void pcap_gethwaddr ();
  80. void pcap_getipaddr ();
  81. unsigned mifindex;
  82. byte mhwaddr [ETHER_ADDR_LEN];
  83. byte mipaddr [sizeof (uint32_t)];
  84. char mhwstring [ETHER_ADDR_LEN * 3];
  85. char mipstring [sizeof (uint32_t) * 4];
  86. char mifname [IF_NAMESIZE];
  87. char miftext [255];
  88. };
  89. /*====================================================================*
  90. * end declaration;
  91. *--------------------------------------------------------------------*/
  92. #endif