iwmulticall.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Wireless Tools
  3. *
  4. * Jean II - HPL 04
  5. *
  6. * Main code for "iwmulticall". This is a wrapper for the multicall version
  7. * of the wireless tools.
  8. * You need to link this code against "-lm".
  9. * Thanks to Ned Ludd <solar@gentoo.org> for the inspiration...
  10. *
  11. * This file is released under the GPL license.
  12. * Copyright (c) 1997-2004 Jean Tourrilhes <jt@hpl.hp.com>
  13. */
  14. /***************************** INCLUDES *****************************/
  15. #include <libgen.h> /* Basename */
  16. /**************************** PROTOTYPES ****************************/
  17. /* Prototypes of the main of each tool */
  18. extern int
  19. main_iwconfig(int argc,
  20. char ** argv);
  21. extern int
  22. main_iwlist(int argc,
  23. char ** argv);
  24. extern int
  25. main_iwspy(int argc,
  26. char ** argv);
  27. extern int
  28. main_iwpriv(int argc,
  29. char ** argv);
  30. extern int
  31. main_iwgetid(int argc,
  32. char ** argv);
  33. /************************** MULTICALL HACK **************************/
  34. /*
  35. * The idea for multicall is to put all the tools and the library in
  36. * the same binary. This way, you can save the overhead of the library,
  37. * of each tool, can better optimise the code and throw away the stuff
  38. * you don't need from the library.
  39. * This almost divide the size of the tools by two (without stripping).
  40. * On the down side, you no longer have the libiw for other tools to
  41. * use, but for the target systems (embedded), this doesn't matter
  42. * much, as they just need to configure the card...
  43. * Note that splitting the lib and the multicall tools would not
  44. * make sense, as most gains are found in the inclusion of the lib...
  45. *
  46. * Our strategy is to include directly the *.c, rather than compile
  47. * them separatly. This allow to simplify compilation and hide the
  48. * multicall tweaks from the other tools.
  49. * Yeah, this leads to a bit a preprocessor abuse...
  50. * Jean II
  51. */
  52. /* We need the library */
  53. #include "iwlib.c"
  54. /* Get iwconfig in there. Mandatory. */
  55. #define main(args...) main_iwconfig(args)
  56. #define iw_usage(args...) iwconfig_usage(args)
  57. #define find_command(args...) iwconfig_find_command(args)
  58. #include "iwconfig.c"
  59. #undef find_command
  60. #undef iw_usage
  61. #undef main
  62. /* Get iwlist in there. Scanning support is pretty sweet. */
  63. #define main(args...) main_iwlist(args)
  64. #define iw_usage(args...) iwlist_usage(args)
  65. #define find_command(args...) iwlist_find_command(args)
  66. #include "iwlist.c"
  67. #undef find_command
  68. #undef iw_usage
  69. #undef main
  70. #ifndef WE_ESSENTIAL
  71. /* Get iwspy in there, it's not that big. */
  72. #define main(args...) main_iwspy(args)
  73. #include "iwspy.c"
  74. #undef main
  75. #endif /* WE_ESSENTIAL */
  76. /* Get iwpriv in there. Mandatory for HostAP and some other drivers. */
  77. #define main(args...) main_iwpriv(args)
  78. #define iw_usage(args...) iwpriv_usage(args)
  79. #include "iwpriv.c"
  80. #undef iw_usage
  81. #undef main
  82. /* Do we really need iwgetid ? Well, it's not like it's a big one */
  83. #define main(args...) main_iwgetid(args)
  84. #define iw_usage(args...) iwgetid_usage(args)
  85. #include "iwgetid.c"
  86. #undef iw_usage
  87. #undef main
  88. /* iwevent is useless for most people, don't grab it ? */
  89. /* ifrename is big and useless for those systems */
  90. /******************************* MAIN ********************************/
  91. /*------------------------------------------------------------------*/
  92. /*
  93. * The main !
  94. */
  95. int
  96. main(int argc,
  97. char ** argv)
  98. {
  99. char * call_name = basename(argv[0]); /* Strip path */
  100. /* This is a testing hack */
  101. if(!strcmp(call_name, "iwmulticall") && (argc > 0))
  102. {
  103. argv++;
  104. argc--;
  105. call_name = basename(argv[0]);
  106. }
  107. /* Just check the name under which we were called... */
  108. if(!strcmp(call_name, "iwconfig"))
  109. return(main_iwconfig(argc, argv));
  110. if(!strcmp(call_name, "iwlist"))
  111. return(main_iwlist(argc, argv));
  112. #ifndef WE_ESSENTIAL
  113. if(!strcmp(call_name, "iwspy"))
  114. return(main_iwspy(argc, argv));
  115. #endif /* WE_ESSENTIAL */
  116. if(!strcmp(call_name, "iwpriv"))
  117. return(main_iwpriv(argc, argv));
  118. if(!strcmp(call_name, "iwgetid"))
  119. return(main_iwgetid(argc, argv));
  120. /* Uh oh... Not supposed to come here. */
  121. printf("iwmulticall : you are not supposed to call me this way...\n");
  122. return(0);
  123. }