nics.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * nics.c - network interface enumerator;
  11. *
  12. * Contributor(s):
  13. * Charles Maier <cmaier@qca.qualcomm.com>
  14. *
  15. *--------------------------------------------------------------------*/
  16. /*====================================================================*
  17. * system header files;
  18. *--------------------------------------------------------------------*/
  19. #include <stdio.h>
  20. #include <memory.h>
  21. /*====================================================================*
  22. * custom header files;
  23. *--------------------------------------------------------------------*/
  24. #include "../tools/getoptv.h"
  25. #include "../tools/putoptv.h"
  26. #include "../tools/version.h"
  27. #include "../tools/error.h"
  28. #include "../tools/memory.h"
  29. #include "../ether/ether.h"
  30. /*====================================================================*
  31. * custom source files;
  32. *--------------------------------------------------------------------*/
  33. #ifndef MAKEFILE
  34. #include "../tools/getoptv.c"
  35. #include "../tools/putoptv.c"
  36. #include "../tools/version.c"
  37. #include "../tools/error.c"
  38. #include "../tools/hexdecode.c"
  39. #include "../tools/decdecode.c"
  40. #include "../tools/hexstring.c"
  41. #include "../tools/decstring.c"
  42. #include "../tools/error.c"
  43. #endif
  44. #ifndef MAKEFILE
  45. #include "../ether/hostnics.c"
  46. #endif
  47. /*====================================================================*
  48. *
  49. * void enumerate ();
  50. *
  51. * enumerate host interface details on stdout;
  52. *
  53. * Contributor(s):
  54. * Charles Maier <cmaier@qca.qualcomm.com>
  55. *
  56. *--------------------------------------------------------------------*/
  57. static void enumerate ()
  58. {
  59. struct nic nics [16];
  60. struct nic * nic;
  61. unsigned count = hostnics (nics, sizeof (nics) / sizeof (struct nic));
  62. for (nic = nics; count--; nic++)
  63. {
  64. byte memory [ETHER_ADDR_LEN];
  65. char string [ETHER_ADDR_LEN * 3];
  66. memset (memory, 0x00, sizeof (memory));
  67. if (! memcmp (memory, nic->ethernet, sizeof (memory)))
  68. {
  69. continue;
  70. }
  71. memset (memory, 0xFF, sizeof (memory));
  72. if (! memcmp (memory, nic->ethernet, sizeof (memory)))
  73. {
  74. continue;
  75. }
  76. printf (" %d", nic->ifindex);
  77. printf (" %s", hexstring (string, sizeof (string), nic->ethernet, sizeof (nic->ethernet)));
  78. printf (" %s", decstring (string, sizeof (string), nic->internet, sizeof (nic->internet)));
  79. printf (" %s", nic->ifname);
  80. printf (" %s", nic->ifdesc);
  81. printf ("\n");
  82. }
  83. return;
  84. }
  85. /*====================================================================*
  86. *
  87. * int main (int argc, char const * argv []);
  88. *
  89. * Contributor(s):
  90. * Charles Maier <cmaier@qca.qualcomm.com>
  91. *
  92. *--------------------------------------------------------------------*/
  93. int main (int argc, char const * argv [])
  94. {
  95. static char const * optv [] =
  96. {
  97. "",
  98. PUTOPTV_S_DIVINE,
  99. "Qualcomm Atheros Ethernet Interface Enumerator",
  100. (char const *) (0)
  101. };
  102. signed c;
  103. while (~ (c = getoptv (argc, argv, optv)))
  104. {
  105. switch (c)
  106. {
  107. default:
  108. break;
  109. }
  110. }
  111. argc -= optind;
  112. argv += optind;
  113. if (argc)
  114. {
  115. error (1, ECANCELED, ERROR_TOOMANY);
  116. }
  117. enumerate ();
  118. return (0);
  119. }