efeu.c.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. efeu.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='efbu.c.html' title=' efbu.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='efreopen.c.html' title=' efreopen.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * edeu.c - Ethernet Frame Echo Utility
  64. *
  65. * Listen for incoming Ethernet II frames and write frame data to
  66. * stdout as a continuous binary data stream. Since frame data can
  67. * contain anything, users should send program output to a file or
  68. * pipe it through a filter program to prevent corruption of the
  69. * terminal session. If all incoming data is ASCII then directing
  70. * stdout to the console should not cause any problems.
  71. *
  72. * this program can be used as a data target when testing AR6405
  73. * UART applications; use program edsu to send files from a remote
  74. * host and this program to display or save them;
  75. *
  76. *
  77. * Contributor(s):
  78. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  79. *
  80. *--------------------------------------------------------------------*/
  81. /*====================================================================*
  82. * system header files;
  83. *--------------------------------------------------------------------*/
  84. #include &lt;fcntl.h&gt;
  85. #include &lt;stdio.h&gt;
  86. #include &lt;limits.h&gt;
  87. #include &lt;ctype.h&gt;
  88. #include &lt;unistd.h&gt;
  89. #include &lt;stdint.h&gt;
  90. #include &lt;stdlib.h&gt;
  91. #include &lt;string.h&gt;
  92. #include &lt;errno.h&gt;
  93. #ifdef __linux__
  94. #include &lt;net/if.h&gt;
  95. #include &lt;net/if_arp.h&gt;
  96. #include &lt;netpacket/packet.h&gt;
  97. #include &lt;signal.h&gt;
  98. #endif
  99. /*====================================================================*
  100. * custom header files;
  101. *--------------------------------------------------------------------*/
  102. #include &quot;../tools/getoptv.h&quot;
  103. #include &quot;../tools/putoptv.h&quot;
  104. #include &quot;../tools/memory.h&quot;
  105. #include &quot;../tools/number.h&quot;
  106. #include &quot;../tools/types.h&quot;
  107. #include &quot;../tools/flags.h&quot;
  108. #include &quot;../tools/error.h&quot;
  109. #include &quot;../ether/channel.h&quot;
  110. /*====================================================================*
  111. * custom source files;
  112. *--------------------------------------------------------------------*/
  113. #ifndef MAKEFILE
  114. #include &quot;../tools/getoptv.c&quot;
  115. #include &quot;../tools/putoptv.c&quot;
  116. #include &quot;../tools/version.c&quot;
  117. #include &quot;../tools/hexdump.c&quot;
  118. #include &quot;../tools/hexdecode.c&quot;
  119. #include &quot;../tools/hexstring.c&quot;
  120. #include &quot;../tools/uintspec.c&quot;
  121. #include &quot;../tools/memswap.c&quot;
  122. #include &quot;../tools/todigit.c&quot;
  123. #include &quot;../tools/error.c&quot;
  124. #endif
  125. #ifndef MAKEFILE
  126. #include &quot;../ether/channel.c&quot;
  127. #include &quot;../ether/openchannel.c&quot;
  128. #include &quot;../ether/closechannel.c&quot;
  129. #include &quot;../ether/sendpacket.c&quot;
  130. #include &quot;../ether/readpacket.c&quot;
  131. #endif
  132. /*====================================================================*
  133. * program constants;
  134. *--------------------------------------------------------------------*/
  135. #define EFEU_INTERFACE &quot;PLC&quot;
  136. #define EFEU_ETHERTYPE ETH_P_802_2
  137. /*====================================================================*
  138. *
  139. * int main (int argc, char * argv[]);
  140. *
  141. *
  142. *--------------------------------------------------------------------*/
  143. int main (int argc, char const * argv [])
  144. {
  145. extern struct channel channel;
  146. struct ethernet_frame frame;
  147. signed length;
  148. static char const * optv [] =
  149. {
  150. &quot;e:i:qt:v&quot;,
  151. PUTOPTV_S_DIVINE,
  152. &quot;Qualcomm Atheros Ethernet Frame Echo Utility&quot;,
  153. &quot;e x\tethertype is (x) [&quot; LITERAL (EFEU_ETHERTYPE) &quot;]&quot;,
  154. #if defined (WINPCAP) || defined (LIBPCAP)
  155. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  156. #else
  157. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  158. #endif
  159. &quot;q\tsuppress normal output&quot;,
  160. &quot;t n\tread timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_FOREVER) &quot;]&quot;,
  161. &quot;v\tverbose messages on stdout&quot;,
  162. (char const *) (0)
  163. };
  164. signed c;
  165. channel.type = EFEU_ETHERTYPE;
  166. channel.timeout = CHANNEL_FOREVER;
  167. if (getenv (EFEU_INTERFACE))
  168. {
  169. #if defined (WINPCAP) || defined (LIBPCAP)
  170. channel.ifindex = atoi (getenv (EFEU_INTERFACE));
  171. #else
  172. channel.ifname = strdup (getenv (EFEU_INTERFACE));
  173. #endif
  174. }
  175. optind = 1;
  176. while ((c = getoptv (argc, argv, optv)) != -1)
  177. {
  178. switch (c)
  179. {
  180. case 'e':
  181. channel.type = (uint16_t)(basespec (optarg, 16, sizeof (channel.type)));
  182. break;
  183. case 'i':
  184. #if defined (WINPCAP) || defined (LIBPCAP)
  185. channel.ifindex = atoi (optarg);
  186. #else
  187. channel.ifname = optarg;
  188. #endif
  189. break;
  190. case 'q':
  191. _setbits (channel.flags, CHANNEL_SILENCE);
  192. break;
  193. case 't':
  194. channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
  195. break;
  196. case 'v':
  197. _setbits (channel.flags, CHANNEL_VERBOSE);
  198. break;
  199. default:
  200. break;
  201. }
  202. }
  203. argc -= optind;
  204. argv += optind;
  205. if (argc)
  206. {
  207. error (1, ECANCELED, ERROR_TOOMANY);
  208. }
  209. openchannel (&amp;channel);
  210. while ((length = readpacket (&amp;channel, &amp;frame, sizeof (frame))) &gt; 0)
  211. {
  212. memswap (&amp;frame.frame_dhost, &amp;frame.frame_shost, sizeof (frame.frame_dhost));
  213. if (sendpacket (&amp;channel, &amp;frame, length) != length)
  214. {
  215. error (1, errno, CHANNEL_CANTSEND);
  216. }
  217. }
  218. closechannel (&amp;channel);
  219. return (0);
  220. }
  221. </pre>
  222. <div class='footerlink'>
  223. [<a href='efbu.c.html' title=' efbu.c '>PREV</a>]
  224. [<a href='toolkit.html' title=' Index '>HOME</a>]
  225. [<a href='efreopen.c.html' title=' efreopen.c '>NEXT</a>]
  226. </div>
  227. </body>
  228. </html>