example-3.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*====================================================================*
  2. Copyright (c) 2020 Qualcomm Technologies, Inc.
  3. All Rights Reserved.
  4. Confidential and Proprietary - Qualcomm Technologies, Inc.
  5. ******************************************************************
  6. 2013 Qualcomm Atheros, Inc.
  7. *====================================================================*/
  8. /*====================================================================*
  9. * system header files;
  10. *--------------------------------------------------------------------*/
  11. #include <cstdlib>
  12. #include <iostream>
  13. /*====================================================================*
  14. * system header files;
  15. *--------------------------------------------------------------------*/
  16. #include <sys/types.h>
  17. #ifndef WINPCAP
  18. #include <sys/socket.h>
  19. #endif
  20. #include <net/if.h>
  21. /*====================================================================*
  22. * custom header files;
  23. *--------------------------------------------------------------------*/
  24. #include "../classes/CPLChannel.hpp"
  25. #include "../classes/CPLNetwork.hpp"
  26. #include "../classes/omemory.hpp"
  27. /*====================================================================*
  28. * custom source files;
  29. *--------------------------------------------------------------------*/
  30. #ifndef MAKEFILE
  31. #include "../classes/omemory.cpp"
  32. #include "../classes/oerror.cpp"
  33. #include "../classes/oflagword.cpp"
  34. #include "../classes/ointerface.cpp"
  35. #include "../classes/oethernet.cpp"
  36. #include "../classes/ointellon.cpp"
  37. #include "../classes/ohomeplug.cpp"
  38. #include "../classes/CPLChannel.cpp"
  39. #include "../classes/CPLStation.cpp"
  40. #include "../classes/CPLNetwork.cpp"
  41. #endif
  42. /*====================================================================*
  43. * program variables;
  44. *--------------------------------------------------------------------*/
  45. char const * program_name;
  46. /*====================================================================*
  47. * main program;
  48. *
  49. * make sure you instantiate channel with the correct interface for
  50. * your test platform or you will not get any output;
  51. *
  52. *--------------------------------------------------------------------*/
  53. int main (int argc, const char *argv [])
  54. {
  55. #if defined (__APPLE__)
  56. CPLChannel channel ("en0", CPLCHANNEL_TIMEOUT);
  57. #elif defined (WIN32)
  58. CPLChannel channel (2, CPLCHANNEL_TIMEOUT);
  59. #elif defined (__OpenBSD__)
  60. CPLChannel channel ("bce0", CPLCHANNEL_TIMEOUT);
  61. #else
  62. CPLChannel channel ("eth4", CPLCHANNEL_TIMEOUT);
  63. #endif
  64. CPLNetwork network (&channel);
  65. std::cout << "Method 1 - The Easy Way" << std::endl << std::endl;
  66. network.Enumerate ();
  67. std::cout << "Method 2 - The Do-it-yourself Way" << std::endl << std::endl;
  68. if (network.Count ())
  69. {
  70. network.Select (0).Selected ().Preface ();
  71. }
  72. while (network.Index () < network.Count ())
  73. {
  74. network.Selected ().Print ();
  75. network.SelectNext ();
  76. }
  77. std::cout << std::endl;
  78. std::cout << "Method 3 - The Hard Way" << std::endl << std::endl;
  79. if (!network.Empty ())
  80. {
  81. network [0].Preface ();
  82. }
  83. while (!network.End ())
  84. {
  85. network.Station ().Print ();
  86. network.SelectNext ();
  87. }
  88. std::cout << std::endl;
  89. std::exit (0);
  90. }