⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arp_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/arp.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center><hr><h1>/opentcp/arp.c</h1><a href="arp_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> *      "This product includes software developed by Viola </span>00019 <span class="comment"> *      Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see &lt;http://www.opentcp.org&gt;.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *&lt;http://www.violasystems.com/&gt;.</span>00052 <span class="comment"> */</span>00053 00069 <span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span>00070 <span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span>00071 <span class="preprocessor">#include &lt;<a class="code" href="ethernet_8h.html">inet/ethernet.h</a>&gt;</span>00072 <span class="preprocessor">#include &lt;<a class="code" href="arp_8h.html">inet/arp.h</a>&gt;</span>00073 <span class="preprocessor">#include &lt;<a class="code" href="timers_8h.html">inet/timers.h</a>&gt;</span>00074 <span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span>00075 <span class="preprocessor">#include &lt;<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>&gt;</span>00076 <a name="l00086"></a><a class="code" href="arp_8c.html#a0">00086</a> <span class="keyword">struct </span><a class="code" href="structarp__entry.html">arp_entry</a>        arp_table[ARP_TSIZE]; 00087 <a name="l00094"></a><a class="code" href="arp_8c.html#a1">00094</a> UINT8 <a class="code" href="arp_8c.html#a1">arp_timer</a>; 00095 <a name="l00116"></a><a class="code" href="arp_8c.html#a2">00116</a> UINT8 <a class="code" href="arp_8c.html#a2">process_arp</a> (<span class="keyword">struct</span> <a class="code" href="structethernet__frame.html">ethernet_frame</a>* frame) {00117         00118         UINT8 temp;             00119         00120         <span class="comment">/* Check if ARP packet*/</span>00121         00122         <span class="keywordflow">if</span>( frame-&gt;<a class="code" href="structethernet__frame.html#m3">protocol</a> == ARP_ETHCODE ) {00123                 <span class="comment">/* Yep, ARP */</span>00124                 00125                 <a class="code" href="system_8h.html#a14">NETWORK_RECEIVE_INITIALIZE</a>(frame-&gt;<a class="code" href="structethernet__frame.html#m4">buf_index</a>);00126                 00127                 <span class="comment">/* Is it long enough?   */</span>00128                 00129                 <span class="keywordflow">if</span>( frame-&gt;<a class="code" href="structethernet__frame.html#m2">frame_size</a> &lt; (2*<a class="code" href="arp_8h.html#a0">MAXHWALEN</a> + 2*<a class="code" href="arp_8h.html#a1">MAXPRALEN</a> + 2 + 6) ) {00130                         <span class="comment">/* Somehow corrupted ARP packet */</span>00131                         ARP_DEBUGOUT(<span class="stringliteral">"Corrupted ARP packet\n\r"</span>);00132                         <span class="comment">/*NETWORK_RECEIVE_END();*/</span>00133                         <span class="keywordflow">return</span>(TRUE);00134                 }00135                          00136                 00137                 <span class="comment">/* Ignore next 6 bytes: &lt;HW type&gt;, &lt;Protocol type&gt; */</span>00138                 <span class="comment">/* &lt;HW address len&gt; and &lt;Protocol address len&gt;     */</span>00139                 00140                 <span class="keywordflow">for</span>(temp=0; temp&lt;6; temp++)00141                         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00142                 00143                 ARP_DEBUGOUT(<span class="stringliteral">"Incoming ARP..\n\r"</span>);00144                 00145                 <span class="comment">/* Check if request or response */</span>00146                 00147                 <span class="keywordflow">if</span>( <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>() == 0x00) {00148                 00149                         temp = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();     <span class="comment">/* get opcode */</span>00150                 00151                         <span class="keywordflow">if</span>( temp == ARP_REQUEST ) {00152                                 ARP_DEBUGOUT(<span class="stringliteral">" ARP REQUEST Received..\n\r"</span>);00153                                 <a class="code" href="arp_8c.html#a3">arp_send_response</a>();00154                         } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( temp == ARP_REPLY ) {00155                                 ARP_DEBUGOUT(<span class="stringliteral">"ARP Response Received..\n\r"</span>);00156                                 <a class="code" href="arp_8c.html#a4">arp_get_response</a>();     00157                         }00158                         00159                 <span class="comment">/* Wasn't request or response or all done, dump it */</span>00160                 00161                 }00162                 00163                 <span class="comment">/*NETWORK_RECEIVE_END();*/</span>00164                 <span class="keywordflow">return</span>(TRUE);00165                 00166         }00167         00168         <span class="comment">/* Wasn't ARP, don't touch the packet */</span>00169         00170         <span class="keywordflow">return</span>(FALSE);                                                          00171 }00172 <a name="l00188"></a><a class="code" href="arp_8c.html#a3">00188</a> <span class="keywordtype">void</span> <a class="code" href="arp_8c.html#a3">arp_send_response</a>(<span class="keywordtype">void</span>)00189 {00190         <span class="keyword">struct </span><a class="code" href="structarp__entry.html">arp_entry</a> *qstruct;00191         UINT8 rem_hwadr[<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>];00192         UINT32 rem_ip;00193         UINT32 ltemp;00194         INT8 i;00195         BYTE j;00196 00197         <span class="comment">/* Record Sender's HW address           */</span>00198         00199         <span class="keywordflow">for</span>( i=<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>-1; i &gt;= 0; i-- )00200                 rem_hwadr[i] = <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();             00201         00202         <span class="comment">/* Read Sender's IP Address     */</span>00203         00204         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a1">MAXPRALEN</a>; i++) {00205                 rem_ip &lt;&lt;= 8;00206                 rem_ip |= <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00207         } 00208         00209         00210         <span class="comment">/* Skip Target HW address               */</span>00211         00212         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00213         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00214         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00215         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00216         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00217         <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();    00218         00219         <span class="comment">/* Is The Packet For Us?        */</span>00220         00221         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a1">MAXPRALEN</a>; i++) {00222                 ltemp &lt;&lt;= 8;00223                 ltemp |= <a class="code" href="system_8h.html#a9">RECEIVE_NETWORK_B</a>();00224         }00225                 00226         00227         <span class="keywordflow">if</span>( ltemp != localmachine.localip ) 00228                 <span class="keywordflow">return</span>;                                                         <span class="comment">/* No   */</span>00229 00230         ARP_DEBUGOUT(<span class="stringliteral">"Preparing for ARP Reply\n\r"</span>);00231         00232         <span class="comment">/* OK. Now send reply           */</span>00233         00234         <a class="code" href="system_8h.html#a17">NETWORK_SEND_INITIALIZE</a>(<a class="code" href="ethernet_8h.html#a35">ARP_BUFFER</a>);00235         00236         <span class="comment">/* Add datalink (Ethernet addresses) information        */</span>00237         00238         <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>; i++)     {00239                 send_frame.destination[i] = rem_hwadr[i];00240                 send_frame.source[i] = localmachine.localHW[i];00241         }00242         00243         send_frame.protocol = <a class="code" href="ethernet_8h.html#a5">PROTOCOL_ARP</a>;00244         00245         <a class="code" href="system_8h.html#a18">NETWORK_ADD_DATALINK</a>(&amp;send_frame);00246         00247         <span class="comment">/* PUT ARP Data */</span>00248         00249         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (BYTE)(AR_HARDWARE&gt;&gt;8) );                               <span class="comment">/* Hardware Type        */</span>00250         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( (BYTE)AR_HARDWARE );00251         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(0x08);                                                                   <span class="comment">/* Protocol Type        */</span>00252         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(0x00);00253         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(<a class="code" href="arp_8h.html#a0">MAXHWALEN</a>);                                                              <span class="comment">/* HW Adr Len           */</span>00254         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>(<a class="code" href="arp_8h.html#a1">MAXPRALEN</a>);                                                              <span class="comment">/* Protocol Adr. Len*/</span>00255         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( 0x00 );                                                                 <span class="comment">/* ARP Opcode           */</span>      00256         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>( 0x02 );                                 00257         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localHW[5]));               <span class="comment">/* Address fields       */</span>00258         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localHW[4]));00259         <a class="code" href="system_8h.html#a11">SEND_NETWORK_B</a>((UINT8)(localmachine.localHW[3]));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -